From 1c4426810c71eead57084be8a18ade8d314dd8c4 Mon Sep 17 00:00:00 2001 From: patrick <patrick.xu@broconcentric.com> Date: 星期二, 10 十二月 2019 14:24:31 +0800 Subject: [PATCH] 1. 重构项目 --- src/A032.Process/ProcessControl_AGV.cs | 8 src/Bro.Device.SeerAGV/SeerAGVConfig.cs | 28 +- src/A032.Process/ProcessConfig.cs | 6 src/A032.Config/ConfigFrm.cs | 28 +- src/A032.Process/ProcessControl_Robot.cs | 4 src/A032.Process/ProcessControl_Calibration.cs | 4 src/Bro.Common.Model/Interface/IDeviceConfig.cs | 13 + src/Bro.Device.SeerAGV/SeerAGVDriver.cs | 7 src/A032.Process/ProcessControl.cs | 54 +++++- src/Bro.Device.AuboRobot/AuboRobotConfig.cs | 36 +-- src/A032.Process/AGVPath.cs | 4 src/A032.Process/ProcessControl_Method.cs | 16 - src/Bro.Common.Model/Interface/IMonitor.cs | 3 src/Bro.Device.AuboRobot/AuboRobotDriver.cs | 33 +++- src/Bro.Device.Common/Base/DeviceBase.cs | 3 src/Bro.Device.Common/Base/DeviceConfigBase.cs | 49 ++++++ src/Bro.Device.OmronFins/OmronFinsDriver.cs | 2 src/A032.Process/AGVBindUnit.cs | 13 + src/Bro.Device.Common/DeviceBase/PLCBase.cs | 91 +++-------- src/A032.Process/ProcessControl_Task.cs | 28 +- src/Bro.Common.Model/Model/WarningSet.cs | 28 ++- src/Bro.Device.Common/DeviceBase/CameraBase.cs | 2 22 files changed, 253 insertions(+), 207 deletions(-) diff --git a/src/A032.Config/ConfigFrm.cs b/src/A032.Config/ConfigFrm.cs index edefec0..f83c982 100644 --- a/src/A032.Config/ConfigFrm.cs +++ b/src/A032.Config/ConfigFrm.cs @@ -267,21 +267,21 @@ private void cboCalibrationMethod_SelectedIndexChanged(object sender, EventArgs e) { - //if (cboCalibrationMethod.SelectedIndex >= 0) - //{ - // string methodCode = cboCalibrationMethod.SelectedValue.ToString(); + if (cboCalibrationMethod.SelectedIndex >= 0) + { + string methodCode = cboCalibrationMethod.SelectedValue.ToString(); - // _calibrationMethod = _calibrationMethodDict[_calibrationMethodDict.Keys.FirstOrDefault(u => u.MethodCode == methodCode)]; + _calibrationMethod = _calibrationMethodDict[_calibrationMethodDict.Keys.FirstOrDefault(u => u.MethodCode == methodCode)]; - // if (Process.StationConfig.ProcessOpConfigDict.Keys.Contains(methodCode)) - // { - // propCalibrationConfig.SelectedObject = Process.StationConfig.ProcessOpConfigDict[methodCode]; - // } - // else - // { - // MessageBox.Show(@"Config of " + methodCode + @" is not found"); - // } - //} + if (Process.StationConfig.ProcessOpConfigDict.Keys.Contains(methodCode)) + { + propCalibrationConfig.SelectedObject = Process.StationConfig.ProcessOpConfigDict[methodCode]; + } + else + { + MessageBox.Show(@"Config of " + methodCode + @" is not found"); + } + } } private void btnStartCalibration_Click(object sender, EventArgs e) @@ -320,7 +320,7 @@ List<IDevice> _deviceList = new List<IDevice>(); private void InitialDevices() { - _deviceList = (Process as ProcessControl).GetDeviceList(); + _deviceList = (Process as ProcessControl).DeviceList; List<ISimpleDevice> list = _deviceList.Select(u => u as ISimpleDevice).ToList(); UIHelper.SetCombo(cboCalibDevices, list, "Name", "Id"); diff --git a/src/A032.Process/AGVBindUnit.cs b/src/A032.Process/AGVBindUnit.cs index f4e06cc..5eef59f 100644 --- a/src/A032.Process/AGVBindUnit.cs +++ b/src/A032.Process/AGVBindUnit.cs @@ -8,10 +8,8 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; -using System.Threading; namespace A032.Process { @@ -154,7 +152,7 @@ [Browsable(false)] [JsonIgnore] - public string WarningMsg { get; set; } = ""; + public List<string> WarningMsg { get; set; } = new List<string>(); #endregion #region 璁惧 @@ -203,6 +201,15 @@ public AGVBindUnit() { } + + public void Reset() + { + WarningMsg.Clear(); + UnitState = AGVState.Idle; + + AGV.ResetAlarm(); + Robot.ResetAlarm(); + } } public class AGVDeviceConverter : ComboBoxItemTypeConvert diff --git a/src/A032.Process/AGVPath.cs b/src/A032.Process/AGVPath.cs index 426a620..f908ae3 100644 --- a/src/A032.Process/AGVPath.cs +++ b/src/A032.Process/AGVPath.cs @@ -4,13 +4,9 @@ using Bro.Common.Model.Interface; using Bro.Device.HikCamera; using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace A032.Process { diff --git a/src/A032.Process/ProcessConfig.cs b/src/A032.Process/ProcessConfig.cs index f71d683..afe171a 100644 --- a/src/A032.Process/ProcessConfig.cs +++ b/src/A032.Process/ProcessConfig.cs @@ -1,5 +1,4 @@ -锘縰sing Autofac; -using Bro.Common.Base; +锘縰sing Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; @@ -10,13 +9,10 @@ using Bro.Device.SeerAGV; using Bro.Device.Station; using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.Linq; -using System.Text; -using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; namespace A032.Process diff --git a/src/A032.Process/ProcessControl.cs b/src/A032.Process/ProcessControl.cs index 1c21d00..f823dc3 100644 --- a/src/A032.Process/ProcessControl.cs +++ b/src/A032.Process/ProcessControl.cs @@ -3,7 +3,6 @@ using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; -using Bro.Common.Model.Interface; using Bro.Common.PubSub; using Bro.Device.AuboRobot; using Bro.Device.OmronFins; @@ -35,7 +34,7 @@ { #region AutoFac娉ㄥ唽 builder.RegisterInstance<ProcessConfig>(StationConfig as ProcessConfig); - builder.RegisterInstance<List<IDevice>>(GetDeviceList()); + builder.RegisterInstance<List<IDevice>>(DeviceList); builder.RegisterInstance<List<ProcessMethodAttribute>>(CollectProcessMethods()); if (isBuild) @@ -119,6 +118,8 @@ Dictionary<string, AuboRobotDriver> RobotDict = new Dictionary<string, AuboRobotDriver>(); Dictionary<string, SeerAGVDriver> AGVDict = new Dictionary<string, SeerAGVDriver>(); Dictionary<string, CameraBase> CameraDict = new Dictionary<string, CameraBase>(); + + public List<IDevice> DeviceList { get; set; } = new List<IDevice>(); private ProcessConfig Config { get => StationConfig as ProcessConfig; } @@ -296,12 +297,16 @@ WarningRemains.CollectionChanged -= _warningRemains_CollectionChanged; WarningRemains.CollectionChanged += _warningRemains_CollectionChanged; + #region 璁惧鍒濆鍖� + DeviceList = new List<IDevice>(); + InitialPLCs(); InitialAGVs(); InitialRobots(); InitialCameras(); InitialAGVBindUnit(); //InitialMachineTrayNums(); + #endregion AutoFacRegister(); @@ -345,6 +350,8 @@ CameraBase camera = CameraHelper.GetCameraInstance(c.DriverType); camera.InitialConfig = c; CameraDict[camera.InitialConfig.ID] = camera; + + DeviceList.Add(camera); }); } @@ -361,6 +368,8 @@ plc.OnMonitorAlarm += OnMonitorAlarm; plc.OnMonitorInvoke += OnMonitorInvoke; + + DeviceList.Add(plc); }); } @@ -381,6 +390,8 @@ robot.OnMonitorAlarm += OnMonitorAlarm; robot.OnMonitorInvoke += OnMonitorInvoke; + + DeviceList.Add(robot); }); } @@ -395,10 +406,15 @@ agv.OnMonitorAlarm -= OnMonitorAlarm; agv.OnMonitorInvoke -= OnMonitorInvoke; + agv.OnMonitorAlarm += OnMonitorAlarm; + agv.OnMonitorInvoke += OnMonitorInvoke; + agv.OnLog = OnDeviceLog; agv.OnAGVPositoinChanged = OnAGVPositionChanged; agv.OnAGVTaskStatusChanged = OnAGVTaskStatusChanged; agv.OnAGVBatteryLvlChanged = OnAGVBatteryLvlChanged; + + DeviceList.Add(agv); }); } @@ -542,17 +558,17 @@ }); } - public List<IDevice> GetDeviceList() - { - List<IDevice> list = new List<IDevice>(); + //public List<IDevice> GetDeviceList() + //{ + // List<IDevice> list = new List<IDevice>(); - list.AddRange(PLCDict.Values); - list.AddRange(RobotDict.Values); - list.AddRange(AGVDict.Values); - list.AddRange(CameraDict.Values); + // list.AddRange(PLCDict.Values); + // list.AddRange(RobotDict.Values); + // list.AddRange(AGVDict.Values); + // list.AddRange(CameraDict.Values); - return list; - } + // return list; + //} #region IMonitor鐩戝惉 private void OnMonitorInvoke(DateTime dt, IDevice device, MonitorSet monitorSet) @@ -631,8 +647,22 @@ #endregion } - private void OnMonitorAlarm(DateTime dt, IDevice device, WarningSet warning, bool isAlarmRaised) + private void OnMonitorAlarm(DateTime dt, IDevice device, WarningSet warning) { + var bind = Config.AGVBindCollection.FirstOrDefault(u => u.CameraId == device.Id || u.RobotId == device.Id || u.AGVId == device.Id); + + if (bind == null) + { + throw new ProcessException($"{device.Name}鐨勫紓甯镐俊鎭湭鑳借幏鍙栫浉鍏崇粦瀹氳澶囦俊鎭�"); + } + + if (warning.CurrentStatus == warning.TriggerValue) + { + bind.WarningMsg.Add(warning.WarningDescription); + bind.UnitState = AGVState.Warning; + } + + //鏆傛椂涓嶆墽琛岃嚜鍔ㄥ浣嶏紝闇�瑕佹墜宸ュ浣� } //List<int> _monitorList = new List<int>(); diff --git a/src/A032.Process/ProcessControl_AGV.cs b/src/A032.Process/ProcessControl_AGV.cs index dcfacac..c3f9b64 100644 --- a/src/A032.Process/ProcessControl_AGV.cs +++ b/src/A032.Process/ProcessControl_AGV.cs @@ -1,9 +1,6 @@ 锘縰sing Bro.Common.Helper; using Bro.Device.SeerAGV; -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace A032.Process @@ -28,8 +25,9 @@ if (chargePosition == null) { - bind.WarningMsg = $"{bind.AGV.Name}鐩墠鏃犲彲鐢ㄥ厖鐢靛湴鍧�"; - new ProcessException(bind.WarningMsg); + string warningMsg = $"{bind.AGV.Name}鐩墠鏃犲彲鐢ㄥ厖鐢靛湴鍧�"; + bind.WarningMsg.Add(warningMsg); + new ProcessException(warningMsg); bind.UnitState = AGVState.Warning; } else diff --git a/src/A032.Process/ProcessControl_Calibration.cs b/src/A032.Process/ProcessControl_Calibration.cs index 7dad539..6c8770e 100644 --- a/src/A032.Process/ProcessControl_Calibration.cs +++ b/src/A032.Process/ProcessControl_Calibration.cs @@ -1,5 +1,4 @@ 锘縰sing A032.Process.Calibration; -using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; @@ -8,9 +7,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; namespace A032.Process diff --git a/src/A032.Process/ProcessControl_Method.cs b/src/A032.Process/ProcessControl_Method.cs index 00c656d..45a0f4f 100644 --- a/src/A032.Process/ProcessControl_Method.cs +++ b/src/A032.Process/ProcessControl_Method.cs @@ -1,21 +1,7 @@ -锘縰sing Bro.Common.Base; -using Bro.Common.Helper; +锘縰sing Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; -using Bro.Device.AuboRobot; -using Bro.Device.HikCamera; -using Bro.Device.SeerAGV; -using HalconDotNet; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Drawing; -using System.IO; using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace A032.Process { diff --git a/src/A032.Process/ProcessControl_Robot.cs b/src/A032.Process/ProcessControl_Robot.cs index ef57b2e..5214083 100644 --- a/src/A032.Process/ProcessControl_Robot.cs +++ b/src/A032.Process/ProcessControl_Robot.cs @@ -1,9 +1,5 @@ 锘縰sing Bro.Device.AuboRobot; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace A032.Process { diff --git a/src/A032.Process/ProcessControl_Task.cs b/src/A032.Process/ProcessControl_Task.cs index 4bf24ed..38abffe 100644 --- a/src/A032.Process/ProcessControl_Task.cs +++ b/src/A032.Process/ProcessControl_Task.cs @@ -9,12 +9,9 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; -using System.Drawing.Design; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -176,8 +173,9 @@ { if (bind.UnitState == AGVState.Warning) { - bind.WarningMsg = ""; - bind.UnitState = AGVState.Idle; + //bind.WarningMsg.Clear(); + //bind.UnitState = AGVState.Idle; + bind.Reset(); } }); @@ -189,8 +187,10 @@ if (bind != null && bind.UnitState == AGVState.Warning) { - bind.WarningMsg = ""; - bind.UnitState = AGVState.Idle; + //bind.WarningMsg.Clear(); + //bind.UnitState = AGVState.Idle; + + bind.Reset(); LogAsync(DateTime.Now, "Reset", $"鎵ц{bind.AGV.Name}澶嶄綅鎿嶄綔"); } @@ -287,7 +287,7 @@ } else { - bind = Config.AGVBindCollection.FirstOrDefault(u => u.Id == unitId); + bind = Config.AGVBindCollection.FirstOrDefault(u => u.Id == unitId && (u.UnitState == AGVState.Idle || u.UnitState == AGVState.IdleCharge)); } if (bind == null) @@ -436,7 +436,7 @@ bind.CurrentTaskId = ""; if (isWarningRaised) { - bind.WarningMsg = warningMsg; + bind.WarningMsg.Add(warningMsg); bind.UnitState = AGVState.Warning; } else @@ -447,8 +447,9 @@ if (!isNotTimeout) { - bind.WarningMsg = $"{bind.AGV.Name}鑾峰彇鐢垫睜鐘舵�佽秴鏃�"; - new ProcessException(bind.WarningMsg); + string msg = $"{bind.AGV.Name}鑾峰彇鐢垫睜鐘舵�佽秴鏃�"; + bind.WarningMsg.Add(msg); + new ProcessException(msg); bind.UnitState = AGVState.Warning; } else @@ -462,8 +463,9 @@ if (chargePosition == null) { - bind.WarningMsg = $"{bind.AGV.Name}鐩墠鏃犲彲鐢ㄥ厖鐢靛湴鍧�"; - new ProcessException(bind.WarningMsg); + string msg = $"{bind.AGV.Name}鐩墠鏃犲彲鐢ㄥ厖鐢靛湴鍧�"; + bind.WarningMsg.Add(msg); + new ProcessException(msg); bind.UnitState = AGVState.Warning; } else diff --git a/src/Bro.Common.Model/Interface/IDeviceConfig.cs b/src/Bro.Common.Model/Interface/IDeviceConfig.cs index ec8236f..8bf5766 100644 --- a/src/Bro.Common.Model/Interface/IDeviceConfig.cs +++ b/src/Bro.Common.Model/Interface/IDeviceConfig.cs @@ -1,4 +1,6 @@ -锘縰sing System; +锘縰sing Bro.Common.Model; +using Bro.Common.Model.Interface; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -35,6 +37,15 @@ string DriverType { get; set; } } + public interface IMonitorInitialConfig + { + bool IsEnableMonitor { get; set; } + int ScanInterval { get; set; } + int Timeout { get; set; } + List<WarningSet> WarningSetCollection { get; set; } + List<MonitorSet> MonitorSetCollection { get; set; } + } + public interface ILog { string LogPath { get; set; } diff --git a/src/Bro.Common.Model/Interface/IMonitor.cs b/src/Bro.Common.Model/Interface/IMonitor.cs index be201fb..afb9d43 100644 --- a/src/Bro.Common.Model/Interface/IMonitor.cs +++ b/src/Bro.Common.Model/Interface/IMonitor.cs @@ -8,11 +8,12 @@ namespace Bro.Common.Model.Interface { public delegate void OnMonitorInvokeDelegate(DateTime dt, IDevice device, MonitorSet monitorSet); - public delegate void OnMonitorAlarmDelegate(DateTime dt, IDevice device, WarningSet warning, bool isAlarmRaised); + public delegate void OnMonitorAlarmDelegate(DateTime dt, IDevice device, WarningSet warning); public interface IMonitor { //List<int> GetMonitorValues(int startAddress, int length); void Monitor(); + void ResetAlarm(); event OnMonitorInvokeDelegate OnMonitorInvoke; event OnMonitorAlarmDelegate OnMonitorAlarm; diff --git a/src/Bro.Common.Model/Model/WarningSet.cs b/src/Bro.Common.Model/Model/WarningSet.cs index b9fe282..fd0765d 100644 --- a/src/Bro.Common.Model/Model/WarningSet.cs +++ b/src/Bro.Common.Model/Model/WarningSet.cs @@ -1,4 +1,5 @@ 锘縰sing Bro.Common.Helper; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -14,28 +15,37 @@ /// </summary> public class WarningSet : IComplexDisplay { - [Category("璀︽姤璁剧疆")] - [Description("璀︽姤浣嶇储寮�")] - public int WaringIndex { get; set; } + [Category("绱㈠紩璁剧疆")] + [Description("璀︽姤绱㈠紩鈥斺�斿瓧绱㈠紩")] + public int WarningIndex_Word { get; set; } - [Category("璀︽姤璁剧疆")] + [Category("绱㈠紩璁剧疆")] + [Description("璀︽姤绱㈠紩鈥斺�斾綅绱㈠紩")] + public int WarningIndex_Bit { get; set; } + + [Category("瑙﹀彂璁剧疆")] + [Description("true锛氶珮鐢靛钩瑙﹀彂鎶ヨ false锛氫綆鐢靛钩瑙﹀彂鎶ヨ")] + public bool TriggerValue { get; set; } = true; + + [Category("璀︽姤鍐呭")] [Description("璀︽姤浠g爜")] public string WarningCode { get; set; } - [Category("璀︽姤璁剧疆")] + [Category("璀︽姤鍐呭")] [Description("璀︽姤鎻忚堪")] public string WarningDescription { get; set; } - [Category("璀︽姤璁剧疆")] + [Category("绾у埆璁剧疆")] [Description("璀︽姤绾у埆")] public int WarningLvl { get; set; } = 0; - [Description("鎶ヨ宸ヤ綅")] - public int WorkPosition { get; set; } = 0; + [Browsable(false)] + [JsonIgnore] + public bool CurrentStatus { get; set; } = false; public string GetDisplayText() { - return WaringIndex + "-" + WarningCode + "-" + WarningDescription + "-" + WorkPosition; + return $"{WarningIndex_Word}:{WarningIndex_Bit}-{WarningCode}-{WarningDescription}"; } } } diff --git a/src/Bro.Device.AuboRobot/AuboRobotConfig.cs b/src/Bro.Device.AuboRobot/AuboRobotConfig.cs index 043faec..cfa159d 100644 --- a/src/Bro.Device.AuboRobot/AuboRobotConfig.cs +++ b/src/Bro.Device.AuboRobot/AuboRobotConfig.cs @@ -1,6 +1,7 @@ 锘縰sing Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Model; +using Bro.Common.Model.Interface; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; @@ -9,7 +10,7 @@ namespace Bro.Device.AuboRobot { [Device("AuboRobot", "濂ュ崥鏈哄櫒浜�", EnumHelper.DeviceAttributeType.InitialConfig)] - public class AuboRobotInitialConfig : InitialConfigBase + public class AuboRobotInitialConfig : InitialMonitorConfigBase { [Category("鏈哄櫒浜鸿缃�")] [Description("鏈哄櫒浜洪�氫俊IP")] @@ -39,36 +40,27 @@ [Description("鍔ㄤ綔瓒呮椂璁剧疆锛屽崟浣峬in")] public float OperationTimeout { get; set; } = 1; - [Category("IO鐩戝惉璁剧疆")] - [Description("IO鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")] + [Category("閫氫俊鎶ヨ閰嶇疆")] + [Description("閫氫俊杩囩▼涓弽棣堟姤璀︿唬鐮侀厤缃�")] [TypeConverter(typeof(CollectionCountConvert))] - [Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))] - public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>(); - - [Category("IO鐩戝惉璁剧疆")] - [Description("IO鐩戝惉闂撮殧锛屼互ms涓哄崟浣�")] - public int ScanInterval { get; set; } = 9999; - - [Category("IO鐩戝惉璁剧疆")] - [Description("鏄惁鍚敤IO鐩戝惉,true锛氱洃鍚� false锛氫笉鐩戝惉")] - public bool IsEnableMonitor { get; set; } = false; - - [Category("鎶ヨ閰嶇疆")] - [Description("鎶ヨ浠g爜閰嶇疆")] - [TypeConverter(typeof(CollectionCountConvert))] - [Editor(typeof(ComplexCollectionEditor<RobotWarningCode>), typeof(UITypeEditor))] - public List<RobotWarningCode> RobotWarnings { get; set; } = new List<RobotWarningCode>(); + [Editor(typeof(ComplexCollectionEditor<RobotReplyWarningCode>), typeof(UITypeEditor))] + public List<RobotReplyWarningCode> RobotReplyWarnings { get; set; } = new List<RobotReplyWarningCode>(); } - public class RobotWarningCode + public class RobotReplyWarningCode : IComplexDisplay { - [Category("鎶ヨ閰嶇疆")] + [Category("鍙嶉鎶ヨ閰嶇疆")] [Description("鎶ヨ浠g爜")] public int WarningCode { get; set; } - [Category("鎶ヨ閰嶇疆")] + [Category("鍙嶉鎶ヨ閰嶇疆")] [Description("鎶ヨ浠g爜鎻忚堪")] public string WarningDescription { get; set; } + + public string GetDisplayText() + { + return $"{WarningCode}-{WarningDescription}"; + } } [Device("AuboRobot", "濂ュ崥鏈哄櫒浜�", EnumHelper.DeviceAttributeType.OperationConfig)] diff --git a/src/Bro.Device.AuboRobot/AuboRobotDriver.cs b/src/Bro.Device.AuboRobot/AuboRobotDriver.cs index 02691de..54a3600 100644 --- a/src/Bro.Device.AuboRobot/AuboRobotDriver.cs +++ b/src/Bro.Device.AuboRobot/AuboRobotDriver.cs @@ -67,14 +67,13 @@ //Query Robot IOs //SendMsg(RobotMsgType.Send, 0, true, RobotMsgAction.IO, RobotMsgParas.Query, new List<string>()); - //scanMsg = new RobotMsg(); - //scanMsg.Action = RobotMsgAction.IO; - //scanMsg.Para1 = RobotMsgParas.Query; + scanMsg = new RobotMsg(); + scanMsg.Action = RobotMsgAction.IOQuery; - //Task.Run(() => - //{ - // Monitor(); - //}); + Task.Run(() => + { + Monitor(); + }); } protected override void Stop() @@ -309,7 +308,7 @@ if (errorCode != 0) { - var desc = IConfig.RobotWarnings.FirstOrDefault(u => u.WarningCode == errorCode); + var desc = IConfig.RobotReplyWarnings.FirstOrDefault(u => u.WarningCode == errorCode); throw new ProcessException($"{Name}{msg.ID}浠诲姟鍙嶉寮傚父{errorCode},寮傚父鎻忚堪锛歿(desc == null ? "鏃�" : desc.WarningDescription)}"); } @@ -508,6 +507,19 @@ protected virtual void MonitorCheckAndInvoke(List<int> tempNew, List<int> tempOld) { + IConfig.WarningSetCollection.ForEach(w => + { + if (w.WarningIndex_Word < 0 || w.WarningIndex_Word >= tempNew.Count) + return; + + bool isOn = tempNew[w.WarningIndex_Word] == 1; + if (w.CurrentStatus != isOn) + { + w.CurrentStatus = isOn; + OnMonitorAlarm?.BeginInvoke(DateTime.Now, this, w, null, null); + } + }); + IConfig.MonitorSetCollection.ForEach(m => { if (m.TriggerIndex < 0 || m.TriggerIndex >= tempNew.Count) @@ -537,6 +549,11 @@ } }); } + + public virtual void ResetAlarm() + { + IConfig.WarningSetCollection.ForEach(u => u.CurrentStatus = !u.TriggerValue); + } #endregion } } diff --git a/src/Bro.Device.Common/Base/DeviceBase.cs b/src/Bro.Device.Common/Base/DeviceBase.cs index 25b45fb..0d3c8dd 100644 --- a/src/Bro.Device.Common/Base/DeviceBase.cs +++ b/src/Bro.Device.Common/Base/DeviceBase.cs @@ -30,7 +30,6 @@ public Action<EnumHelper.DeviceState> OnDeviceStateChanged { get; set; } #endregion - int RetryTime = 3; /// <summary> /// 鍜岃澶囨殏鍋滅姸鎬佸叧鑱旂殑淇″彿閲� @@ -169,8 +168,6 @@ [JsonIgnore] public Dictionary<DeviceInputMethodAttribute, MethodInfo> InputMethods { get; set; } = new Dictionary<DeviceInputMethodAttribute, MethodInfo>(); - - //public event DeviceStateChangedDelegate OnDeviceStateChanged; diff --git a/src/Bro.Device.Common/Base/DeviceConfigBase.cs b/src/Bro.Device.Common/Base/DeviceConfigBase.cs index 0f28653..e708e99 100644 --- a/src/Bro.Device.Common/Base/DeviceConfigBase.cs +++ b/src/Bro.Device.Common/Base/DeviceConfigBase.cs @@ -1,5 +1,7 @@ 锘縰sing Bro.Common.Helper; using Bro.Common.Interface; +using Bro.Common.Model; +using Bro.Common.Model.Interface; using System; using System.Collections.Generic; using System.ComponentModel; @@ -43,5 +45,52 @@ [Category("鏃ュ織閰嶇疆")] [Description("true锛氬惎鐢ㄦ棩蹇楄褰� false锛氫笉鍚敤鏃ュ織璁板綍")] public bool IsEnableLog { get; set; } = false; + + public virtual List<string> GetHalconToolPathList() + { + return new List<string>(); + } + } + + public class InitialMonitorConfigBase : InitialConfigBase, IMonitorInitialConfig, IHalconToolPath + { + [Category("鐩戝惉璁剧疆")] + [Description("true:鍚敤鐩戝惉 false锛氫笉鍚敤鐩戝惉")] + public bool IsEnableMonitor { get; set; } = true; + + [Category("鐩戝惉璁剧疆")] + [Description("鎵弿闂撮殧鏃堕棿锛屽崟浣嶏細ms")] + public int ScanInterval { get; set; } = 100; + + [Category("鐩戝惉璁剧疆")] + [Description("瓒呮椂璁剧疆锛屽崟浣嶏細ms")] + public int Timeout { get; set; } = 500; + + [Category("鐩戝惉璁剧疆")] + [Description("璀︽姤閰嶇疆鍒楄〃")] + [TypeConverter(typeof(CollectionCountConvert))] + [Editor(typeof(ComplexCollectionEditor<WarningSet>), typeof(UITypeEditor))] + public List<WarningSet> WarningSetCollection { get; set; } = new List<WarningSet>(); + + [Category("鐩戝惉璁剧疆")] + [Description("鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")] + [TypeConverter(typeof(CollectionCountConvert))] + [Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))] + public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>(); + + public new virtual List<string> GetHalconToolPathList() + { + return MonitorSetCollection.SelectMany(u => + { + if (u.OpConfig is IHalconToolPath) + { + return (u.OpConfig as IHalconToolPath).GetHalconToolPathList(); + } + else + { + return new List<string>(); + } + }).ToList(); + } } } diff --git a/src/Bro.Device.Common/DeviceBase/CameraBase.cs b/src/Bro.Device.Common/DeviceBase/CameraBase.cs index ca8bb7e..30e33d5 100644 --- a/src/Bro.Device.Common/DeviceBase/CameraBase.cs +++ b/src/Bro.Device.Common/DeviceBase/CameraBase.cs @@ -654,7 +654,7 @@ [Category("鐩告満璁剧疆")] [Description("椹卞姩绫诲瀷")] [TypeConverter(typeof(CameraTypeConverter))] - public string DriverType { get; set; } = "HikCamera"; + public new string DriverType { get; set; } = "HikCamera"; [Category("鐩告満璁剧疆")] [Description("鐩告満搴忓垪鍙�")] diff --git a/src/Bro.Device.Common/DeviceBase/PLCBase.cs b/src/Bro.Device.Common/DeviceBase/PLCBase.cs index 2141644..9862511 100644 --- a/src/Bro.Device.Common/DeviceBase/PLCBase.cs +++ b/src/Bro.Device.Common/DeviceBase/PLCBase.cs @@ -58,8 +58,6 @@ if (newValues == null || newValues.Count == 0) continue; - //Stopwatch sw = new Stopwatch(); - //sw.Start(); if (oldValues.Count == newValues.Count) { var tempNew = new List<int>(newValues); @@ -67,13 +65,6 @@ MonitorCheckAndInvoke(tempNew, tempOld); } oldValues = new List<int>(newValues); - //sw.Stop(); - - //if (sw.ElapsedMilliseconds > 10) - //{ - // LogAsync(DateTime.Now, $"杞鏃堕棿锛歿sw.ElapsedMilliseconds}", ""); - // TimeRecordCSV(DateTime.Now, "杞鏃堕棿", (int)sw.ElapsedMilliseconds); - //} Thread.Sleep(PLCIConfig.ScanInterval); } @@ -88,42 +79,31 @@ protected virtual void MonitorCheckAndInvoke(List<int> tempNew, List<int> tempOld) { #region PLC璀︽姤淇℃伅 - //bool warningSignal = (m.TriggerIndex >= PLCIConfig.WarningStartIndex && m.TriggerIndex < PLCIConfig.WarningStartIndex + PLCIConfig.WarningLength); + PLCIConfig.WarningSetCollection.ForEach(w => + { + if (w.WarningIndex_Word < 0 || w.WarningIndex_Word >= tempNew.Count) + return; - //if (warningSignal) - //{ - // if (newValue != oldValue) - // { - // int warningIndex = m.TriggerIndex - PLCIConfig.WarningStartIndex; - // for (int i = 0; i < 16; i++) - // { - // var ws = PLCIConfig.WarningSetCollection.FirstOrDefault(w => w.WaringIndex == (warningIndex * 16) + i); + if (w.WarningIndex_Bit < 0 || w.WarningIndex_Bit > 16) + return; - // if (ws != null) - // { - // int newAlarmValue = newValue >> i & 1; - // int oldAlarmValue = oldValue >> i & 1; + bool isOn = ((tempNew[w.WarningIndex_Word] >> w.WarningIndex_Bit) & 1) == 1; - // if (newAlarmValue != oldAlarmValue) - // { - // OnMonitorAlarm?.BeginInvoke(ws, newAlarmValue == 1, null, null); - - // //浠呬繚瀛樿鎶ヤ俊鎭紝涓嶄繚瀛樻彁绀轰俊鎭� - // //if (ws.WarningLvl == 0) - // //{ - // // SaveAlarm(Config.StationCode, ws, newValue); - // //} - // } - // } - // } - // } - - // return; - //} + if (w.CurrentStatus != isOn) + { + w.CurrentStatus = isOn; + OnMonitorAlarm?.BeginInvoke(DateTime.Now, this, w, null, null); + } + }); #endregion PLCIConfig.MonitorSetCollection.ForEach(m => { + if (m.TriggerIndex < 0 || m.TriggerIndex >= tempNew.Count) + { + return; + } + int newValue = tempNew[m.TriggerIndex]; int oldValue = tempOld[m.TriggerIndex]; @@ -192,6 +172,11 @@ } while (repeatTime > 0); } } + + public virtual void ResetAlarm() + { + PLCIConfig.WarningSetCollection.ForEach(u => u.CurrentStatus = !u.TriggerValue); + } #endregion } @@ -212,36 +197,8 @@ { } - public class PLCInitialConfigBase : InitialConfigBase + public class PLCInitialConfigBase : InitialMonitorConfigBase { - [Category("鐩戝惉璁剧疆")] - [Description("璀︽姤閰嶇疆鍒楄〃")] - [TypeConverter(typeof(CollectionCountConvert))] - [Editor(typeof(ComplexCollectionEditor<WarningSet>), typeof(UITypeEditor))] - public List<WarningSet> WarningSetCollection { get; set; } = new List<WarningSet>(); - - [Category("鐩戝惉璁剧疆")] - [Description("鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")] - [TypeConverter(typeof(CollectionCountConvert))] - [Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))] - public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>(); - - [Category("鐩戝惉璁剧疆")] - [Description("鎵弿闂撮殧鏃堕棿锛屽崟浣嶏細ms")] - public int ScanInterval { get; set; } = 100; - - [Category("鐩戝惉璁剧疆")] - [Description("瓒呮椂璁剧疆锛屽崟浣嶏細ms")] - public int Timeout { get; set; } = 500; - - //[Category("杈撳嚭璁剧疆")] - //[Description("鏄惁鏃ュ織杈撳嚭")] - //public bool IsEnabelLog { get; set; } = false; - - //[Category("杈撳嚭璁剧疆")] - //[Description("杈撳嚭鏂囦欢璺緞")] - //public string LogPath { get; set; } = @"D:\PLCLog.txt"; - #region 鍦板潃璁剧疆 [Category("浜嬩欢鍦板潃璁剧疆")] [Description("浜嬩欢寮�濮嬪湴鍧�锛孭LC鐨勫疄闄呭瘎瀛樺櫒鍦板潃銆傚崄杩涘埗锛屼笉鍖呭惈鍔熻兘鐮併��")] diff --git a/src/Bro.Device.OmronFins/OmronFinsDriver.cs b/src/Bro.Device.OmronFins/OmronFinsDriver.cs index 695423b..13a3065 100644 --- a/src/Bro.Device.OmronFins/OmronFinsDriver.cs +++ b/src/Bro.Device.OmronFins/OmronFinsDriver.cs @@ -17,7 +17,7 @@ namespace Bro.Device.OmronFins { - public class OmronFinsDriver : PLCBase, IMonitor + public class OmronFinsDriver : PLCBase { #region PLCBase public override void Read(PLCOperationConfigBase config) diff --git a/src/Bro.Device.SeerAGV/SeerAGVConfig.cs b/src/Bro.Device.SeerAGV/SeerAGVConfig.cs index 55214f0..933114b 100644 --- a/src/Bro.Device.SeerAGV/SeerAGVConfig.cs +++ b/src/Bro.Device.SeerAGV/SeerAGVConfig.cs @@ -11,7 +11,7 @@ namespace Bro.Device.SeerAGV { [Device("SeerAGV", "SeerAGV", EnumHelper.DeviceAttributeType.InitialConfig)] - public class SeerAGVInitialConfig : InitialConfigBase + public class SeerAGVInitialConfig : InitialMonitorConfigBase { [Category("閫氫俊閰嶇疆")] [Description("AGVIP鍦板潃")] @@ -25,21 +25,21 @@ [Description("瀵艰埅绔彛")] public int GuidePort { get; set; } = 19206; - [Category("鐩戝惉閰嶇疆")] - [Description("鐩戝惉闂撮殧锛屽崟浣峬s")] - public int ScanInterval { get; set; } = 500; - //[Category("鐩戝惉閰嶇疆")] - //[Description("鐩戝惉鐨処O淇℃伅閰嶇疆闆嗗悎")] - //[TypeConverter(typeof(CollectionCountConvert))] - //[Editor(typeof(ComplexCollectionEditor<IODefinition>), typeof(UITypeEditor))] - //public List<IODefinition> IOCollection { get; set; } = new List<IODefinition>(); + //[Description("鐩戝惉闂撮殧锛屽崟浣峬s")] + //public int ScanInterval { get; set; } = 500; - [Category("鐩戝惉璁剧疆")] - [Description("鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")] - [TypeConverter(typeof(CollectionCountConvert))] - [Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))] - public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>(); + ////[Category("鐩戝惉閰嶇疆")] + ////[Description("鐩戝惉鐨処O淇℃伅閰嶇疆闆嗗悎")] + ////[TypeConverter(typeof(CollectionCountConvert))] + ////[Editor(typeof(ComplexCollectionEditor<IODefinition>), typeof(UITypeEditor))] + ////public List<IODefinition> IOCollection { get; set; } = new List<IODefinition>(); + + //[Category("鐩戝惉璁剧疆")] + //[Description("鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")] + //[TypeConverter(typeof(CollectionCountConvert))] + //[Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))] + //public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>(); [Category("鐩戝惉閰嶇疆")] [Description("鏄惁閲囩敤绠�鍗曠洃鍚ā寮忋�倀rue锛氱畝鍗曟ā寮忥紝鍙幏鍙栦换鍔$姸鎬侊紱false锛氬叏閮ㄦā寮忥紝鑾峰彇浠诲姟鎵�鏈変俊鎭�")] diff --git a/src/Bro.Device.SeerAGV/SeerAGVDriver.cs b/src/Bro.Device.SeerAGV/SeerAGVDriver.cs index bb05aee..7726e0e 100644 --- a/src/Bro.Device.SeerAGV/SeerAGVDriver.cs +++ b/src/Bro.Device.SeerAGV/SeerAGVDriver.cs @@ -102,7 +102,7 @@ _taskDoneHandle.Set(); _monitorLock.Set(); - + if (client_Guide != null && client_Guide.Connected) { CancelTask(); @@ -440,6 +440,11 @@ } } } + + public virtual void ResetAlarm() + { + IConfig.WarningSetCollection.ForEach(u => u.CurrentStatus = !u.TriggerValue); + } #endregion } } -- Gitblit v1.8.0