领胜LDS 键盘AOI检测项目
patrick.xu
2020-12-16 5241a8f6377dfd1618610dd15fd05ed6f51c8ba2
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;
@@ -348,10 +347,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 +364,7 @@
                }
                //添加到Setting.json
                SettingHelper.AddNewProductionCode(ProductionCode);
                SettingHelper.AddNewProductionCode(newProductionCode);
            }
            catch (Exception ex)
            {
@@ -527,7 +532,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 +608,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>