From b5e7fa2db4ac36fdb7bf9fd330d12a72ade9d483 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期日, 24 一月 2021 15:07:26 +0800
Subject: [PATCH] 0124
---
src/Bro.Device.GTSCard/GTSCardDriver.cs | 31 ++++---
src/Bro.M071.Process/M071Process.cs | 52 ++++++++----
src/Bro.Device.Gocator/GocatorDriver.cs | 82 +++++++++++++++++--
src/Bro.M071.Process/M071Process_MotionCard.cs | 26 +++--
src/Bro.M071.Process/M071Models.cs | 2
5 files changed, 140 insertions(+), 53 deletions(-)
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index 303ddb4..25ec672 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -400,24 +400,28 @@
/// <returns></returns>
private bool SetAxisParam(MovingOption optionPara)
{
- List<short> resultCode = new List<short>() { 0 };
+ List<short> resultCode = new List<short>();
GTSCardAPI.TTrapPrm trapprm = new GTSCardAPI.TTrapPrm();
short axisIndex = short.Parse(optionPara.AxisIndexStr);
resultCode.Add(GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, axisIndex));
- resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, axisIndex, out trapprm));
- trapprm.smoothTime = 1;
- if (optionPara.VelocityPara.Acc != 0)
+ if (optionPara.VelocityPara.Acc != 0 || optionPara.VelocityPara.Dec != 0)
{
- trapprm.acc = optionPara.VelocityPara.Acc;
- }
+ resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, axisIndex, out trapprm));
+ trapprm.smoothTime = 1;
- if (optionPara.VelocityPara.Dec != 0)
- {
- trapprm.dec = optionPara.VelocityPara.Dec;
- }
+ if (optionPara.VelocityPara.Acc != 0)
+ {
+ trapprm.acc = optionPara.VelocityPara.Acc;
+ }
- resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, axisIndex, ref trapprm));
+ if (optionPara.VelocityPara.Dec != 0)
+ {
+ trapprm.dec = optionPara.VelocityPara.Dec;
+ }
+
+ resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, axisIndex, ref trapprm));
+ }
if (optionPara.VelocityPara.Velocity != 0)
{
@@ -427,9 +431,10 @@
var resultOK = resultCode.All(u => u == (short)GTSRetCode.GRCRunOK);
if (!resultOK)
{
- throw new ProcessException("杞�" + optionPara.AxisIndex + "璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛�" + string.Join(",", resultCode));
+ //throw new ProcessException("杞�" + optionPara.AxisIndex + "璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛�" + string.Join(",", resultCode));
+ LogAsync(DateTime.Now, $"杞磠optionPara.AxisIndex}璁剧疆鍙傛暟寮傚父锛岄敊璇爜锛歿string.Join(",", resultCode)}", "");
}
- return resultOK;
+ return true;
}
TaskFactory taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
diff --git a/src/Bro.Device.Gocator/GocatorDriver.cs b/src/Bro.Device.Gocator/GocatorDriver.cs
index ba3546f..fb7e04f 100644
--- a/src/Bro.Device.Gocator/GocatorDriver.cs
+++ b/src/Bro.Device.Gocator/GocatorDriver.cs
@@ -139,10 +139,12 @@
//imgSet.HImage.GenImage1("int4", (int)width, zoomHeight, zoomPtr);
imgSet.HImage.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr);
- imgSet.HImage_2 = imgSet.HImage.Clone();
+ //imgSet.HImage_2 = imgSet.HImage.Clone();
//imgSet.HImage_2.GenImage1("uint2", (int)width, zoomHeight, zoomPtr);
//imgSet.HImage_2.GenImage1("int4", (int)width, zoomHeight, zoomPtr);
- //imgSet.HImage_2.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr);
+
+ imgSet.HImage_2 = new HImage();
+ imgSet.HImage_2.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr);
LaserScanParam para = new LaserScanParam()
{
@@ -223,7 +225,32 @@
{
if (opConfig.IsOpenConnection)
{
- system.Start();
+ while (sensor.State != GoState.Ready)
+ {
+ Thread.Sleep(10);
+ }
+
+ do
+ {
+ try
+ {
+ system.Start();
+ if (sensor.State != GoState.Running)
+ {
+ Thread.Sleep(100);
+ }
+ else
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogAsync(DateTime.Now, $"寮�鍚紓甯革細{ex.GetExceptionMessage()}", "");
+ }
+ } while (true);
+
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ惎鍔ㄦ垚鍔�", "");
}
if (!opConfig.IsSnapshotAction)
@@ -264,7 +291,9 @@
catch (Exception ex)
{
LogAsync(DateTime.Now, $"{Name}鑾峰彇鍥惧儚寮傚父", ex.GetExceptionMessage());
- return null;
+ imgSet.HImage = null;
+ dataSet = null;
+ //return imgSet;
}
}
@@ -272,18 +301,47 @@
{
if (!opConfig.IsOpenConnection)
{
- system.Stop();
+ while (sensor.State == GoState.Busy)
+ {
+ Thread.Sleep(100);
+ }
+
+ do
+ {
+ try
+ {
+ system.Stop();
+
+ if (sensor.State != GoState.Ready)
+ {
+ Thread.Sleep(100);
+ }
+ else
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogAsync(DateTime.Now, $"鍏抽棴寮傚父锛歿ex.GetExceptionMessage()}", "");
+ }
+ } while (true);
+
sensor.Flush();
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ叧闂垚鍔�", "");
}
}
- HandleGoData(dataSet, imgSet);
-
- dataSet.Dispose();
-
- if (imgSet.HImage == null)
+ if (dataSet != null)
{
- LogAsync(DateTime.Now, $"{Name}鏈兘鑾峰彇HImage鍥惧儚", "");
+ HandleGoData(dataSet, imgSet);
+
+ dataSet.Dispose();
+
+ if (imgSet.HImage == null)
+ {
+ LogAsync(DateTime.Now, $"{Name}鏈兘鑾峰彇HImage鍥惧儚", "");
+ }
}
return imgSet;
@@ -384,6 +442,8 @@
{
base.Start();
+ //system.Start();
+
if (IIConfig.IsAsyncMode)
system.Start();
}
diff --git a/src/Bro.M071.Process/M071Models.cs b/src/Bro.M071.Process/M071Models.cs
index 69113c0..790745a 100644
--- a/src/Bro.M071.Process/M071Models.cs
+++ b/src/Bro.M071.Process/M071Models.cs
@@ -280,7 +280,7 @@
Measurements?.ForEach(m => m?.Dispose());
Measurements = null;
ElementList = null;
- Barcode = null;
+ //Barcode = null;
GC.Collect();
}
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 4a24029..f4108cd 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -193,6 +193,7 @@
}
#endregion
+ object productionLock = new object();
List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
[ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
@@ -204,12 +205,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 +248,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 +448,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 +593,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 +1206,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();
diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
index 5423b8f..8806106 100644
--- a/src/Bro.M071.Process/M071Process_MotionCard.cs
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -29,6 +29,7 @@
if (machineState == value)
return;
+ LogAsync(DateTime.Now, $"璁惧鐘舵�佸垏鎹�:{machineState.ToString()}->{value.ToString()}", "");
machineState = value;
Task.Run(() =>
@@ -249,15 +250,15 @@
RaisedAlarm("");
- if (MachineState != MachineState.Pause)
- {
- MachineState = MachineState.Ready;
- }
- else
- {
- LogAsync(DateTime.Now, "璁惧鏆傚仠涓紝鏃犳硶澶嶄綅", "");
- return new ProcessResponse(true);
- }
+ //if (MachineState != MachineState.Pause)
+ //{
+ MachineState = MachineState.Ready;
+ //}
+ //else
+ //{
+ // LogAsync(DateTime.Now, "璁惧鏆傚仠涓紝鏃犳硶澶嶄綅", "");
+ // return new ProcessResponse(true);
+ //}
if (IsEmergencyStopped)
{
@@ -301,8 +302,11 @@
MachineState = MachineState.Resetting;
MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
- productionList.ForEach(u => u.Dispose());
- productionList.Clear();
+ lock (productionLock)
+ {
+ productionList.ForEach(u => u.Dispose());
+ productionList.Clear();
+ }
OnFullResetDone?.Invoke();
--
Gitblit v1.8.0