From 1491846b4736bc2e79604086acfd8544aa3ba384 Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期一, 07 九月 2020 12:09:46 +0800
Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071

---
 src/Bro.Device.GTSCard/GTSCardDriver.cs            |  158 +++++++++++-----------
 src/Bro.M071.Process/UI/M071_MainForm.cs           |   12 +
 src/Bro.UI.Model.Winform/UI/CanvasImage.cs         |    3 
 src/Bro.M071.Process/UI/M071_MainForm.Designer.cs  |   27 ++-
 src/Bro.M071.Process/UI/M071_MainForm.resx         |    3 
 src/Bro.Process/ProcessControl.cs                  |   12 +
 src/Bro.Common.Model/Interface/IProcess.cs         |    4 
 src/Bro.Device.HikCamera/HikCameraDriver.cs        |    9 
 src/Bro.Process/Bro.Process.csproj                 |   10 -
 src/Bro.M071.Process/M071Process.cs                |  142 ++++++++++++-------
 src/Bro.Common.Model/Helper/SettingHelper.cs       |    9 +
 src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs |    8 +
 src/Bro.M071.Process/M071Config.cs                 |   10 +
 src/Bro.Common.Model/GlobalVar.cs                  |   10 +
 14 files changed, 254 insertions(+), 163 deletions(-)

diff --git a/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs b/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
index f1f385d..ceb3068 100644
--- a/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
+++ b/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
@@ -136,9 +136,15 @@
             catch (HDevEngineException ex)
             {
                 IsSuccessful = false;
+                errorMsg = $"HDevProgram {ex.ProcedureName} Run fail , Line number: {ex.LineNumber}, Halcon error number : {ex.HalconError},ex:{ex.Message}";
+                return false;
+            }
+            catch (Exception ex)
+            {
+                IsSuccessful = false;
                 //Trace.TraceInformation("HDevProgram {0} Run fail , Line number: {1}, Halcon error number : {2},ex:{3}", ex.ProcedureName, ex.LineNumber, ex.HalconError, ex.Message);
                 //return;
-                errorMsg = $"HDevProgram {ex.ProcedureName} Run fail , Line number: {ex.LineNumber}, Halcon error number : {ex.HalconError},ex:{ex.Message}";
+                errorMsg = $"{ex.Message}";
                 return false;
             }
         }
diff --git a/src/Bro.Common.Model/GlobalVar.cs b/src/Bro.Common.Model/GlobalVar.cs
index cc555e4..d0b5310 100644
--- a/src/Bro.Common.Model/GlobalVar.cs
+++ b/src/Bro.Common.Model/GlobalVar.cs
@@ -6,6 +6,8 @@
     {
         public static ContainerBuilder Builder { get; set; } = new ContainerBuilder();
 
+        private static object containerLock = new object();
+
         private static IContainer container = null;
         public static IContainer Container
         {
@@ -13,7 +15,13 @@
             {
                 if (container == null)
                 {
-                    container = Builder.Build();
+                    lock (containerLock)
+                    {
+                        if (container == null)
+                        {
+                            container = Builder.Build();
+                        }
+                    }
                 }
 
                 return container;
diff --git a/src/Bro.Common.Model/Helper/SettingHelper.cs b/src/Bro.Common.Model/Helper/SettingHelper.cs
index a14100e..99f93c2 100644
--- a/src/Bro.Common.Model/Helper/SettingHelper.cs
+++ b/src/Bro.Common.Model/Helper/SettingHelper.cs
@@ -76,9 +76,15 @@
             return codes;
         }
 
-        public static List<string> AddNewProductionCode(string code)
+        public static void AddNewProductionCode(string code)
         {
             var dataTemp = GetSettingData();
+
+            if (!dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES))
+            {
+                dataTemp.Add(PROPERTY_PRODUCTIONCODES, new JArray());
+            }
+
             if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES))
             {
                 List<string> codes = GetProductionCodes();
@@ -96,7 +102,6 @@
                     writer.Close();
                 }
             }
-            return GetProductionCodes();
         }
 
         public static string GetConfigFilePath()
diff --git a/src/Bro.Common.Model/Interface/IProcess.cs b/src/Bro.Common.Model/Interface/IProcess.cs
index 403375d..3a5669c 100644
--- a/src/Bro.Common.Model/Interface/IProcess.cs
+++ b/src/Bro.Common.Model/Interface/IProcess.cs
@@ -51,7 +51,7 @@
         //event Action<string, Bitmap, string> OnBitmapOutput;
 
         event Action<DeviceState> OnProcessStateChanged;
-        event Action<string> OnAlarmUpdate;        
+        event Action<string> OnAlarmUpdate;
 
         Action<DateTime, int> OnUpdateResult { get; set; }
         Action<float> OnUpdateCT { get; set; }
@@ -59,7 +59,7 @@
 
         #region 鏁版嵁搴撴搷浣�
         void SaveProcessConfig(IProcessConfig config);
-        void CreateNewConfig(IProcessConfig config,string newProductionCode);
+        void CreateNewConfig(IProcessConfig config, string newProductionCode);
         #endregion
     }
 }
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index d87e661..c430886 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -443,7 +443,7 @@
                 {
                     axisImmediatePauseHandleDict[optionPara.AxisIndex].WaitOne();
 
-                    if (!axisPauseResumeFlag[optionPara.AxisIndex])
+                    if (axisPauseResumeFlag.ContainsKey(optionPara.AxisIndex) && !axisPauseResumeFlag[optionPara.AxisIndex])
                         return true;
 
                     try
@@ -492,7 +492,7 @@
                         isSuccessAndStop = false;
                         LogAsync(DateTime.Now, $"杞磠optionPara.AxisIndex}杩愬姩寮傚父", ex.GetExceptionMessage());
                     }
-                } while (axisImmediatePauseFlag[optionPara.AxisIndex]);
+                } while (axisImmediatePauseFlag.ContainsKey(optionPara.AxisIndex) && axisImmediatePauseFlag[optionPara.AxisIndex]);
                 return isSuccessAndStop;
             });
         }
@@ -891,19 +891,12 @@
                 var goHomePara = IConfig.AxisSettings.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex).GoHomePara;
                 bool homeDirection = goHomePara.IsHomeDirPositive;
                 bool isRightLimitReached = false;
-
-            StartCapture:
-
-                PositionReset(movingOption.AxisIndex, 1);
-                ClearStatus(movingOption.AxisIndex, 1);
+                short capture = 0;
 
                 GTSCardAPI.TTrapPrm trapPrm;
-                bool isStop = false;
-                //鎼滅储璺濈 闃舵1
-                // 鍚姩Home鎹曡幏
-                short sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME);
+
                 // 鍒囨崲鍒扮偣浣嶈繍鍔ㄦā寮�
-                sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex);
+                short sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex);
                 // 璇诲彇鐐逛綅妯″紡杩愬姩鍙傛暟
                 sRtn = GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, out trapPrm);
                 trapPrm.acc = movingOption.VelocityPara.Acc;
@@ -913,88 +906,99 @@
                 // 璁剧疆鐐逛綅妯″紡鐩爣閫熷害锛屽嵆鍥炲師鐐归�熷害
                 sRtn = GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)movingOption.AxisIndex, goHomePara.HighVelocity);
 
-                // 璁剧疆鐐逛綅妯″紡鐩爣浣嶇疆锛屽嵆鍘熺偣鎼滅储璺濈
-                sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 99999999 : -99999999);
-                // 鍚姩杩愬姩
-                sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
-
-                int repeatTime = goHomePara.GoHomeTimeOut * 1000;
-                short capture;
-                int pos;
-                uint clk;//鏃堕挓鍙傛暟
                 do
                 {
-                    Thread.Sleep(IConfig.MonitorInterval);
-                    // 璇诲彇鎹曡幏鐘舵��
-                    GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk);
-                    isStop = IsStop((short)movingOption.AxisIndex);
-                    repeatTime -= IConfig.MonitorInterval;
-                } while (!(isStop || capture == 1 || repeatTime <= 0));
+                    PositionReset(movingOption.AxisIndex, 1);
+                    ClearStatus(movingOption.AxisIndex, 1);
 
-                if (repeatTime <= 0)
-                {
-                    MoveStop((short)movingOption.AxisIndex, 0);
-                    throw new ProcessException($"杩愬姩杞磠movingOption.AxisIndex} 锛屽洖鍘熺偣瓒呮椂寮傚父");
-                }
+                    //鎼滅储璺濈 闃舵1
+                    // 鍚姩Home鎹曡幏
+                    sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME);
 
-                if (isStop && capture != 1)
-                {
-                    ClearStatus((short)movingOption.AxisIndex, 1);
+                    // 璁剧疆鐐逛綅妯″紡鐩爣浣嶇疆锛屽嵆鍘熺偣鎼滅储璺濈
+                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 99999999 : -99999999);
+                    // 鍚姩杩愬姩
+                    sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
+
+                    int repeatTime = goHomePara.GoHomeTimeOut * 1000;
+
+                    bool isStop = false;
+                    int pos;
+                    uint clk;//鏃堕挓鍙傛暟
+                    do
+                    {
+                        Thread.Sleep(IConfig.MonitorInterval * 5);
+                        // 璇诲彇鎹曡幏鐘舵��
+                        GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk);
+                        isStop = IsStop((short)movingOption.AxisIndex);
+                        repeatTime -= IConfig.MonitorInterval * 5;
+                    } while (!(isStop || capture == 1 || repeatTime <= 0));
+
+                    if (repeatTime <= 0)
+                    {
+                        MoveStop((short)movingOption.AxisIndex, 0);
+                        throw new ProcessException($"杩愬姩杞磠movingOption.AxisIndex} 锛屽洖鍘熺偣瓒呮椂寮傚父");
+                    }
 
                     var axisStatus = AxisStatusList.FirstOrDefault(u => u.AxisIndex == movingOption.AxisIndex);
 
-                    if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0))
+                    if (isStop && capture != 1)
                     {
-                        //movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1);
-
-                        //姝i檺浣�
-                        if ((axisStatus.AxisStatus & 0x20) != 0 && !goHomePara.IsCaptureDirPositive)
+                        if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0))
                         {
-                            isRightLimitReached = true;
+                            //movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1);
+
+                            //姝i檺浣�
+                            if ((axisStatus.AxisStatus & 0x20) != 0 && !goHomePara.IsCaptureDirPositive)
+                            {
+                                isRightLimitReached = true;
+                            }
+
+                            //璐熼檺浣�
+                            if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive)
+                            {
+                                isRightLimitReached = true;
+                            }
+
+                            homeDirection = !homeDirection;
                         }
 
+                        ClearStatus(movingOption.AxisIndex, 1);
+                    }
 
-                        //璐熼檺浣�
-                        if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive)
+                    if (capture == 1)
+                    {
+                        if (!isRightLimitReached)
                         {
-                            isRightLimitReached = true;
+                            capture = 0;
+                            ClearStatus(movingOption.AxisIndex, 1);
+                            //GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME);
+                            continue;
                         }
 
-                        homeDirection = !homeDirection;
-                        goto StartCapture;
+                        //鍏坰top
+                        MoveStop((short)movingOption.AxisIndex, 0);
+                        ClearStatus((short)movingOption.AxisIndex, 1);
+
+                        //宸茬粡鎹曡幏鍒癏ome鎵嶅彲浠ュ洖闆� 闃舵2
+                        // 杩愬姩鍒�"鎹曡幏浣嶇疆+鍋忕Щ閲�"
+                        sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + goHomePara.HomeOffset);
+                        // 鍦ㄨ繍鍔ㄧ姸鎬佷笅鏇存柊鐩爣浣嶇疆
+                        sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
+                        isStop = false;
+
+                        repeatTime = 1000;
+                        do
+                        {
+                            Thread.Sleep(20);
+                            isStop = IsStop((short)movingOption.AxisIndex);
+                            repeatTime--;
+                        } while (!isStop && repeatTime > 0);
+                        PositionReset(movingOption.AxisIndex, 1);
+                        return (sRtn == (short)GTSRetCode.GRCRunOK) && isStop;
                     }
 
-                    throw new ProcessException($"杩愬姩杞磠movingOption.AxisIndex} 锛屽洖鍘熺偣瓒呮椂寮傚父");
-                }
-
-                if (capture == 1)
-                {
-                    if (!isRightLimitReached)
-                    {
-                        capture = 0;
-                        goto StartCapture;
-                    }
-
-                    //鍏坰top
-                    MoveStop((short)movingOption.AxisIndex, 0);
-                    ClearStatus((short)movingOption.AxisIndex, 1);
-                    //宸茬粡鎹曡幏鍒癏ome鎵嶅彲浠ュ洖闆� 闃舵2
-                    // 杩愬姩鍒�"鎹曡幏浣嶇疆+鍋忕Щ閲�"
-                    sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + goHomePara.HomeOffset);
-                    // 鍦ㄨ繍鍔ㄧ姸鎬佷笅鏇存柊鐩爣浣嶇疆
-                    sRtn = GTSCardAPI.GT_Update((short)IConfig.CardNum, 1 << (movingOption.AxisIndex - 1));
-                    isStop = false;
-
-                    repeatTime = 1000;
-                    do
-                    {
-                        Thread.Sleep(20);
-                        isStop = IsStop((short)movingOption.AxisIndex);
-                        repeatTime--;
-                    } while (!isStop && repeatTime > 0);
-                    PositionReset(movingOption.AxisIndex, 1);
-                    return (sRtn == (short)GTSRetCode.GRCRunOK) && isStop;
-                }
+                } while (!(capture == 1 && isRightLimitReached));
                 return false;
             }
             catch (Exception ex)
diff --git a/src/Bro.Device.HikCamera/HikCameraDriver.cs b/src/Bro.Device.HikCamera/HikCameraDriver.cs
index f308873..b77232f 100644
--- a/src/Bro.Device.HikCamera/HikCameraDriver.cs
+++ b/src/Bro.Device.HikCamera/HikCameraDriver.cs
@@ -463,15 +463,14 @@
         {
             if (nMsgType == MyCamera.MV_EXCEPTION_DEV_DISCONNECT)
             {
-                Thread.Sleep(1000);
-
-                Stop();
-
                 if (CurrentState != EnumHelper.DeviceState.DSClose)
                 {
                     int reTryTimes = 3;
                     do
                     {
+                        Thread.Sleep(1000);
+                        Stop();
+
                         try
                         {
                             Start();
@@ -484,7 +483,7 @@
                             if (reTryTimes > 0)
                             {
                                 //OnLog?.Invoke(DateTime.Now, this, "閲嶆柊杩炴帴鐩告満寮傚父\r\n" + ex.GetExceptionMessage());
-                                LogAsync(DateTime.Now, "閲嶆柊杩炴帴寮傚父", ex.GetExceptionMessage());
+                                LogAsync(DateTime.Now, $"{this.Name}閲嶆柊杩炴帴寮傚父", ex.GetExceptionMessage());
                             }
                             else
                             {
diff --git a/src/Bro.M071.Process/M071Config.cs b/src/Bro.M071.Process/M071Config.cs
index 9edb448..08a33a7 100644
--- a/src/Bro.M071.Process/M071Config.cs
+++ b/src/Bro.M071.Process/M071Config.cs
@@ -75,6 +75,16 @@
         [Editor(typeof(ComplexCollectionEditor<MeasurementUnit>), typeof(UITypeEditor))]
         public List<MeasurementUnit> MeasurementUnitCollection { get; set; } = new List<MeasurementUnit>();
 
+        [Category("妫�娴嬭缃�")]
+        [Description("骞抽潰琛ュ伩鍊�")]
+        [DisplayName("4.骞抽潰琛ュ伩鍊�")]
+        public double PlanCompensation { get; set; }
+
+        [Category("妫�娴嬭缃�")]
+        [Description("鏁版嵁绮惧害璁剧疆")]
+        [DisplayName("5.鏁版嵁绮惧害浣嶆暟")]
+        public int Precision { get; set; } = 3;
+
         //[Category("妫�娴嬭缃�")]
         //[DisplayName("缁撴灉鏁版嵁淇濆瓨璺緞")]
         //[Description("妫�娴嬬粨鏋滄暟鎹繚瀛樿矾寰�")]
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 325cccc..a3a23dc 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -48,6 +48,9 @@
         public event Action OnFullResetDone;
         #endregion
 
+        string _precision = "f3";
+
+
         public override void Open()
         {
             InitialSetting();
@@ -63,6 +66,11 @@
 
             Reset(null, null, null);
             FullReset(null);
+
+            if (Config.Precision > 0)
+            {
+                _precision = "f" + Config.Precision;
+            }
         }
 
         private void InitialMotionCardBaseAxisAlarm()
@@ -367,25 +375,36 @@
                                     }
                                     else
                                     {
-                                        var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.ToList().ConvertAll(v => v ?? -999)).ToArray();
-                                        _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array);
-                                        if (!_halconToolDict[toolKey].RunProcedure(out string error))
+                                        //var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.ToList().ConvertAll(v => v ?? -999)).ToArray();
+                                        var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.Select(v => v ?? -999)).ToArray();
+
+                                        if (array == null || array.Length == 0)
                                         {
-                                            LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}绠楁硶寮傚父,{error}", "");
+                                            LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}鏈兘鑾峰彇瀵瑰簲妫�娴嬪��", "");
                                             m.Spec.ActualValue = -999;
                                         }
                                         else
                                         {
-                                            m.Spec.ActualValue = double.Parse(_halconToolDict[toolKey].GetResultTuple("OUTPUT_Result").D.ToString("f2"));
-                                            LogAsync(DateTime.Now, $"{m.GetDisplayText()}鏁版嵁{m.Spec.ActualValue}锛岀粨鏋渰(m.Spec.MeasureResult == null ? "TBD" : (m.Spec.MeasureResult == true ? "OK" : "NG"))}", "");
+
+                                            _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array);
+                                            if (!_halconToolDict[toolKey].RunProcedure(out string error))
+                                            {
+                                                LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}绠楁硶寮傚父,{error}", "");
+                                                m.Spec.ActualValue = -999;
+                                            }
+                                            else
+                                            {
+                                                m.Spec.ActualValue = double.Parse(_halconToolDict[toolKey].GetResultTuple("OUTPUT_Result").D.ToString(_precision));
+                                                //LogAsync(DateTime.Now, $"{m.GetDisplayText()}鏁版嵁{m.Spec.ActualValue}锛岀粨鏋渰(m.Spec.MeasureResult == null ? "TBD" : (m.Spec.MeasureResult == true ? "OK" : "NG"))}", "");
+                                            }
                                         }
                                     }
                                 }
 
-                                LogAsync(DateTime.Now, $"{m.GetDisplayText()}妫�娴嬬粨鏋�", $"{((m.Spec.MeasureResult ?? false) ? "OK" : "NG")}");
+                                //LogAsync(DateTime.Now, $"{m.GetDisplayText()}妫�娴嬬粨鏋�", $"{((m.Spec.MeasureResult ?? false) ? "OK" : "NG")}");
 
                                 KeyIndicator indicator = new KeyIndicator(m.Id, m.DisplayLocation);
-                                indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString("f2");
+                                indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString(_precision);
                                 indicator.ResultState = m.Spec.MeasureResult;
                                 pMeasure.ElementList.Add(indicator);
                                 //杈撳嚭鍥惧舰鍩哄厓鍒扮晫闈� 
@@ -517,7 +536,7 @@
                         measurementUnitResult.Keys = measurementUnit.KeyUnitCollection[0].KeyResultId + "~" + measurementUnit.KeyUnitCollection[measurementUnit.KeyUnitCollection.Count() - 1].KeyResultId;
                     }
                     measurementUnitResult.MeasurementType = measurementUnit.MeasureType;
-                    measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue == null ? "NA" : measurementUnit.Spec.ActualValue.Value.ToString("f2");
+                    measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue == null ? "NA" : measurementUnit.Spec.ActualValue.Value.ToString(_precision);
                     measurementUnitResult.MeasurementResult = measurementUnit.Spec.MeasureResult.Value ? "OK" : "NG";
 
                     measurementUnitResults.Add(measurementUnitResult);
@@ -533,7 +552,7 @@
                                 keyUnitData.ProductionBarcode = productionMeasurementRecords.ProductionBarcode;
                                 keyUnitData.Key = keyUnit.Key;
                                 keyUnitData.MeasurementItem = keyValue.Key;
-                                keyUnitData.ItemValue = keyValue.Value == null ? "NA" : keyValue.Value.Value.ToString("f2");
+                                keyUnitData.ItemValue = keyValue.Value == null ? "NA" : keyValue.Value.Value.ToString(_precision);
                                 keyUnitDatas.Add(keyUnitData);
 
                                 MeasurementAndKeyDataRelation measurementAndKeyDataRelation = new MeasurementAndKeyDataRelation();
@@ -758,8 +777,12 @@
                         {
                             int slantStartCol = slantSheet.Dimension.Columns;
 
-                            var barcodeCell = slantSheet.Cells[1, slantStartCol + 1, 1, slantStartCol + 2];
-                            barcodeCell.Merge = true;
+                            //var barcodeCell = slantSheet.Cells[1, slantStartCol + 1, 1, slantStartCol + 2];
+                            //barcodeCell.Merge = true;
+                            //barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
+                            //SetTitleCell(barcodeCell);
+
+                            var barcodeCell = slantSheet.Cells[1, slantStartCol + 1];
                             barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
                             SetTitleCell(barcodeCell);
 
@@ -767,9 +790,9 @@
                             valueCell.Value = "Value";
                             SetTitleCell(valueCell);
 
-                            var resultCell = slantSheet.Cells[2, slantStartCol + 2];
-                            resultCell.Value = "Result";
-                            SetTitleCell(resultCell);
+                            //var resultCell = slantSheet.Cells[2, slantStartCol + 2];
+                            //resultCell.Value = "Result";
+                            //SetTitleCell(resultCell);
 
                             slantMeasures.ForEach(m =>
                             {
@@ -781,15 +804,15 @@
                                 }
 
                                 var cellValue = slantSheet.Cells[rowIndex + 1 + 2, slantStartCol + 1];
-                                var cellResult = slantSheet.Cells[rowIndex + 1 + 2, slantStartCol + 2];
+                                //var cellResult = slantSheet.Cells[rowIndex + 1 + 2, slantStartCol + 2];
 
                                 cellValue.Value = m.MeasurementValue;
-                                cellResult.Value = m.MeasurementResult;
+                                //cellResult.Value = m.MeasurementResult;
 
                                 if (m.MeasurementResult != "OK")
                                 {
                                     SetNGCell(cellValue);
-                                    SetNGCell(cellResult);
+                                    //SetNGCell(cellResult);
                                 }
                             });
                         }
@@ -804,7 +827,7 @@
                                 int allRowNums = alignmentSheet.Dimension.Rows;
                                 int aligneStartCol = alignmentSheet.Dimension.Columns;
 
-                                for (int i = 3; i <= allRowNums; i++)
+                                for (int i = 3; i <= alignmentSheet.Dimension.End.Row; i++)
                                 {
                                     string keys = alignmentSheet.Cells[i, 1].Value.ToString();
                                     string position = alignmentSheet.Cells[i, 2].Value.ToString();
@@ -812,8 +835,12 @@
                                     keysList.Add($"{keys}_{position}");
                                 }
 
-                                var barcodeCell = alignmentSheet.Cells[1, aligneStartCol + 1, 1, aligneStartCol + 2];
-                                barcodeCell.Merge = true;
+                                //var barcodeCell = alignmentSheet.Cells[1, aligneStartCol + 1, 1, aligneStartCol + 2];
+                                //barcodeCell.Merge = true;
+                                //barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
+                                //SetTitleCell(barcodeCell);
+
+                                var barcodeCell = alignmentSheet.Cells[1, aligneStartCol + 1];
                                 barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
                                 SetTitleCell(barcodeCell);
 
@@ -821,9 +848,9 @@
                                 valueCell.Value = "Value";
                                 SetTitleCell(valueCell);
 
-                                var resultCell = alignmentSheet.Cells[2, aligneStartCol + 2];
-                                resultCell.Value = "Result";
-                                SetTitleCell(resultCell);
+                                //var resultCell = alignmentSheet.Cells[2, aligneStartCol + 2];
+                                //resultCell.Value = "Result";
+                                //SetTitleCell(resultCell);
 
                                 alignmentMeasures.ForEach(a =>
                                 {
@@ -835,15 +862,15 @@
                                     }
 
                                     var cellValue = alignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 1];
-                                    var cellResult = alignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 2];
+                                    //var cellResult = alignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 2];
 
                                     cellValue.Value = a.MeasurementValue;
-                                    cellResult.Value = a.MeasurementResult;
+                                    //cellResult.Value = a.MeasurementResult;
 
                                     if (a.MeasurementResult != "OK")
                                     {
                                         SetNGCell(cellValue);
-                                        SetNGCell(cellResult);
+                                        //SetNGCell(cellResult);
                                     }
                                 });
                             }
@@ -867,8 +894,12 @@
                                     keysList.Add($"{keys}_{position}");
                                 }
 
-                                var barcodeCell = rowAlignmentSheet.Cells[1, aligneStartCol + 1, 1, aligneStartCol + 2];
-                                barcodeCell.Merge = true;
+                                //var barcodeCell = rowAlignmentSheet.Cells[1, aligneStartCol + 1, 1, aligneStartCol + 2];
+                                //barcodeCell.Merge = true;
+                                //barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
+                                //SetTitleCell(barcodeCell);
+
+                                var barcodeCell = rowAlignmentSheet.Cells[1, aligneStartCol + 1];
                                 barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
                                 SetTitleCell(barcodeCell);
 
@@ -876,9 +907,9 @@
                                 valueCell.Value = "Value";
                                 SetTitleCell(valueCell);
 
-                                var resultCell = rowAlignmentSheet.Cells[2, aligneStartCol + 2];
-                                resultCell.Value = "Result";
-                                SetTitleCell(resultCell);
+                                //var resultCell = rowAlignmentSheet.Cells[2, aligneStartCol + 2];
+                                //resultCell.Value = "Result";
+                                //SetTitleCell(resultCell);
 
                                 rowAlignmentMeasures.ForEach(a =>
                                 {
@@ -890,15 +921,15 @@
                                     }
 
                                     var cellValue = rowAlignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 1];
-                                    var cellResult = rowAlignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 2];
+                                    //var cellResult = rowAlignmentSheet.Cells[rowIndex + 1 + 2, aligneStartCol + 2];
 
                                     cellValue.Value = a.MeasurementValue;
-                                    cellResult.Value = a.MeasurementResult;
+                                    //cellResult.Value = a.MeasurementResult;
 
                                     if (a.MeasurementResult != "OK")
                                     {
                                         SetNGCell(cellValue);
-                                        SetNGCell(cellResult);
+                                        //SetNGCell(cellResult);
                                     }
                                 });
                             }
@@ -913,10 +944,10 @@
 
         private void SetNGCell(ExcelRange cell)
         {
-            cell.Style.Font.Color.SetColor(Color.White);
+            cell.Style.Font.Color.SetColor(Color.Red);
             cell.Style.Font.Bold = true;
-            cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
-            cell.Style.Fill.BackgroundColor.SetColor(Color.Red);
+            //cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
+            //cell.Style.Fill.BackgroundColor.SetColor(Color.Red);
         }
 
         private void SetTitleCell(ExcelRange cell, bool isCenterAlign = true)
@@ -1035,7 +1066,9 @@
                  var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList();
 
                  string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath;
-                 HObject images = imgSet.HImage;
+                 //HObject images = imgSet.HImage;
+
+                 HObject images = new HObject();
                  LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(imgSet.ImageData);
                  LogAsync(DateTime.Now, $"鎵弿鍙傛暟:{imgSet.ImageData}", "");
 
@@ -1049,8 +1082,8 @@
                          return;
                      }
 
-                     string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif");
-                     imgSet.HImage.WriteImage("tiff", 0, fileName);
+                     //string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif");
+                     //imgSet.HImage.WriteImage("tiff", 0, fileName);
 
                      _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage;
                      if (!_halconToolDict[toolKey].RunProcedure(out string error))
@@ -1083,22 +1116,22 @@
                           });
                  }
 
-                 string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{DateTime.Now.ToString("yyyyMMdd")}", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}");
-                 if (!Directory.Exists(dir))
-                 {
-                     Directory.CreateDirectory(dir);
-                 }
+                 //string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{DateTime.Now.ToString("yyyyMMdd")}", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}");
+                 //if (!Directory.Exists(dir))
+                 //{
+                 //    Directory.CreateDirectory(dir);
+                 //}
 
                  //Parallel.For(1, count.I + 1, (i) =>
                  for (int i = 1; i <= count.I; i++)
                  {
                      HOperatorSet.SelectObj(images, out HObject image, i);
 
-                     string fileName = Path.Combine(dir, $"{i}.tif");
-                     using (HImage temp = image.ConvertHObjectToHImage())
-                     {
-                         temp.WriteImage("tiff", 0, fileName);
-                     }
+                     //string fileName = Path.Combine(dir, $"{i}.tif");
+                     //using (HImage temp = image.ConvertHObjectToHImage())
+                     //{
+                     //    temp.WriteImage("tiff", 0, fileName);
+                     //}
 
                      keys.Where(u => u.ImageSeq == i).ToList().ForEach(k =>
                          {
@@ -1115,6 +1148,7 @@
                              {
                                  _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image;
                                  _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0;
+                                 _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Y"] = scanParam.Resolution_Y / 1000000.0;
                                  _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0;
                                  _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif";
                                  if (!_halconToolDict[keyToolKey].RunProcedure(out string error))
@@ -1130,8 +1164,9 @@
                                      }
                                      else
                                      {
-                                         //results = results.Select(u => double.Parse(u.ToString("f2"))).ToList();
-                                         LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁", $"{string.Join(" ", results)}");
+                                         //LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁", $"{string.Join(" ", results)}");
+
+                                         results = results.Select(u => u - Config.PlanCompensation).ToList();
                                          resultDict = k.KeyResultList.ToDictionary(u => u, u =>
                                               {
                                                   int index = k.KeyResultList.IndexOf(u);
@@ -1152,6 +1187,7 @@
                  }
                  //);
 
+                 images.Dispose();
                  //if (count.I != 1)
                  //{
                  //    hImage?.Dispose();
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
index bbe64d2..a702101 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
@@ -33,6 +33,7 @@
             this.tsmiShowToolBar = new System.Windows.Forms.ToolStripMenuItem();
             this.tsmiShowStatusBar = new System.Windows.Forms.ToolStripMenuItem();
             this.tsmiShowEditor = new System.Windows.Forms.ToolStripMenuItem();
+            this.tsmiRefreshLabels = new System.Windows.Forms.ToolStripMenuItem();
             this.btnReset = new System.Windows.Forms.Button();
             this.btnStartMeasure = new System.Windows.Forms.Button();
             this.lblCT = new System.Windows.Forms.Label();
@@ -48,7 +49,7 @@
             this.lvMeasures = new System.Windows.Forms.ListView();
             this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.propGridKeyIndicator = new System.Windows.Forms.PropertyGrid();
-            this.tsmiRefreshLabels = new System.Windows.Forms.ToolStripMenuItem();
+            this.timer1 = new System.Windows.Forms.Timer(this.components);
             this.contextMenuStrip1.SuspendLayout();
             this.plImage.SuspendLayout();
             this.tscEditLocation.ContentPanel.SuspendLayout();
@@ -68,13 +69,13 @@
             this.tsmiShowEditor,
             this.tsmiRefreshLabels});
             this.contextMenuStrip1.Name = "contextMenuStrip1";
-            this.contextMenuStrip1.Size = new System.Drawing.Size(181, 114);
+            this.contextMenuStrip1.Size = new System.Drawing.Size(149, 92);
             // 
             // tsmiShowToolBar
             // 
             this.tsmiShowToolBar.CheckOnClick = true;
             this.tsmiShowToolBar.Name = "tsmiShowToolBar";
-            this.tsmiShowToolBar.Size = new System.Drawing.Size(180, 22);
+            this.tsmiShowToolBar.Size = new System.Drawing.Size(148, 22);
             this.tsmiShowToolBar.Text = "鏄剧ず宸ュ叿鏉�";
             this.tsmiShowToolBar.CheckedChanged += new System.EventHandler(this.tsmiShowToolBar_CheckedChanged);
             // 
@@ -82,7 +83,7 @@
             // 
             this.tsmiShowStatusBar.CheckOnClick = true;
             this.tsmiShowStatusBar.Name = "tsmiShowStatusBar";
-            this.tsmiShowStatusBar.Size = new System.Drawing.Size(180, 22);
+            this.tsmiShowStatusBar.Size = new System.Drawing.Size(148, 22);
             this.tsmiShowStatusBar.Text = "鏄剧ず鐘舵�佹爮";
             this.tsmiShowStatusBar.CheckedChanged += new System.EventHandler(this.tsmiShowStatusBar_CheckedChanged);
             // 
@@ -90,9 +91,16 @@
             // 
             this.tsmiShowEditor.CheckOnClick = true;
             this.tsmiShowEditor.Name = "tsmiShowEditor";
-            this.tsmiShowEditor.Size = new System.Drawing.Size(180, 22);
+            this.tsmiShowEditor.Size = new System.Drawing.Size(148, 22);
             this.tsmiShowEditor.Text = "缂栬緫鏄剧ず鐐逛綅";
             this.tsmiShowEditor.CheckedChanged += new System.EventHandler(this.tsmiShowEditor_CheckedChanged);
+            // 
+            // tsmiRefreshLabels
+            // 
+            this.tsmiRefreshLabels.Name = "tsmiRefreshLabels";
+            this.tsmiRefreshLabels.Size = new System.Drawing.Size(148, 22);
+            this.tsmiRefreshLabels.Text = "鍒锋柊鏄剧ず鐐逛綅";
+            this.tsmiRefreshLabels.Click += new System.EventHandler(this.tsmiRefreshLabels_Click);
             // 
             // btnReset
             // 
@@ -293,12 +301,10 @@
             this.propGridKeyIndicator.TabIndex = 0;
             this.propGridKeyIndicator.ToolbarVisible = false;
             // 
-            // tsmiRefreshLabels
+            // timer1
             // 
-            this.tsmiRefreshLabels.Name = "tsmiRefreshLabels";
-            this.tsmiRefreshLabels.Size = new System.Drawing.Size(180, 22);
-            this.tsmiRefreshLabels.Text = "鍒锋柊鏄剧ず鐐逛綅";
-            this.tsmiRefreshLabels.Click += new System.EventHandler(this.tsmiRefreshLabels_Click);
+            this.timer1.Interval = 3000;
+            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
             // 
             // M071_MainForm
             // 
@@ -353,5 +359,6 @@
         private System.Windows.Forms.Button btnReset;
         private System.Windows.Forms.ColumnHeader columnHeader1;
         private System.Windows.Forms.ToolStripMenuItem tsmiRefreshLabels;
+        private System.Windows.Forms.Timer timer1;
     }
 }
\ No newline at end of file
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index efadaed..0ed4652 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -40,6 +40,8 @@
                    cvImage.SetScreenSize();
                    cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle;
                    cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle;
+
+                   timer1.Enabled = true;
                };
         }
 
@@ -284,6 +286,10 @@
             {
                 _barcode += keyStr.ToUpper();
             }
+            else if (keyStr.Length == 2 && keyStr.StartsWith("D"))
+            {
+                _barcode += keyStr.Substring(1).ToUpper();
+            }
 
             if (e.KeyValue == 13)
             {
@@ -337,7 +343,7 @@
                             btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
                             btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
                             lblMachineState.Text = "灏辩华";
-                            
+
                             btnStartMeasure.Text = "寮�濮嬫祴閲�";
                             btnStartMeasure.Enabled = true;
                             break;
@@ -475,5 +481,9 @@
         }
         #endregion
 
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            cvImage.Refresh();
+        }
     }
 }
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.resx b/src/Bro.M071.Process/UI/M071_MainForm.resx
index ad53752..2b01b4a 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.resx
+++ b/src/Bro.M071.Process/UI/M071_MainForm.resx
@@ -120,4 +120,7 @@
   <metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>182, 17</value>
+  </metadata>
 </root>
\ No newline at end of file
diff --git a/src/Bro.Process/Bro.Process.csproj b/src/Bro.Process/Bro.Process.csproj
index d7b408b..e56f5e8 100644
--- a/src/Bro.Process/Bro.Process.csproj
+++ b/src/Bro.Process/Bro.Process.csproj
@@ -128,9 +128,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
-    <None Include="Setting.json">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
+    <None Include="Setting.json" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Forms\Calibration\FrmCalibration_9P.resx">
@@ -170,9 +168,5 @@
     <Error Condition="!Exists('..\..\packages\PostSharp.6.2.7\build\PostSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\PostSharp.6.2.7\build\PostSharp.targets'))" />
   </Target>
   <Import Project="..\..\packages\PostSharp.6.2.7\build\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.6.2.7\build\PostSharp.targets')" />
-  <ProjectExtensions>
-    <VisualStudio>
-      <UserProperties setting_1json__JsonSchema="https://batect.dev/configSchema.json" />
-    </VisualStudio>
-  </ProjectExtensions>
+  <ProjectExtensions />
 </Project>
\ No newline at end of file
diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs
index ca587d2..8a4c27f 100644
--- a/src/Bro.Process/ProcessControl.cs
+++ b/src/Bro.Process/ProcessControl.cs
@@ -348,10 +348,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 +365,7 @@
                 }
 
                 //娣诲姞鍒癝etting.json
-                SettingHelper.AddNewProductionCode(ProductionCode);
+                SettingHelper.AddNewProductionCode(newProductionCode);
             }
             catch (Exception ex)
             {
diff --git a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
index 76beeac..978e513 100644
--- a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
+++ b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
@@ -614,6 +614,9 @@
             if (map == null)
                 return;
 
+            MAP?.Dispose();
+            MAP = null;
+
             MAP = map;
             //MAP = map;
 

--
Gitblit v1.8.0