From e54c5a471c372e314f89c340644ddda98ab063bb Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期三, 19 八月 2020 11:04:22 +0800 Subject: [PATCH] 1. 优化gts板卡回原点操作 2. 添加数据精度配置 3. 添加HalconTool异常捕捉分类和部分非空判断 --- src/Bro.Process/ProcessControl.cs | 71 ++++++++++++++++++++++++++++++++--- 1 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs index 35c3af7..8a4c27f 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 @@ -342,6 +342,37 @@ } } + public void CreateNewConfig(IProcessConfig config, string newProductionCode) + { + try + { + if (config == null) + throw new ProcessException("淇濆瓨鐨勯厤缃俊鎭笉鑳戒负绌�"); + + 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(newConfigPath, false, System.Text.Encoding.UTF8)) + { + writer.Write(newConfig); + writer.Flush(); + writer.Close(); + } + + //娣诲姞鍒癝etting.json + SettingHelper.AddNewProductionCode(newProductionCode); + } + catch (Exception ex) + { + throw new ProcessException(ex.Message, null); + } + } + private void SaveBackupConfig() { string backPath = Path.GetDirectoryName(_configPath); @@ -495,11 +526,14 @@ return; } + if (!ProcessInvokePreCheck()) + return; + IOperationConfig config = monitorSet.OpConfig; object res = null; int reTryTimes = config.ReTryTimes; IDevice device = DeviceCollection.FirstOrDefault(u => u.Id == deviceId); - LogAsync(DateTime.Now, $"{device.Name}璋冪敤{methodCode}寮�濮�", ""); + LogAsync(DateTime.Now, $"{device?.Name}璋冪敤{methodCode}寮�濮�", ""); Stopwatch sw = new Stopwatch(); sw.Start(); @@ -553,6 +587,8 @@ } LogAsync(DateTime.Now, methodCode + "寮傚父淇℃伅", ex.GetExceptionMessage()); + + ExceptionRaisedInMonitor(ex); } } @@ -573,13 +609,30 @@ #endregion sw.Stop(); - LogAsync(DateTime.Now, $"{device.Name}璋冪敤{methodCode}瀹屾垚锛岃�楁椂{sw.ElapsedMilliseconds}ms", ""); - TimeRecordCSV(DateTime.Now, device.Name, $"{methodCode}璋冪敤瀹屾垚", (int)sw.ElapsedMilliseconds); + LogAsync(DateTime.Now, $"{device?.Name}璋冪敤{methodCode}瀹屾垚锛岃�楁椂{sw.ElapsedMilliseconds}ms", ""); + TimeRecordCSV(DateTime.Now, device?.Name, $"{methodCode}璋冪敤瀹屾垚", (int)sw.ElapsedMilliseconds); + } + + /// <summary> + /// 娴佺▼鎵ц鐨勯妫�鏌� + /// </summary> + /// <returns></returns> + public virtual bool ProcessInvokePreCheck() + { + return true; + } + + /// <summary> + /// 鐩戝惉娴佺▼涓紓甯告姏鍑� 鍦ㄥ叿浣撲笟鍔′腑鍏蜂綋澶勭悊 + /// </summary> + /// <param name="ex">鐩戝惉娴佺▼涓紓甯稿璞�</param> + public virtual void ExceptionRaisedInMonitor(Exception ex) + { } #endregion #region 鍥惧儚澶勭悊 - protected HImage CollectHImage(CameraBase camera, IOperationConfig opConfig, out string imgSetId, [CallerMemberName]string methodCode = "") + protected IImageSet CollectHImage(CameraBase camera, IOperationConfig opConfig, [CallerMemberName]string methodCode = "") { IImageSet set = null; @@ -628,8 +681,7 @@ TimeRecordCSV(DateTime.Now, camera.Name, methodCode + "閲囧浘", (int)sw.ElapsedMilliseconds); } - imgSetId = set?.Id; - return set.HImage; + return set; } protected async void CameraUpdateImage(CameraBase camera, Bitmap image, string setId) @@ -673,6 +725,11 @@ OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null); } + + public virtual void RaisedAlarm(string alarmMsg) + { + OnAlarmUpdate?.Invoke(alarmMsg); + } #endregion #region ILogger -- Gitblit v1.8.0