From 3f6e94d7de9694378114773ab48d8a61bcc3a01e Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期一, 01 二月 2021 09:22:20 +0800 Subject: [PATCH] 1. 报警生成前后端异步调用 2. 安全光栅方法单线程调用 3. 复位完成时修改界面显示 4. 机台状态拆分执行状态 --- src/Bro.Process/ProcessControl.cs | 35 +++++++++++++++++++++++++---------- 1 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs index ca587d2..7e900ab 100644 --- a/src/Bro.Process/ProcessControl.cs +++ b/src/Bro.Process/ProcessControl.cs @@ -21,7 +21,7 @@ using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; -namespace Bro.Process +namespace Bro.Process { [Process("", DeviceAttributeType.Device)] public partial class ProcessControl : IProcess @@ -45,7 +45,6 @@ #region Event public event Action<string, Bitmap, string> OnBitmapOutput; - //public event Action<string, object> OnObjectOutput; public Action<DateTime, Exception> OnExceptionOccured { get; set; } public event Action<DeviceState> OnProcessStateChanged; public event Action<DateTime, string, string> OnLog; @@ -209,10 +208,17 @@ d.OnLog -= OnDeviceLog; d.OnLog += OnDeviceLog; + d.OnExceptionOccured = OnDeviceExceptionRaised; + d.StateChange(DeviceState.DSInit); d.StateChange(DeviceState.DSOpen); } }); + } + + private void OnDeviceExceptionRaised(DateTime dt, Exception ex) + { + LogAsync(dt, "璁惧寮傚父", ex.GetExceptionMessage()); } #endregion @@ -348,10 +354,16 @@ { if (config == null) throw new ProcessException("淇濆瓨鐨勯厤缃俊鎭笉鑳戒负绌�"); - ProductionCode = newProductionCode; + + string newConfigPath = Path.Combine(Path.GetDirectoryName(_configPath), $"Config_{newProductionCode}.json"); + if (File.Exists(newConfigPath)) + { + throw new ProcessException($"{newProductionCode}閰嶇疆鏂囦欢宸茬粡瀛樺湪"); + } + //鐢熸垚config.json string newConfig = JsonConvert.SerializeObject(config, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); - using (StreamWriter writer = new StreamWriter(_configPath, false, System.Text.Encoding.UTF8)) + using (StreamWriter writer = new StreamWriter(newConfigPath, false, System.Text.Encoding.UTF8)) { writer.Write(newConfig); writer.Flush(); @@ -359,7 +371,7 @@ } //娣诲姞鍒癝etting.json - SettingHelper.AddNewProductionCode(ProductionCode); + SettingHelper.AddNewProductionCode(newProductionCode); } catch (Exception ex) { @@ -465,14 +477,14 @@ /// <param name="config">鎿嶄綔閰嶇疆锛岀敤鏉ョ‘璁ょ洃鍚潵婧愬拰绠楁硶璺緞</param> /// <param name="algorithemPath">绠楁硶璺緞锛岄粯璁ゆ槸閰嶇疆涓殑绗竴涓畻娉曡矾寰�</param> /// <returns>Halcon绠楁硶</returns> - protected HDevEngineTool GetHalconTool(IOperationConfig config, string algorithemPath = "") + protected HDevEngineTool GetHalconTool(IOperationConfig config, string monitorSetId = "", string algorithemPath = "") { if (string.IsNullOrWhiteSpace(algorithemPath)) { algorithemPath = (config as IHalconToolPath)?.GetHalconToolPathList()[0]; } - string key = config.MonitorSetId + "|" + algorithemPath; + string key = (string.IsNullOrWhiteSpace(monitorSetId) ? config.MonitorSetId : monitorSetId) + "|" + algorithemPath; if (_halconToolDict.ContainsKey(key)) { return _halconToolDict[key]; @@ -626,7 +638,7 @@ #endregion #region 鍥惧儚澶勭悊 - protected IImageSet CollectHImage(CameraBase camera, IOperationConfig opConfig, [CallerMemberName]string methodCode = "") + protected IImageSet CollectHImage(CameraBase camera, IOperationConfig opConfig, [CallerMemberName] string methodCode = "") { IImageSet set = null; @@ -720,9 +732,12 @@ OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null); } - public virtual void RaisedAlarm(string alarmMsg) + public async virtual void RaisedAlarm(string alarmMsg) { - OnAlarmUpdate?.Invoke(alarmMsg); + await Task.Run(() => + { + OnAlarmUpdate?.Invoke(alarmMsg); + }); } #endregion -- Gitblit v1.8.0