184 lines
6.8 KiB
C#
184 lines
6.8 KiB
C#
using ACS.SPiiPlusNET;
|
|
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Framework.Alarm;
|
|
using AuroraACS;
|
|
using AuroraChiller;
|
|
using AuroraIO;
|
|
using AuroraLaser;
|
|
using AuroraLaser.Trumpf;
|
|
using AuroraLaserScanner;
|
|
using AuroraLBAD;
|
|
using AuroraMotionBoard.Ajin;
|
|
using AuroraOCT;
|
|
using Hermes.Functional;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Device;
|
|
using WeldingCommon.Device.ACS;
|
|
using WeldingCommon.Process;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Devices;
|
|
using WeldingCommon.Sequences;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Utils;
|
|
using WeldingCommon.Devices.ACS;
|
|
|
|
namespace WeldingCommon.Sequences.Monitoring
|
|
{
|
|
public class SeqAlarmMonitor
|
|
{
|
|
static readonly Logger Log = new Logger("AlarmMonitoring");
|
|
|
|
const string SEQ_START = "SEQ START"; // 딱 한번 Sequence 진입 시에만 실행될 Node
|
|
|
|
const string SEQ_LoopFirst = "SEQ Loop First";
|
|
|
|
public const string CHECK_ALARM_PLC = "Check Alarm PLC";
|
|
public const string CHECK_ALARM_ACS = "Check Alarm ACS";
|
|
public const string CHECK_ALARM_LASER = "Check Alarm Laser";
|
|
public const string CHECK_ALARM_IO = "Check Alarm IO";
|
|
|
|
private static SequenceSetting _SequenceSetting;
|
|
|
|
private static Laser _laser;
|
|
private static LaserTruFiber _laserCore;
|
|
private static ScannerACS _acs; // 26.04.13
|
|
private static ACSMotor _axisX, _axisZ; //, _axisY1, _axisY2,
|
|
|
|
public const int NODE_SLEEP = 100; // msec
|
|
|
|
public static SequenceBuilder Builder()
|
|
{
|
|
SequenceBuilder sb = new SequenceBuilder(1000, true);
|
|
|
|
sb.AddAction(SEQ_START, StartNode);
|
|
sb.AddDecision(SEQ_LoopFirst, LoopFirstNode);
|
|
sb.AddAction(CHECK_ALARM_LASER, CheckAlarmLaser);
|
|
sb.AddAction(CHECK_ALARM_IO, CheckAlarmIO);
|
|
sb.AddAction(CHECK_ALARM_ACS, CheckAlarmAcs);
|
|
|
|
sb.Flows(sb.Init > sb[SEQ_START] > sb[SEQ_LoopFirst]
|
|
> sb[CHECK_ALARM_LASER] > sb[CHECK_ALARM_IO] > sb[CHECK_ALARM_ACS]
|
|
> sb[SEQ_LoopFirst]);
|
|
|
|
sb.Flows(sb[SEQ_LoopFirst] > sb.Final);
|
|
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
//sb.Draw("SeqAlarmMonitor.pdf");
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
//StartNode 알람
|
|
private static SequenceActionResult StartNode(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_SequenceSetting = context.Settings[CommonSettingIds.Sequence] as SequenceSetting;
|
|
|
|
if (_laser is null)
|
|
_laser = context.Devices[CommonDeviceIds.Laser] as Laser;
|
|
|
|
_laserCore = _laser.getCore() as LaserTruFiber;
|
|
|
|
if (_acs is null)
|
|
_acs = context.Devices[CommonDeviceIds.ACS] as ScannerACS;
|
|
|
|
if (_axisX is null)
|
|
_axisX = context.Devices[CommonMotorIds.AxisX2] as ACSMotor;
|
|
|
|
//if (_axisY1 is null)
|
|
// _axisY1 = context.Devices[CommonMotorIds.AxisY1] as ACSMotor;
|
|
|
|
//if (_axisY2 is null)
|
|
// _axisY2 = context.Devices[CommonMotorIds.AxisY2] as ACSMotor;
|
|
|
|
if (_axisZ is null)
|
|
_axisZ = context.Devices[CommonMotorIds.AxisZ] as ACSMotor;
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static string LoopFirstNode(SequenceContext context, string id, ICollection<string> branches, SequenceActionResult param)
|
|
{
|
|
while (!context.Stopped) {
|
|
return CHECK_ALARM_PLC;
|
|
}
|
|
|
|
Thread.Sleep(NODE_SLEEP);
|
|
return SeqNodeIds.FINAL;
|
|
}
|
|
|
|
private static SequenceActionResult CheckAlarmAcs(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if ((_acs.HasHeavyAlarm | _acs.HasLightAlarm) & _acs.IsActivated) {
|
|
foreach (var alarm in _acs.HaveAlarmCodes) {
|
|
if (alarm != 0) {
|
|
if (!AlarmManager.IsOccuredAlarm(alarm))
|
|
Log.E($"{context.AlarmAccured(alarm)}");
|
|
}
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(NODE_SLEEP);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult CheckAlarmLaser(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
#region 26.04.13 잠시 주석처리
|
|
_laserCore = _laser.getCore() as LaserTruFiber;
|
|
if (_laserCore.GetEStopOpen())
|
|
{
|
|
if (!AlarmManager.IsOccuredAlarm(AlarmCode_PrismaticGun.DEVICE_IO_LASER_EMO))
|
|
Log.E($"{context.AlarmAccured(AlarmCode_PrismaticGun.DEVICE_IO_LASER_EMO)}");
|
|
}
|
|
if (_laserCore.GetFaultLaser())
|
|
{
|
|
if (!AlarmManager.IsOccuredAlarm(AlarmCode_PrismaticGun.DEVICE_LASER_ERROR_MSG))
|
|
{
|
|
string alarmCode = $"{Convert.ToString(_laserCore.GetLastMessageCompID(), 16).ToUpper().PadLeft(2, '0')}{Convert.ToString(_laserCore.GetLastMessageCompNum(), 16).ToUpper().PadLeft(2, '0')} {Convert.ToString(_laserCore.GetLastMessageMsgCode(), 16).ToUpper().PadLeft(2, '0')}";
|
|
string alarmDescription = $" {_laserCore.GetLastMessageShortText()}";
|
|
Log.E($"{context.AlarmAccured(AlarmCode_PrismaticGun.DEVICE_LASER_ERROR_MSG)} >> code desc {alarmCode + alarmDescription}");
|
|
}
|
|
}
|
|
else if (_laserCore.GetMonitoring())
|
|
{
|
|
if (!AlarmManager.IsOccuredAlarm(AlarmCode_PrismaticGun.DEVICE_LASER_WARNING_MSG))
|
|
{
|
|
string alarmCode = $"{Convert.ToString(_laserCore.GetLastMessageCompID(), 16).ToUpper().PadLeft(2, '0')}{Convert.ToString(_laserCore.GetLastMessageCompNum(), 16).ToUpper().PadLeft(2, '0')} {Convert.ToString(_laserCore.GetLastMessageMsgCode(), 16).ToUpper().PadLeft(2, '0')}";
|
|
string alarmDescription = $" {_laserCore.GetLastMessageShortText()}";
|
|
Log.E($"{context.AlarmAccured(AlarmCode_PrismaticGun.DEVICE_LASER_WARNING_MSG)} >> code desc {alarmCode + alarmDescription}");
|
|
}
|
|
}
|
|
Thread.Sleep(NODE_SLEEP);
|
|
|
|
#endregion
|
|
return SequenceAction.Ok();
|
|
|
|
|
|
}
|
|
private static SequenceActionResult CheckAlarmIO(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnStopped(SequenceContext context)
|
|
{
|
|
}
|
|
|
|
private static void OnForceError(SequenceContext context, string arg2)
|
|
{
|
|
}
|
|
}
|
|
}
|