From 6935238d2b7fdabbe46514b50e154df44af862f8 Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期一, 06 七月 2020 11:32:09 +0800
Subject: [PATCH] 合并
---
src/Bro.Device.GTSCard/GTSCardDriver.cs | 6
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs | 2
src/Bro.M071.Process/M071Process.cs | 44 +++---
src/Bro.M071.Process/M071Process_MotionCard.cs | 296 ++++++++++++++++++++++++++++++++++++++++++++++--
src/Bro.M071.Process/M071Config.cs | 2
src/Bro.Common.Model/Helper/EnumHelper.cs | 4
6 files changed, 309 insertions(+), 45 deletions(-)
diff --git a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
index 355739a..7fb7839 100644
--- a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
+++ b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -57,7 +57,7 @@
/// </summary>
public List<MovingOption> AxisMovingOptionValues { get; set; } = new List<MovingOption>();
- public abstract void WriteOutput(short cardNum, short index, IOValue value);
+ public abstract void WriteOutput(short index, IOValue value);
}
public class MotionCardInitialConfigBase : InitialConfigBase, IMonitorConfig
diff --git a/src/Bro.Common.Model/Helper/EnumHelper.cs b/src/Bro.Common.Model/Helper/EnumHelper.cs
index a9cf25a..03c6d7a 100644
--- a/src/Bro.Common.Model/Helper/EnumHelper.cs
+++ b/src/Bro.Common.Model/Helper/EnumHelper.cs
@@ -532,9 +532,9 @@
[Description("鎸囩ず鐏�-榛�")]
Light_Yellow = 1,
- [Description("鎸囩ず鐏�-绾�")]
- Light_Green = 2,
[Description("鎸囩ず鐏�-缁�")]
+ Light_Green = 2,
+ [Description("鎸囩ず鐏�-绾�")]
Light_Red = 3,
[Description("铚傞福鍣�")]
Beep = 4,
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index 3d06c3f..adba5c9 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -767,17 +767,17 @@
/// </summary>
/// <param name="index">杈撳嚭鍙�,杩斿洖1-16</param>
/// <param name="value">false琛ㄧず杈撳嚭锛宼rue琛ㄧず鍏抽棴</param>
- public override void WriteOutput(short cardNum, short index, IOValue value)
+ public override void WriteOutput(short index, IOValue value)
{
short outNum = (short)(index % 100 + 1);
if ((int)value <= 1)
{
- GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value);
+ GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)value);
}
else
{
var currentValue = (int)MonitorValues.FirstOrDefault(u => u.IONum == outNum && u.IOType == IOType.OUTPUT).Value;
- GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1));
+ GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1));
}
}
diff --git a/src/Bro.M071.Process/M071Config.cs b/src/Bro.M071.Process/M071Config.cs
index cdee3bc..9f8559f 100644
--- a/src/Bro.M071.Process/M071Config.cs
+++ b/src/Bro.M071.Process/M071Config.cs
@@ -75,7 +75,7 @@
[Category("鍥剧墖淇濆瓨閰嶇疆")]
[Description("鍗曢敭鍥剧墖淇濆瓨鐩綍璺緞")]
- [Editor(typeof(FoldDialogEditor),typeof(UITypeEditor))]
+ [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
public string ImageSaveFolder { get; set; } = "";
[Category("灞忚斀閰嶇疆")]
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 12b9601..c026e29 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -56,6 +56,8 @@
//鏁版嵁搴撹縼绉绘鏌�
DatabaseInitialize.Initialize();
+ MotionCardSettingCheck();
+
Config.SnapshotPointCollection.ForEach(u =>
{
u.GetHalconToolPathList().ForEach(path =>
@@ -353,28 +355,28 @@
{
return;
}
-
- pMeasure.EndTime = DateTime.Now;
- bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true);
- OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0);
- OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds);
-
- LogAsync(DateTime.Now, $"{pMeasure.Barcode} 妫�娴嬪畬鎴愶紝缁撴灉 {(pResult ? "OK" : "NG")}", "");
-
- if (MachineState == MachineState.Running)
- MachineState = MachineState.Ready;
-
- //MES杈撳嚭 todo
-
- //Excel鎶ヨ〃杈撳嚭 todo
-
- //鏁版嵁搴撲繚瀛� todo
-
- SaveWholeImage(pMeasure);
-
- productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
- pMeasure.Dispose();
}
+
+ pMeasure.EndTime = DateTime.Now;
+ bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true);
+ OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0);
+ OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds);
+
+ LogAsync(DateTime.Now, $"{pMeasure.Barcode} 妫�娴嬪畬鎴愶紝缁撴灉 {(pResult ? "OK" : "NG")}", "");
+
+ if (MachineState == MachineState.Running)
+ MachineState = MachineState.Ready;
+
+ //MES杈撳嚭 todo
+
+ //Excel鎶ヨ〃杈撳嚭 todo
+
+ //鏁版嵁搴撲繚瀛� todo
+
+ SaveWholeImage(pMeasure);
+
+ productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
+ pMeasure.Dispose();
}
}
diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
index 98ce638..06474aa 100644
--- a/src/Bro.M071.Process/M071Process_MotionCard.cs
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -30,18 +30,116 @@
switch (machineState)
{
case MachineState.Ready:
+ SwitchBeep(false);
+ SwitchLightRed(false);
+ SwitchLightYellow(false);
+
+ Task.Run(() =>
+ {
+ while (MachineState == MachineState.Ready)
+ {
+ SwitchLightGreen(true);
+ Thread.Sleep(1000);
+ SwitchLightGreen(false);
+ }
+ });
+
break;
case MachineState.Running:
+ SwitchBeep(false);
+ SwitchLightRed(false);
+ SwitchLightYellow(false);
+ SwitchLightGreen(true);
break;
case MachineState.Alarm:
+ SwitchBeep(true);
+ SwitchLightRed(true);
+ SwitchLightYellow(false);
+ SwitchLightGreen(false);
break;
case MachineState.Pause:
+ SwitchBeep(false);
+ SwitchLightRed(false);
+ Task.Run(() =>
+ {
+ while (MachineState == MachineState.Pause)
+ {
+ SwitchLightYellow(true);
+ SwitchLightGreen(true);
+ Thread.Sleep(1000);
+ SwitchLightYellow(false);
+ SwitchLightGreen(false);
+ }
+ });
break;
default:
break;
}
OnMachineStateChanged?.Invoke(machineState);
+ }
+ }
+
+ private void MotionCardSettingCheck()
+ {
+ IDevice device = DeviceCollection.FirstOrDefault(u => u is IMotionCard);
+ if (device.InitialConfig is MotionCardInitialConfigBase iConfig)
+ {
+ outputCtrlCard = device as MotionCardBase;
+
+ var redDefinition = iConfig.IODefinitionCollection.FirstOrDefault(u => u.IOPreStatement == IOPrestatement.Light_Red);
+ if (redDefinition != null)
+ {
+ index_RedLight = redDefinition.IONum;
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"{iConfig.Name}鏈厤缃孩鑹茬伅杈撳嚭绱㈠紩", "");
+ }
+
+ var greenDefinition = iConfig.IODefinitionCollection.FirstOrDefault(u => u.IOPreStatement == IOPrestatement.Light_Green);
+ if (greenDefinition != null)
+ {
+ index_GreenLight = greenDefinition.IONum;
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"{iConfig.Name}鏈厤缃豢鑹茬伅杈撳嚭绱㈠紩", "");
+ }
+
+ var yellowDefinition = iConfig.IODefinitionCollection.FirstOrDefault(u => u.IOPreStatement == IOPrestatement.Light_Yellow);
+ if (yellowDefinition != null)
+ {
+ index_YellowLight = yellowDefinition.IONum;
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"{iConfig.Name}鏈厤缃粍鑹茬伅杈撳嚭绱㈠紩", "");
+ }
+
+ var beepDefinition = iConfig.IODefinitionCollection.FirstOrDefault(u => u.IOPreStatement == IOPrestatement.Beep);
+ if (beepDefinition != null)
+ {
+ index_Beep = beepDefinition.IONum;
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"{iConfig.Name}鏈厤缃渹楦e櫒杈撳嚭绱㈠紩", "");
+ }
+
+ var lightDefinition = iConfig.IODefinitionCollection.FirstOrDefault(u => u.IOPreStatement == IOPrestatement.Light);
+ if (lightDefinition != null)
+ {
+ index_NormalLight = lightDefinition.IONum;
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"{iConfig.Name}鏈厤缃棩鍏夌伅杈撳嚭绱㈠紩", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈厤缃澘鍗¤澶�", "");
}
}
@@ -66,7 +164,14 @@
// }
//}
+ if (IsSafetyBeamTrigged || IsSafetyDoorTrigged)
+ {
+ LogAsync(DateTime.Now, $"{(IsSafetyDoorTrigged ? "瀹夊叏闂�" : "")}{(IsSafetyBeamTrigged ? " 瀹夊叏鍏夌嚎" : "")}瑙﹀彂涓紝澶嶄綅澶辫触", "");
+ return new ProcessResponse(false);
+ }
+
MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice);
+ //(invokeDevice as IMotionCard).Reset();
RaisedAlarm("");
MachineState = MachineState.Ready;
@@ -175,38 +280,145 @@
return new ProcessResponse(_pauseHandle.WaitResult);
}
- [ProcessMethod("MotionCardBase", "SwitchLightRed", "鍒囨崲鎸囩ず鐏�-绾�", InvokeType.TestInvoke)]
- public ProcessResponse SwitchLightRed(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ #region 涓夎壊鐏� & 铚傞福鍣�
+ //[ProcessMethod("MotionCardBase", "SwitchLightRed", "鍒囨崲鎸囩ず鐏�-绾�", InvokeType.TestInvoke)]
+ //public ProcessResponse SwitchLightRed(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ //{
+ // MotionCardDefaultRun("SwitchLightRed", ref opConfig, ref invokeDevice);
+ // return new ProcessResponse(true);
+ //}
+
+ //[ProcessMethod("MotionCardBase", "SwitchLightYellow", "鍒囨崲鎸囩ず鐏�-榛�", InvokeType.TestInvoke)]
+ //public ProcessResponse SwitchLightYellow(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ //{
+ // return new ProcessResponse(true);
+ //}
+
+ //[ProcessMethod("MotionCardBase", "SwitchLightGreen", "鍒囨崲鎸囩ず鐏�-缁�", InvokeType.TestInvoke)]
+ //public ProcessResponse SwitchLightGreen(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ //{
+ // return new ProcessResponse(true);
+ //}
+
+ //[ProcessMethod("MotionCardBase", "SwitchBeep", "鍒囨崲铚傞福鍣�", InvokeType.TestInvoke)]
+ //public ProcessResponse SwitchBeep(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ //{
+ // return new ProcessResponse(true);
+ //}
+
+ //[ProcessMethod("MotionCardBase", "SwitchNormalLight", "鍒囨崲鏃ュ厜鐏�", InvokeType.TestInvoke)]
+ //public ProcessResponse SwitchNormalLight(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ //{
+ // MotionCardDefaultRun("SwitchNormalLight", ref opConfig, ref invokeDevice);
+
+ // return new ProcessResponse(true);
+ //}
+
+ int index_RedLight = -1;
+ int index_GreenLight = -1;
+ int index_YellowLight = -1;
+ int index_Beep = -1;
+ int index_NormalLight = -1;
+ MotionCardBase outputCtrlCard = null;
+
+ public void SwitchLightRed(bool isOn)
{
- MotionCardDefaultRun("SwitchLightRed", ref opConfig, ref invokeDevice);
- return new ProcessResponse(true);
+ if (index_RedLight >= 0)
+ {
+ if (outputCtrlCard != null)
+ {
+ outputCtrlCard.WriteOutput((short)index_RedLight, isOn ? IOValue.TRUE : IOValue.FALSE);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈缃澘鍗¤緭鍑鸿澶�", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "绾㈣壊鐏湭閰嶇疆姝g‘杈撳嚭绱㈠紩", "");
+ }
}
- [ProcessMethod("MotionCardBase", "SwitchLightYellow", "鍒囨崲鎸囩ず鐏�-榛�", InvokeType.TestInvoke)]
- public ProcessResponse SwitchLightYellow(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ public void SwitchLightYellow(bool isOn)
{
- return new ProcessResponse(true);
+ if (index_YellowLight >= 0)
+ {
+ if (outputCtrlCard != null)
+ {
+ outputCtrlCard.WriteOutput((short)index_YellowLight, isOn ? IOValue.TRUE : IOValue.FALSE);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈缃澘鍗¤緭鍑鸿澶�", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "榛勮壊鐏湭閰嶇疆姝g‘杈撳嚭绱㈠紩", "");
+ }
}
- [ProcessMethod("MotionCardBase", "SwitchLightGreen", "鍒囨崲鎸囩ず鐏�-缁�", InvokeType.TestInvoke)]
- public ProcessResponse SwitchLightGreen(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ public void SwitchLightGreen(bool isOn)
{
- return new ProcessResponse(true);
+ if (index_GreenLight >= 0)
+ {
+ if (outputCtrlCard != null)
+ {
+ outputCtrlCard.WriteOutput((short)index_GreenLight, isOn ? IOValue.TRUE : IOValue.FALSE);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈缃澘鍗¤緭鍑鸿澶�", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "缁胯壊鐏湭閰嶇疆姝g‘杈撳嚭绱㈠紩", "");
+ }
}
- [ProcessMethod("MotionCardBase", "SwitchBeep", "鍒囨崲铚傞福鍣�", InvokeType.TestInvoke)]
- public ProcessResponse SwitchBeep(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ public void SwitchLight(bool isOn)
{
- return new ProcessResponse(true);
+ if (index_NormalLight >= 0)
+ {
+ if (outputCtrlCard != null)
+ {
+ outputCtrlCard.WriteOutput((short)index_NormalLight, isOn ? IOValue.TRUE : IOValue.FALSE);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈缃澘鍗¤緭鍑鸿澶�", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鐓ф槑鐏湭閰嶇疆姝g‘杈撳嚭绱㈠紩", "");
+ }
}
- [ProcessMethod("MotionCardBase", "SwitchNormalLight", "鍒囨崲鏃ュ厜鐏�", InvokeType.TestInvoke)]
- public ProcessResponse SwitchNormalLight(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ public void SwitchBeep(bool isOn)
{
- MotionCardDefaultRun("SwitchNormalLight", ref opConfig, ref invokeDevice);
+ if (Config.IsBeepBlocked)
+ return;
- return new ProcessResponse(true);
+ if (index_Beep >= 0)
+ {
+ if (outputCtrlCard != null)
+ {
+ outputCtrlCard.WriteOutput((short)index_Beep, isOn ? IOValue.TRUE : IOValue.FALSE);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "鏈缃澘鍗¤緭鍑鸿澶�", "");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, "铚傞福鍣ㄦ湭閰嶇疆姝g‘杈撳嚭绱㈠紩", "");
+ }
}
+ #endregion
private void MotionCardDefaultRun(string methodCode, ref IOperationConfig opConfig, ref IDevice invokeDevice)
{
@@ -234,5 +446,55 @@
motionCard.Run(opConfig);
}
}
+
+ #region 瀹夊叏闂� & 瀹夊叏鍏夌嚎
+ bool isSafetyDoorTrigged = false;
+ bool isSafetyBeamTrigged = false;
+
+ public bool IsSafetyDoorTrigged
+ {
+ get => !Config.IsSafetyDoorBlocked && isSafetyDoorTrigged;
+ set => isSafetyDoorTrigged = value;
+ }
+ public bool IsSafetyBeamTrigged
+ {
+ get => !Config.IsSafetyBeamBlocked && isSafetyBeamTrigged;
+ set => isSafetyBeamTrigged = value;
+ }
+
+ [ProcessMethod("", "SafetyDoorSignal", "瀹夊叏闂ㄤ俊鍙风洃鎺э紝姝e父ON锛孫FF鏃舵姤璀�", InvokeType.TestInvoke)]
+ public ProcessResponse SafetyDoorSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
+ throw new ProcessException("瀹夊叏闂ㄧ洃鎺ф湭閰嶇疆杈撳叆淇″彿");
+
+ IsSafetyDoorTrigged = opConfig.InputPara[0] == 0;
+
+ if (IsSafetyDoorTrigged)
+ {
+ RaisedAlarm("瀹夊叏闂ㄦ湭姝e父鍏抽棴");
+ MachineState = MachineState.Alarm;
+ }
+
+ return new ProcessResponse(true);
+ }
+
+ [ProcessMethod("", "SafetyBeamSignal", "瀹夊叏鍏夊箷淇″彿鐩戞帶锛屾甯窸N锛孫FF鏃舵姤璀�", InvokeType.TestInvoke)]
+ public ProcessResponse SafetyBeamSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
+ throw new ProcessException("瀹夊叏鍏夊箷鐩戞帶鏈厤缃緭鍏ヤ俊鍙�");
+
+ IsSafetyBeamTrigged = opConfig.InputPara[0] == 0;
+
+ if (IsSafetyBeamTrigged)
+ {
+ RaisedAlarm("瀹夊叏鍏夌嚎琚伄鎸�");
+ MachineState = MachineState.Alarm;
+ }
+
+ return new ProcessResponse(true);
+ }
+ #endregion
}
}
--
Gitblit v1.8.0