src/Bro.Common.Device/DeviceBase/MotionCardBase.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.Common.Model/Helper/EnumHelper.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.Common.Model/Model/IOItem.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.Device.GTSCard/GTSCardDriver.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/Bro.M071.Process.csproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/M071Config.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/M071Models.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/M071Process.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/M071Process_IO.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/Bro.M071.Process/M071Process_MotionCard.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -12,6 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static Bro.Common.Helper.EnumHelper; namespace Bro.Common.Base { @@ -26,7 +27,7 @@ public abstract void ResetAlarm(); public abstract ResponseMessage Run(IOperationConfig config); public void ExcuteMonitorInvok(DateTime dateTime, string invokeDevice, IDevice device, IMonitorSet monitorSet) public void ExcuteMonitorInvoke(DateTime dateTime, string invokeDevice, IDevice device, IMonitorSet monitorSet) { OnMonitorInvoke?.BeginInvoke(dateTime, invokeDevice, device, monitorSet, null, null); } @@ -43,6 +44,10 @@ return InitialConfig as MotionCardInitialConfigBase; } } public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); public abstract void WriteOutput(short cardNum, short index, IOValue value); } public class MotionCardInitialConfigBase : InitialConfigBase, IMonitorConfig @@ -126,6 +131,7 @@ #endregion } [Device("MotionCardBase", "板卡操作配置基类", EnumHelper.DeviceAttributeType.OperationConfig)] public class MotionCardOperationConfigBase : OperationConfigBase, IComplexDisplay { [Category("IO操作配置")] @@ -199,6 +205,16 @@ } } [Device("MotionCardOperationConfigCollection", "板卡操作配置基类集合", EnumHelper.DeviceAttributeType.OperationConfig)] public class MotionCardOperationConfigCollection : OperationConfigBase { [Category("复位操作")] [Description("板卡操作配置基类集合,依次执行")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))] public List<MotionCardOperationConfigBase> MotionCardOpsCollection { get; set; } = new List<MotionCardOperationConfigBase>(); } public class IORefrenceItemCollectionEditor : CollectionEditor { protected override CollectionForm CreateCollectionForm() src/Bro.Common.Model/Helper/EnumHelper.cs
@@ -577,6 +577,16 @@ OUTPUT = 1 } public enum IOValue { [Description("关闭")] FALSE = 0, [Description("开启")] TRUE = 1, [Description("反转")] REVERSE = 2, } /// <summary> /// PubSubCenter事件中心的消息类型 /// </summary> @@ -593,5 +603,14 @@ //[Description("更新数据")] //UpdateData, } public enum MachineState { Unknown, Ready, Running, Alarm, Pause, } } } src/Bro.Common.Model/Model/IOItem.cs
@@ -22,8 +22,9 @@ /// IO点的值 /// </summary> [Category("IO配置")] [Description("IO数值")] public virtual int Value { get; set; } [Description("IO状态")] [TypeConverter(typeof(EnumDescriptionConverter<IOValue>))] public virtual IOValue Value { get; set; } /// <summary> /// IO点是in还是out @@ -44,7 +45,7 @@ public virtual string GetDisplayText() { return $"{IOType.GetEnumDescription()}-{IONum}-{Value}"; return $"{IOType.GetEnumDescription()}-{IONum}-{Value.GetEnumDescription()}"; } public int GetHashCode(object obj) @@ -70,7 +71,7 @@ [Browsable(false)] [JsonIgnore] public override int Value { get; set; } public override IOValue Value { get; set; } public override string GetDisplayText() { @@ -86,8 +87,8 @@ public IODefinition IOItem { get; set; } = new IODefinition(); [Category("IO操作配置")] [Description("需要操作的IO的数值")] public int CheckValue [Description("需要操作的IO的状态")] public IOValue CheckValue { get => IOItem.Value; set => IOItem.Value = value; @@ -99,7 +100,7 @@ public string GetDisplayText() { return IOItem.IODesc + "-" + CheckValue; return IOItem.IODesc + "-" + CheckValue.GetEnumDescription(); } } src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -652,16 +652,17 @@ /// <param name="cardNum">卡号</param> /// <param name="index">输出口,返回1-16</param> /// <param name="value">false表示输出,true表示关闭</param> public void WriteOut(short cardNum, short index, bool value) public override void WriteOutput(short cardNum, short index, IOValue value) { short outNum = (short)(index % 100 + 1); if (value) if ((int)value <= 1) { GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, 0); GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value); } else { GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, 1); 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)); } } @@ -687,7 +688,7 @@ #region IMonitor public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); //public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); public List<IOItem> GetMonitorValues() @@ -706,13 +707,13 @@ IOItem inItem = new IOItem() { IONum = index, Value = (inValue & (1 << index)) == 0 ? 1 : 0, Value = (inValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE, IOType = IOType.INPUT }; IOItem outItem = new IOItem() { IONum = index, Value = (outValue & (1 << index)) == 0 ? 1 : 0, Value = (outValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE, IOType = IOType.OUTPUT }; result.Add(inItem); @@ -801,13 +802,12 @@ { MotionCardWarningSet warningSet = wSet as MotionCardWarningSet; bool isOn = ((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0); bool isOn = (((int)((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value)) >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0); if (warningSet.CurrentStatus != isOn) { warningSet.CurrentStatus = isOn; warningSet.TriggerTime = DateTime.Now; warningSet.WarningDescription = $"警报:{warningSet.Name}-触发索引:{warningSet.TriggerIndex}-{warningSet.WarningIOModel.GetEnumDescription()}:{warningSet.WarningCode}"; SaveAlarmCSVAsync(DateTime.Now, this.Name, warningSet); ExcuteMonitorAlarm(DateTime.Now, this, warningSet); } @@ -828,7 +828,7 @@ if (newIOItem?.Value != oldIOItem?.Value) { if (monitorSet.TriggerValue == -999 || newIOItem.Value == monitorSet.TriggerValue) if (monitorSet.TriggerValue == -999 || (int)newIOItem.Value == monitorSet.TriggerValue) { if (monitorSet.OpConfig == null) { @@ -840,7 +840,7 @@ // return tempNew[index].Value; //}).ToList(); ExcuteMonitorInvok(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet); ExcuteMonitorInvoke(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet); } } }); src/Bro.M071.Process/Bro.M071.Process.csproj
@@ -110,7 +110,7 @@ <Compile Include="M071Config.cs" /> <Compile Include="M071Models.cs" /> <Compile Include="M071Process.cs" /> <Compile Include="M071Process_IO.cs" /> <Compile Include="M071Process_MotionCard.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="UI\KeyIndicator.cs" /> <Compile Include="UI\M071Node.cs" /> src/Bro.M071.Process/M071Config.cs
@@ -44,18 +44,21 @@ [Category("背景图片设置")] [Description("运行背景图片路径")] [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] [DisplayName("背景图片")] public string BackgroundImagePath { get; set; } [Category("检测设置")] [Description("拍摄点位设置集合")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor<SnapshotPoint>), typeof(UITypeEditor))] [DisplayName("拍摄点位")] public List<SnapshotPoint> SnapshotPointCollection { get; set; } = new List<SnapshotPoint>(); [Category("检测设置")] [Description("视觉检测单键配置集合")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor<KeyUnit>), typeof(UITypeEditor))] [DisplayName("单键配置")] public List<KeyUnit> KeyUnitCollection { get; set; } = new List<KeyUnit>(); [Category("检测设置")] src/Bro.M071.Process/M071Models.cs
@@ -312,7 +312,7 @@ [Category("单键配置")] [Description("单键结果配置")] [TypeConverter(typeof(KeyUnitResultConverter))] public string KeyResult { get; set; } = ""; public string KeyResultId { get; set; } = ""; public List<HImage> KeyImages = new List<HImage>(); @@ -342,7 +342,7 @@ { string msg = Key; msg += string.IsNullOrWhiteSpace(KeyResult) ? "" : $"-{KeyResult}"; msg += string.IsNullOrWhiteSpace(KeyResultId) ? "" : $"-{KeyResultId}"; return msg; } src/Bro.M071.Process/M071Process.cs
@@ -110,7 +110,7 @@ if (keyRespone.Count == 0) throw new ProcessException($"{u.GetDisplayText()}对应的单键不存在或不可用"); if (b.KeyResult == "All") if (b.KeyResultId == "All") { keyRespone.SelectMany(kr => kr.KeyResultList).ToList().ForEach(r => { @@ -119,7 +119,7 @@ } else { b.MeasureValueDict[b.KeyResult] = null; b.MeasureValueDict[b.KeyResultId] = null; } }); }); @@ -236,39 +236,6 @@ BarCode = ""; return new ProcessResponse(true); } /// <summary> /// 暂停标志 /// WaitHandle 暂停句柄 默认为非阻塞 可执行 /// WaitResult 暂停标志 true 正常执行 false 暂停中 /// </summary> ManualWaitConfirm _pauseHandle = new ManualWaitConfirm() { WaitHandle = new ManualResetEvent(true), WaitResult = true, }; [ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)] public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { if (_pauseHandle.WaitResult) { #region 板卡暂停动作 #endregion _pauseHandle.WaitHandle.Reset(); } else { #region 板卡恢复动作 #endregion _pauseHandle.WaitHandle.Set(); } _pauseHandle.WaitResult = !_pauseHandle.WaitResult; return new ProcessResponse(_pauseHandle.WaitResult); } #region 私有方法 src/Bro.M071.Process/M071Process_IO.cs
File was deleted src/Bro.M071.Process/M071Process_MotionCard.cs
New file @@ -0,0 +1,217 @@ using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; namespace Bro.M071.Process { public partial class M071Process { Timer _resetTimer = null; const int FULLRESETTIME = 5; MachineState machineState = MachineState.Unknown; MachineState MachineState { get => machineState; set { machineState = value; switch (machineState) { case MachineState.Ready: break; case MachineState.Running: break; case MachineState.Alarm: break; case MachineState.Pause: break; default: break; } } } [ProcessMethod("MotionCardBase", "Reset", "简单复位操作", InvokeType.TestInvoke)] public ProcessResponse Reset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { //if (opConfig == null) //{ // var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "Reset"); // if (monitorSet == null) // throw new ProcessException("未配置默认复位操作"); // opConfig = monitorSet.OpConfig; // if (opConfig == null) // throw new ProcessException("未配置复位操作具体配置动作"); // if (invokeDevice == null) // { // invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice); // if (invokeDevice == null) // throw new ProcessException("未配置复位操作执行设备"); // } //} MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice); if (_resetTimer == null) { _resetTimer = new Timer(FullReset, null, -1, -1); } if (opConfig.InputPara.Count > 0) { //大复位信号 _resetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1); } //if (invokeDevice is MotionCardBase motionCard) //{ // motionCard.Run(opConfig); //} return new ProcessResponse(true); } private void FullReset(object state) { FullReset(null, null, null); } [ProcessMethod("MotionCardOperationConfigCollection", "FullReset", "大复位操作", InvokeType.TestInvoke)] public ProcessResponse FullReset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { //if (opConfig == null) //{ // var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "FullReset"); // if (monitorSet == null) // throw new ProcessException("未配置默认大复位操作"); // opConfig = monitorSet.OpConfig; // if (opConfig == null) // throw new ProcessException("未配置大复位操作具体配置动作"); // if (invokeDevice == null) // { // invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice); // if (invokeDevice == null) // throw new ProcessException("未配置大复位操作执行设备"); // } //} //if (invokeDevice is MotionCardBase motionCard) //{ // motionCard.Run(opConfig); //} MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice); return new ProcessResponse(true); } /// <summary> /// 暂停标志 /// WaitHandle 暂停句柄 默认为非阻塞 可执行 /// WaitResult 暂停标志 true 正常执行 false 暂停中 /// </summary> ManualWaitConfirm _pauseHandle = new ManualWaitConfirm() { WaitHandle = new ManualResetEvent(true), WaitResult = true, }; [ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)] public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { if (_pauseHandle.WaitResult) { #region 板卡暂停动作 #endregion _pauseHandle.WaitHandle.Reset(); } else { #region 板卡恢复动作 #endregion _pauseHandle.WaitHandle.Set(); } _pauseHandle.WaitResult = !_pauseHandle.WaitResult; return new ProcessResponse(_pauseHandle.WaitResult); } [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); } private void MotionCardDefaultRun(string methodCode, ref IOperationConfig opConfig, ref IDevice invokeDevice) { IMonitorSet monitorSet = null; if (opConfig == null) { monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == methodCode); if (monitorSet == null) throw new ProcessException("未配置默认操作"); opConfig = monitorSet.OpConfig; if (opConfig == null) throw new ProcessException("未配置具体配置动作"); } if (invokeDevice == null) { invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice); if (invokeDevice == null) throw new ProcessException("未配置操作执行设备"); } if (invokeDevice is MotionCardBase motionCard) { motionCard.Run(opConfig); } } } }