领胜LDS 键盘AOI检测项目
patrick.xu
2021-02-20 78289c64a16dd02cc9fec595bf758a9e30a30926
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);
@@ -265,16 +269,23 @@
            GoDataSet dataSet = null;
            if (IIConfig.IsAsyncMode)
            {
                if (!IIConfig.IsHardwareTrigger)
                if (opConfig.IsSnapshotAction)
                {
                    _snapFlag = true;
                    if (!_snapHandle.WaitOne(IIConfig.SnapshotTimeout))
                    if (!IIConfig.IsHardwareTrigger)
                    {
                        LogAsync(DateTime.Now, $"{Name}获取图像超时", "");
                        return null;
                    }
                        _snapFlag = true;
                        if (!_snapHandle.WaitOne(IIConfig.SnapshotTimeout))
                        {
                            LogAsync(DateTime.Now, $"{Name}获取图像超时", "");
                            return null;
                        }
                    dataSet = _currentData;
                        dataSet = _currentData;
                    }
                }
                else
                {
                    imgSet = null;
                }
            }
            else
@@ -284,17 +295,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 +331,9 @@
                    {
                        try
                        {
                            system.Stop();
                            sensor.Stop();
                            LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", "");
                            if (sensor.State != GoState.Ready)
                            {
                                Thread.Sleep(100);
@@ -324,13 +346,14 @@
                        catch (Exception ex)
                        {
                            LogAsync(DateTime.Now, $"关闭异常:{ex.GetExceptionMessage()}", "");
                            Thread.Sleep(100);
                        }
                    } while (true);
                    sensor.Flush();
                    LogAsync(DateTime.Now, $"传感器关闭成功", "");
                }
            }
            sensor.Flush();
            if (dataSet != null)
            {
@@ -442,10 +465,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()