领胜LDS 键盘AOI检测项目
src/Bro.Process/ProcessControl.cs
@@ -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 @@
                }
                //添加到Setting.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];
@@ -527,7 +539,7 @@
            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();
@@ -603,8 +615,8 @@
            #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>
@@ -626,7 +638,7 @@
        #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;
@@ -675,8 +687,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)