From e69865a1a3739740201bac8782b721da35d49923 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期一, 25 一月 2021 18:45:28 +0800
Subject: [PATCH] 1. gocator添加重试和清理缓存操作 2. gts板卡调整监听频率 3. 记录产品数据使用filsstream避免程序崩溃影响

---
 src/Bro.M071.Process/M071Process.cs |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 4a24029..7165338 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -19,6 +19,7 @@
 using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -193,9 +194,11 @@
         }
         #endregion
 
+        object productionLock = new object();
         List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
 
         [ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
+        [MethodImpl(MethodImplOptions.Synchronized)]
         public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
             if (!IsAllowedWork)
@@ -204,12 +207,12 @@
             }
 
             string hint = "";
-            if (MachineState != MachineState.Ready)
-            {
-                hint = "鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�";
-                OnCheckHintUpload?.Invoke(hint, true);
-                throw new ProcessException(hint, null, ExceptionLevel.Warning);
-            }
+            //if (MachineState != MachineState.Ready)
+            //{
+            //    hint = "鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�";
+            //    OnCheckHintUpload?.Invoke(hint, true);
+            //    throw new ProcessException(hint, null, ExceptionLevel.Warning);
+            //}
 
             if (string.IsNullOrWhiteSpace(BarCode))
             {
@@ -247,15 +250,18 @@
 
             BarCode = "";
 
-            var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
-            if (existedProduction != null)
+            lock (productionLock)
             {
-                productionList.Remove(existedProduction);
-                existedProduction.Dispose();
-                existedProduction = null;
-            }
+                var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
+                if (existedProduction != null)
+                {
+                    productionList.Remove(existedProduction);
+                    existedProduction.Dispose();
+                    existedProduction = null;
+                }
 
-            productionList.Add(pMeasure);
+                productionList.Add(pMeasure);
+            }
 
             pMeasure.InitialMeasurementsPropertyChanged();
             pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
@@ -444,9 +450,13 @@
         {
             if (sender is ProductionMeasurement pMeasure)
             {
-                var production = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
-                if (production == null)
-                    return;
+                ProductionMeasurement production = null;
+                lock (productionLock)
+                {
+                    production = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
+                    if (production == null)
+                        return;
+                }
 
                 lock (production)
                 {
@@ -585,7 +595,10 @@
 
                 SaveWholeImage(pMeasure);
 
-                productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
+                lock (productionLock)
+                {
+                    productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
+                }
                 pMeasure.Dispose();
                 //LogAsync(DateTime.Now, $"{pMeasure.Barcode}浜у搧淇℃伅閲婃斁瀹屾垚", JsonConvert.SerializeObject(pMeasure));
             }
@@ -1195,6 +1208,13 @@
                 var keys = Config.KeyUnitCollection.Where(u => u.IsEnabled && u.SnapshotPointId == snapshotId);
                 var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList();
 
+                if (imgSet.HImage == null)
+                {
+                    LogAsync(DateTime.Now, $"{snapshotName}鏈幏鍙栨壂鎻忓浘鍍�", "");
+                    keyBindCollection.ForEach(k => k.FillKeyValues(null));
+                    return;
+                }
+
                 string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath;
 
                 HObject images = new HObject();

--
Gitblit v1.8.0