From 78289c64a16dd02cc9fec595bf758a9e30a30926 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期六, 20 二月 2021 10:51:11 +0800
Subject: [PATCH] gocator修改异步模式下图片获取操作
---
src/Bro.M071.Process/M071Process.cs | 58 +++++++++++++++++++++++------
src/Bro.Device.Gocator/GocatorDriver.cs | 25 ++++++++----
src/Bro.M071.Process/M071Process_MotionCard.cs | 2 +
src/Bro.M071.Process/M071Process_MES.cs | 2
4 files changed, 65 insertions(+), 22 deletions(-)
diff --git a/src/Bro.Device.Gocator/GocatorDriver.cs b/src/Bro.Device.Gocator/GocatorDriver.cs
index 52c32df..99263dc 100644
--- a/src/Bro.Device.Gocator/GocatorDriver.cs
+++ b/src/Bro.Device.Gocator/GocatorDriver.cs
@@ -269,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
@@ -342,12 +349,12 @@
Thread.Sleep(100);
}
} while (true);
-
- sensor.Flush();
LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ叧闂垚鍔�", "");
}
}
+ sensor.Flush();
+
if (dataSet != null)
{
HandleGoData(dataSet, imgSet);
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 7666577..f7b3f92 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -199,9 +199,9 @@
List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
bool _isdoing = false;
+ object _doingLock = new object();
[ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
- [MethodImpl(MethodImplOptions.Synchronized)]
public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
{
if (!IsAllowedWork)
@@ -226,7 +226,16 @@
throw new ProcessException(hint);
}
- _isdoing = true;
+ lock (_doingLock)
+ {
+ if (_isdoing)
+ {
+ LogAsync(DateTime.Now, "璁惧姝e湪杩愯涓�", "");
+ return new ProcessResponse(true);
+ }
+
+ _isdoing = true;
+ }
MachineState = MachineState.Running;
@@ -272,7 +281,9 @@
pMeasure.InitialMeasurementsPropertyChanged();
pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
- Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
+ try
+ {
+ Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
{
_pausedHandle.Wait();
@@ -321,26 +332,42 @@
RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
});
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
+ _isdoing = false;
- LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
- _isdoing = false;
-
- GC.Collect(0, GCCollectionMode.Optimized);
+ GC.Collect(0, GCCollectionMode.Optimized);
+ }
return new ProcessResponse(true);
}
#region 鍙屾墜鍚姩
+ object _leftStartLock = new object();
+ object _rightStartLock = new object();
+
bool isLeftStart = false;
bool IsLeftStart
{
get => isLeftStart;
set
{
- if (IsLeftStart != value)
+ if (isLeftStart != value)
{
- isLeftStart = value;
- StartCheck();
+ lock (_leftStartLock)
+ {
+ if (IsLeftStart != value)
+ {
+ isLeftStart = value;
+ StartCheck();
+ }
+ }
}
}
}
@@ -353,14 +380,21 @@
{
if (isRightStart != value)
{
- isRightStart = value;
- StartCheck();
+ lock (_rightStartLock)
+ {
+ if (isRightStart != value)
+ {
+ isRightStart = value;
+ StartCheck();
+ }
+ }
}
}
}
private void StartCheck()
{
+
if (isRightStart && isLeftStart)
{
if (_isdoing)
diff --git a/src/Bro.M071.Process/M071Process_MES.cs b/src/Bro.M071.Process/M071Process_MES.cs
index e1c5f74..43ff973 100644
--- a/src/Bro.M071.Process/M071Process_MES.cs
+++ b/src/Bro.M071.Process/M071Process_MES.cs
@@ -207,7 +207,7 @@
if (Config.IsEnableMESLog)
{
- LogAsync(DateTime.Now, $"{barcode}浜у搧妫�娴嬫暟鎹笂浼�", JsonConvert.SerializeObject(paras));
+ LogAsync(DateTime.Now, $"{pMeasure.Barcode}浜у搧妫�娴嬫暟鎹笂浼�", JsonConvert.SerializeObject(paras));
}
var result = DataUploadMethod?.Invoke(DataUploadObj, paras).ToString();
diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
index c49221c..baf87f7 100644
--- a/src/Bro.M071.Process/M071Process_MotionCard.cs
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -250,6 +250,8 @@
(invokeDevice as MotionCardBase).ResetAlarm();
_isdoing = false;
+ _pausedHandle.Set();
+
RaisedAlarm("");
OnCheckHintUpload?.Invoke("", false);
--
Gitblit v1.8.0