领胜LDS 键盘AOI检测项目
xcd
2020-07-06 a6f2ba736d1ac63d8fe33c71dfc3a578b1702b95
src/Bro.Process/ProcessControl.cs
@@ -342,6 +342,31 @@
            }
        }
        public void CreateNewConfig(IProcessConfig config, string newProductionCode)
        {
            try
            {
                if (config == null)
                    throw new ProcessException("保存的配置信息不能为空");
                ProductionCode = newProductionCode;
                //生成config.json
                string newConfig = JsonConvert.SerializeObject(config, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
                using (StreamWriter writer = new StreamWriter(_configPath, false, System.Text.Encoding.UTF8))
                {
                    writer.Write(newConfig);
                    writer.Flush();
                    writer.Close();
                }
                //添加到Setting.json
                SettingHelper.AddNewProductionCode(ProductionCode);
            }
            catch (Exception ex)
            {
                throw new ProcessException(ex.Message, null);
            }
        }
        private void SaveBackupConfig()
        {
            string backPath = Path.GetDirectoryName(_configPath);
@@ -495,6 +520,9 @@
                return;
            }
            if (!ProcessInvokePreCheck())
                return;
            IOperationConfig config = monitorSet.OpConfig;
            object res = null;
            int reTryTimes = config.ReTryTimes;
@@ -553,6 +581,8 @@
                        }
                        LogAsync(DateTime.Now, methodCode + "异常信息", ex.GetExceptionMessage());
                        ExceptionRaisedInMonitor(ex);
                    }
                }
@@ -576,12 +606,29 @@
            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 = "")
        {
            ImageSet set = null;
            IImageSet set = null;
            if (IConfig.IsImageOffline)
            {
@@ -628,7 +675,7 @@
                TimeRecordCSV(DateTime.Now, camera.Name, methodCode + "采图", (int)sw.ElapsedMilliseconds);
            }
            imgSetId = set.Id;
            imgSetId = set?.Id;
            return set.HImage;
        }
@@ -673,6 +720,11 @@
            OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null);
        }
        public virtual void RaisedAlarm(string alarmMsg)
        {
            OnAlarmUpdate?.Invoke(alarmMsg);
        }
        #endregion
        #region ILogger