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.Device.Gocator/GocatorDriver.cs |   56 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/src/Bro.Device.Gocator/GocatorDriver.cs b/src/Bro.Device.Gocator/GocatorDriver.cs
index fb7e04f..52c32df 100644
--- a/src/Bro.Device.Gocator/GocatorDriver.cs
+++ b/src/Bro.Device.Gocator/GocatorDriver.cs
@@ -13,6 +13,7 @@
 using System.Drawing;
 using System.IO;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
@@ -218,6 +219,7 @@
             }
         }
 
+        [MethodImpl(MethodImplOptions.Synchronized)]
         public override IImageSet Snapshot(IOperationConfig config)
         {
             GocatorOperationConfig opConfig = config as GocatorOperationConfig;
@@ -234,7 +236,8 @@
                     {
                         try
                         {
-                            system.Start();
+                            sensor.Start();
+                            LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
                             if (sensor.State != GoState.Running)
                             {
                                 Thread.Sleep(100);
@@ -247,6 +250,7 @@
                         catch (Exception ex)
                         {
                             LogAsync(DateTime.Now, $"寮�鍚紓甯革細{ex.GetExceptionMessage()}", "");
+                            Thread.Sleep(100);
                         }
                     } while (true);
 
@@ -284,17 +288,27 @@
                     return null;
                 }
 
-                try
+                int reTryTime = 3;
+                do
                 {
-                    dataSet = system.ReceiveData(IIConfig.SnapshotTimeout);
-                }
-                catch (Exception ex)
-                {
-                    LogAsync(DateTime.Now, $"{Name}鑾峰彇鍥惧儚寮傚父", ex.GetExceptionMessage());
-                    imgSet.HImage = null;
-                    dataSet = null;
-                    //return imgSet;
-                }
+                    try
+                    {
+                        dataSet = system.ReceiveData(IIConfig.SnapshotTimeout);
+                        reTryTime = 0;
+                    }
+                    catch (Exception ex)
+                    {
+                        reTryTime--;
+                        LogAsync(DateTime.Now, $"{Name}鑾峰彇鍥惧儚寮傚父", ex.GetExceptionMessage());
+
+                        if (reTryTime <= 0)
+                        {
+                            imgSet.HImage = null;
+                            dataSet = null;
+                            system.ClearData();
+                        }
+                    }
+                } while (reTryTime > 0);
             }
 
             if (!IIConfig.IsAsyncMode)
@@ -310,8 +324,9 @@
                     {
                         try
                         {
-                            system.Stop();
+                            sensor.Stop();
 
+                            LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
                             if (sensor.State != GoState.Ready)
                             {
                                 Thread.Sleep(100);
@@ -324,6 +339,7 @@
                         catch (Exception ex)
                         {
                             LogAsync(DateTime.Now, $"鍏抽棴寮傚父锛歿ex.GetExceptionMessage()}", "");
+                            Thread.Sleep(100);
                         }
                     } while (true);
 
@@ -442,10 +458,22 @@
         {
             base.Start();
 
-            //system.Start();
+            if (sensor.State != GoState.Ready)
+            {
+                system.Start();
+            }
 
             if (IIConfig.IsAsyncMode)
-                system.Start();
+            {
+                sensor.Start();
+            }
+            else
+            {
+                //if (sensor.State == GoState.Ready)
+                {
+                    sensor.Stop();
+                }
+            }
         }
 
         protected override void Stop()

--
Gitblit v1.8.0