From 8a3ab64a65da226636743be07c4bee63f50da25d Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期六, 06 三月 2021 11:35:20 +0800
Subject: [PATCH] 1. 解决软件异常崩溃问题
---
src/Bro.Device.Gocator/GocatorConfig.cs | 1
src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs | 4
src/Bro.M071.Process/UI/M071_MainForm.cs | 63 ++++++
src/Bro.UI.Model.Winform/UI/CanvasImage.cs | 18 +
src/Bro.M071.Process/M071Process.cs | 143 +++++++++-----
src/Bro.Device.Gocator/GocatorDriver.cs | 256 ++++++++++++++-----------
src/Bro.M071.Process/UI/M071_MainForm.Designer.cs | 14 +
src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs | 56 +++++
src/Bro.M071.Process/M071Config.cs | 8
src/Bro.Common.Device/DeviceBase/CameraBase.cs | 20 +-
src/Bro.Device.Gocator/Properties/AssemblyInfo.cs | 4
src/Bro.M071.Process/Properties/AssemblyInfo.cs | 4
12 files changed, 406 insertions(+), 185 deletions(-)
diff --git a/src/Bro.Common.Device/DeviceBase/CameraBase.cs b/src/Bro.Common.Device/DeviceBase/CameraBase.cs
index ca7afb3..d96dc0d 100644
--- a/src/Bro.Common.Device/DeviceBase/CameraBase.cs
+++ b/src/Bro.Common.Device/DeviceBase/CameraBase.cs
@@ -397,17 +397,17 @@
}
}
- public void ClearImageSet(string imgSetId)
- {
- IImageSet set = _imageSetList[imgSetId];
- if (set != null)
- ClearImageSet(set);
- }
+ //public void ClearImageSet(string imgSetId)
+ //{
+ // IImageSet set = _imageSetList[imgSetId];
+ // if (set != null)
+ // ClearImageSet(set);
+ //}
- private void ImageSet_OnImageSetTimeout(ImageSet set)
- {
- ClearImageSet(set);
- }
+ //private void ImageSet_OnImageSetTimeout(ImageSet set)
+ //{
+ // ClearImageSet(set);
+ //}
//private void ClearImageSetPeriodically()
//{
diff --git a/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs b/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
index ceb3068..7fc9b36 100644
--- a/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
+++ b/src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs
@@ -214,7 +214,7 @@
}
}
- public static Bitmap ConvertHImgaeToBitmap(this HImage hImage)
+ public static Bitmap ConvertHImageToBitmap(this HImage hImage)
{
try
{
@@ -272,5 +272,59 @@
return img;
}
+
+ public static Bitmap ConvertHImageTo16GrayBitmap(this HImage originHImage)
+ {
+ HImage hImage = originHImage.Clone();
+
+ //get_domain(Image, rectangle)
+ //* 鑾峰彇鍏ㄥ浘涓儚绱犵伆搴﹀�肩殑鏈�澶у拰鏈�灏忓��
+ //min_max_gray(rectangle, Image, 0, Min, Max, range)
+ hImage.MinMaxGray(hImage.GetDomain(), 0, out double min, out double max, out double range);
+
+ //* 灏�16浣嶅浘鐨勭伆搴﹀�兼槧灏勫埌0 - 255涓�
+ double mult = 255.0 / (max - min);
+ double add = -mult * min;
+ hImage = hImage.ScaleImage(mult, add);
+
+ //* 杞崲涓�'byte'绫诲瀷
+ //convert_image_type(Image_scaled, ImageConverted, 'byte')
+ hImage = hImage.ConvertImageType("byte");
+
+ Bitmap showImage = hImage.ConvertHImageToBitmap();
+
+ hImage.Dispose();
+
+ return showImage;
+ }
+
+ public static Bitmap ConvertSignedHImageTo16GrayBitmap(this HImage originHImage)
+ {
+ HImage hImage = originHImage.Clone();
+
+ hImage = hImage.ConvertImageType("int4");
+ hImage = hImage.ScaleImage(1.0, 32768);
+ hImage = hImage.ConvertImageType("uint2");
+
+ //get_domain(Image, rectangle)
+ //* 鑾峰彇鍏ㄥ浘涓儚绱犵伆搴﹀�肩殑鏈�澶у拰鏈�灏忓��
+ //min_max_gray(rectangle, Image, 0, Min, Max, range)
+ hImage.MinMaxGray(hImage.GetDomain(), 0, out double min, out double max, out double range);
+
+ //* 灏�16浣嶅浘鐨勭伆搴﹀�兼槧灏勫埌0 - 255涓�
+ double mult = 255.0 / (max - min);
+ double add = -mult * min;
+ hImage = hImage.ScaleImage(mult, add);
+
+ //* 杞崲涓�'byte'绫诲瀷
+ //convert_image_type(Image_scaled, ImageConverted, 'byte')
+ hImage = hImage.ConvertImageType("byte");
+
+ Bitmap showImage = hImage.ConvertHImageToBitmap();
+
+ hImage.Dispose();
+
+ return showImage;
+ }
}
}
diff --git a/src/Bro.Device.Gocator/GocatorConfig.cs b/src/Bro.Device.Gocator/GocatorConfig.cs
index 40ec8ba..27df208 100644
--- a/src/Bro.Device.Gocator/GocatorConfig.cs
+++ b/src/Bro.Device.Gocator/GocatorConfig.cs
@@ -50,6 +50,7 @@
[Category("鏁版嵁浣嶉厤缃�")]
[Description("鍥惧儚鏁版嵁浣嶆暟锛�2浣�/4浣�")]
+ [Browsable(false)]
public GocatorDataByteNums ByteNums { get; set; } = GocatorDataByteNums.Byte2;
}
diff --git a/src/Bro.Device.Gocator/GocatorDriver.cs b/src/Bro.Device.Gocator/GocatorDriver.cs
index 99263dc..ffec5c6 100644
--- a/src/Bro.Device.Gocator/GocatorDriver.cs
+++ b/src/Bro.Device.Gocator/GocatorDriver.cs
@@ -91,13 +91,12 @@
long bufferSize = width * height;
IntPtr bufferPointer = surfaceMsg.Data;
-
float zoomFactor = (float)((double)surfaceMsg.YResolution / (double)surfaceMsg.XResolution);
int zoomHeight = (int)(zoomFactor * height);
- //IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 2);
+ IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 2);
//IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 4);
- IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * (int)IIConfig.ByteNums);
+ //IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * (int)IIConfig.ByteNums);
//娌℃湁鎻掑�硷紝榛樿0
//Parallel.For(0, height, h =>
@@ -105,47 +104,52 @@
// CopyMemory((IntPtr)((long)zoomPtr + width * 2 * Math.Floor(h * zoomFactor)), (IntPtr)((long)bufferPointer + width * 2 * h), width * 2);
// });
- if (IIConfig.ByteNums == GocatorDataByteNums.Byte2)
+ //if (IIConfig.ByteNums == GocatorDataByteNums.Byte2)
+ //{
+ //浣跨敤涓婁竴琛屽師鏈夋暟鎹�
+ Parallel.For(0, zoomHeight, h =>
{
- //浣跨敤涓婁竴琛屽師鏈夋暟鎹�
- Parallel.For(0, zoomHeight, h =>
- {
- int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight);
+ int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight);
+ CopyMemory((IntPtr)((long)zoomPtr + width * 2 * h), (IntPtr)((long)bufferPointer + width * 2 * originHeightIndex), width * 2);
+ });
+ //}
+ //else
+ //{
+ // //浣跨敤涓婁竴琛屽師鏈夋暟鎹�
+ // Parallel.For(0, zoomHeight, h =>
+ // {
+ // int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight);
- CopyMemory((IntPtr)((long)zoomPtr + width * 2 * h), (IntPtr)((long)bufferPointer + width * 2 * originHeightIndex), width * 2);
- });
- }
- else
- {
- //浣跨敤涓婁竴琛屽師鏈夋暟鎹�
- Parallel.For(0, zoomHeight, h =>
- {
- int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight);
+ // byte[] rowBuffer = new byte[width * 4];
+ // Parallel.For(0, width, w =>
+ // {
+ // rowBuffer[w * 4 + 2] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2));
+ // rowBuffer[w * 4 + 3] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2 + 1));
+ // });
- byte[] rowBuffer = new byte[width * 4];
- Parallel.For(0, width, w =>
- {
- rowBuffer[w * 4 + 2] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2));
- rowBuffer[w * 4 + 3] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2 + 1));
- });
-
- Marshal.Copy(rowBuffer, 0, (IntPtr)((long)zoomPtr + width * 2 * h), rowBuffer.Length);
- });
- }
+ // Marshal.Copy(rowBuffer, 0, (IntPtr)((long)zoomPtr + width * 2 * h), rowBuffer.Length);
+ // });
+ //}
if (imgSet != null)
{
imgSet.HImage = new HImage();
//imgSet.HImage.GenImage1("uint2", (int)width, zoomHeight, zoomPtr);
//imgSet.HImage.GenImage1("int4", (int)width, zoomHeight, zoomPtr);
- imgSet.HImage.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "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.GenImage1("int2", (int)width, zoomHeight, zoomPtr);
+
+ //imgSet.HImage = imgSet.HImage.ConvertImageType("int4");
+ //imgSet.HImage = imgSet.HImage.ScaleImage(1.0, short.MaxValue + 1.0);
+ //imgSet.HImage = imgSet.HImage.ConvertImageType("uint2");
+ imgSet.HImage_2 = new HImage();
+ imgSet.HImage_2.GenImage1("int2", (int)width, zoomHeight, zoomPtr);
//imgSet.HImage_2.GenImage1("uint2", (int)width, zoomHeight, zoomPtr);
//imgSet.HImage_2.GenImage1("int4", (int)width, zoomHeight, zoomPtr);
- imgSet.HImage_2 = new HImage();
- 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()
{
@@ -162,6 +166,12 @@
//imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant");
}
+ //var showImage = imgSet.HImage_2.ConvertSignedHImageTo16GrayBitmap();
+ //showImage.Save($@"D:\SI\{DateTime.Now.ToString("yyyyMMddHHmmss")}.tif", System.Drawing.Imaging.ImageFormat.Tiff);
+
+ //SaveOriginImage(null, showImage, imgSet.Id);
+
+ //Marshal.FreeHGlobal(zoomPtr);
Generate16GrayImageByPointer((int)width, zoomHeight, zoomPtr, imgSet?.Id).ContinueWith(t =>
{
Marshal.FreeHGlobal(zoomPtr);
@@ -227,34 +237,7 @@
{
if (opConfig.IsOpenConnection)
{
- while (sensor.State != GoState.Ready)
- {
- Thread.Sleep(10);
- }
-
- do
- {
- try
- {
- sensor.Start();
- LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
- if (sensor.State != GoState.Running)
- {
- Thread.Sleep(100);
- }
- else
- {
- break;
- }
- }
- catch (Exception ex)
- {
- LogAsync(DateTime.Now, $"寮�鍚紓甯革細{ex.GetExceptionMessage()}", "");
- Thread.Sleep(100);
- }
- } while (true);
-
- LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ惎鍔ㄦ垚鍔�", "");
+ StartSensor();
}
if (!opConfig.IsSnapshotAction)
@@ -277,10 +260,12 @@
if (!_snapHandle.WaitOne(IIConfig.SnapshotTimeout))
{
LogAsync(DateTime.Now, $"{Name}鑾峰彇鍥惧儚瓒呮椂", "");
- return null;
+ return imgSet;
}
dataSet = _currentData;
+
+ //dataSet = system.ReceiveData(IIConfig.SnapshotTimeout);
}
}
else
@@ -322,38 +307,9 @@
{
if (!opConfig.IsOpenConnection)
{
- while (sensor.State == GoState.Busy)
- {
- Thread.Sleep(100);
- }
-
- do
- {
- try
- {
- sensor.Stop();
-
- LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
- if (sensor.State != GoState.Ready)
- {
- Thread.Sleep(100);
- }
- else
- {
- break;
- }
- }
- catch (Exception ex)
- {
- LogAsync(DateTime.Now, $"鍏抽棴寮傚父锛歿ex.GetExceptionMessage()}", "");
- Thread.Sleep(100);
- }
- } while (true);
- LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ叧闂垚鍔�", "");
+ StopSensor();
}
}
-
- sensor.Flush();
if (dataSet != null)
{
@@ -367,7 +323,72 @@
}
}
+ sensor.Flush();
return imgSet;
+ }
+
+ private void StopSensor()
+ {
+ while (sensor.State == GoState.Busy)
+ {
+ Thread.Sleep(100);
+ }
+
+ do
+ {
+ try
+ {
+ sensor.Stop();
+
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
+ if (sensor.State != GoState.Ready)
+ {
+ Thread.Sleep(100);
+ }
+ else
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogAsync(DateTime.Now, $"鍏抽棴寮傚父锛歿ex.GetExceptionMessage()}", "");
+ Thread.Sleep(100);
+ }
+ } while (true);
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ叧闂垚鍔�", "");
+ }
+
+ private void StartSensor()
+ {
+ while (sensor.State != GoState.Ready)
+ {
+ Thread.Sleep(10);
+ }
+
+ do
+ {
+ try
+ {
+ sensor.Start();
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄧ姸鎬侊細{sensor.State.ToString()}", "");
+ if (sensor.State != GoState.Running)
+ {
+ Thread.Sleep(100);
+ }
+ else
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogAsync(DateTime.Now, $"寮�鍚紓甯革細{ex.GetExceptionMessage()}", "");
+ Thread.Sleep(100);
+ }
+ } while (true);
+
+ LogAsync(DateTime.Now, $"浼犳劅鍣ㄥ惎鍔ㄦ垚鍔�", "");
}
float _currentExposure = 0;
@@ -433,6 +454,7 @@
system.EnableData(true);
+
if (IIConfig.IsAsyncMode)
{
system.SetDataHandler(onData);
@@ -465,22 +487,26 @@
{
base.Start();
- if (sensor.State != GoState.Ready)
- {
- system.Start();
- }
+ //if (sensor.State != GoState.Ready)
+ //{
+ // system.Start();
+ //}
if (IIConfig.IsAsyncMode)
{
- sensor.Start();
+ //sensor.Start();
+
+ StartSensor();
}
- else
- {
- //if (sensor.State == GoState.Ready)
- {
- sensor.Stop();
- }
- }
+ //else
+ //{
+ // //if (sensor.State == GoState.Ready)
+ // //{
+ // // sensor.Stop();
+ // //}
+
+ // StopSensor();
+ //}
}
protected override void Stop()
@@ -488,7 +514,9 @@
base.Stop();
if (IIConfig.IsAsyncMode)
- system.Stop();
+ {
+ StopSensor();
+ }
if (IIConfig.IsUseAccelerator)
{
@@ -517,7 +545,7 @@
}
volatile bool _snapFlag = false;
- readonly ManualResetEvent _snapHandle = new ManualResetEvent(false);
+ readonly AutoResetEvent _snapHandle = new AutoResetEvent(false);
GoDataSet _currentData = null;
/// <summary>
@@ -526,6 +554,7 @@
/// <param name="data"></param>
private void onData(KObject data)
{
+ LogAsync(DateTime.Now, $"鎵弿鍥惧儚杈撳嚭", "");
GoDataSet dataSet = (GoDataSet)data;
if (IIConfig.IsHardwareTrigger)
@@ -546,11 +575,13 @@
}
else
{
- if (_snapFlag)
+ //if (_snapFlag)
{
_snapFlag = false;
_currentData = dataSet.Clone<GoDataSet>();
+
+ _currentData = dataSet;
_snapHandle.Set();
}
}
@@ -571,8 +602,6 @@
if (set == null)
return;
- set.Image = map;
-
await Task.Run(() =>
{
lock (set.SaveLock)
@@ -586,6 +615,8 @@
//SaveImageByNameAndType(map, set.Id, set.ImageSaveOption.ImageFormat, imgDir);
string filePath = Path.Combine(imgDir, $"{set.Id}.tif");
set.HImage_2.WriteImage("tiff", 0, filePath);
+ set.HImage_2.Dispose();
+ set.HImage_2 = null;
}
catch (Exception ex)
{
@@ -616,11 +647,6 @@
if (set.ImageSaveOption.AddtionalSaveType.Contains(prefix) && !set.IsAddtionalSaved)
{
string imgDir = CheckImageDirectory(set.ImageSaveOption.ImageSaveSubDirectory, prefix);
-
- while (set.Image == null)
- {
- Thread.Sleep(50);
- }
try
{
@@ -657,10 +683,10 @@
public override void Dispose()
{
- base.Dispose();
+ //HImage_2?.Dispose();
+ //HImage_2 = null;
- HImage_2?.Dispose();
- HImage_2 = null;
+ base.Dispose();
}
}
}
diff --git a/src/Bro.Device.Gocator/Properties/AssemblyInfo.cs b/src/Bro.Device.Gocator/Properties/AssemblyInfo.cs
index 3407a97..20ca3eb 100644
--- a/src/Bro.Device.Gocator/Properties/AssemblyInfo.cs
+++ b/src/Bro.Device.Gocator/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//鍙互鎸囧畾鎵�鏈夎繖浜涘�硷紝涔熷彲浠ヤ娇鐢ㄢ�滅敓鎴愬彿鈥濆拰鈥滀慨璁㈠彿鈥濈殑榛樿鍊�
//閫氳繃浣跨敤 "*"锛屽涓嬫墍绀�:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
+[assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyFileVersion("1.0.3.0")]
diff --git a/src/Bro.M071.Process/M071Config.cs b/src/Bro.M071.Process/M071Config.cs
index e9f1b94..d2bcd20 100644
--- a/src/Bro.M071.Process/M071Config.cs
+++ b/src/Bro.M071.Process/M071Config.cs
@@ -201,6 +201,14 @@
}
}
+ [Device("ManualTest", "鎵嬪姩娴嬭瘯鎿嶄綔閰嶇疆", EnumHelper.DeviceAttributeType.OperationConfig)]
+ public class ManualTestOperationConfig : OperationConfigBase
+ {
+ [Category("鎵嬪姩娴嬭瘯閰嶇疆")]
+ [Description("鎵嬪姩娴嬭瘯閲嶅娆℃暟")]
+ public int RepeatTimes { get; set; } = 1;
+ }
+
public class OperationCombination : IComplexDisplay, IHalconToolPath
{
[Category("杩愬姩鏈烘瀯閰嶇疆")]
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 9f967b6..69301a8 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -195,6 +195,37 @@
}
#endregion
+
+ AutoResetEvent _jobDoneHandle = new AutoResetEvent(false);
+ [ProcessMethod("ManualTest", "ManualTest", "鎵嬪姩娴嬭瘯", InvokeType.TestInvoke)]
+ public ProcessResponse ManualTest(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ if (config is ManualTestOperationConfig opConfig)
+ {
+ Task.Run(async () =>
+ {
+ for (int i = 0; i < opConfig.RepeatTimes; i++)
+ {
+ BarCode = $"Test_{i + 1}";
+ StartJob(null, null, null);
+
+ if (_jobDoneHandle.WaitOne(20000))
+ {
+ LogAsync(DateTime.Now, $"绗瑊i + 1}娆′换鍔″畬鎴�", "");
+ await Task.Delay(500);
+ }
+ else
+ {
+ LogAsync(DateTime.Now, $"绗瑊i + 1}娆′换鍔¤秴鏃�", "");
+ break;
+ }
+ }
+ });
+ }
+
+ return new ProcessResponse(true);
+ }
+
object productionLock = new object();
List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
@@ -394,7 +425,6 @@
private void StartCheck()
{
-
if (isRightStart && isLeftStart)
{
if (_isdoing)
@@ -630,6 +660,8 @@
}
}
+ _jobDoneHandle.Set();
+
var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure);
if (pMeasure.PResult != "NA")
@@ -821,6 +853,7 @@
//}
static object excelExportLock = new object();
+ string fileName = "";
private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData)
{
if (!Config.IsCSVOutputEnabled)
@@ -834,7 +867,11 @@
{
Directory.CreateDirectory(Config.LogPath);
}
- var fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx");
+
+ if (string.IsNullOrWhiteSpace(fileName))
+ {
+ fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx");
+ }
try
{
@@ -1139,9 +1176,10 @@
catch (Exception ex)
{
LogAsync(DateTime.Now, "Excel鏃ュ織寮傚父", ex.GetExceptionMessage());
- string bkFileName = Path.Combine(Config.LogPath, $"{Path.GetFileNameWithoutExtension(fileName)}_bk_{DateTime.Now.ToString("HHmmss")}.xlsx");
- File.Copy(fileName, bkFileName);
- File.Delete(fileName);
+ fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx");
+ //string bkFileName = Path.Combine(Config.LogPath, $"{Path.GetFileNameWithoutExtension(fileName)}_bk_{DateTime.Now.ToString("HHmmss")}.xlsx");
+ //File.Copy(fileName, bkFileName);
+ //File.Delete(fileName);
}
}
});
@@ -1263,6 +1301,8 @@
}
#endregion
+ static object _resultCalcLock = new object();
+
private async void RunImageHandle(IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList)
{
await Task.Run(() =>
@@ -1340,71 +1380,74 @@
// Directory.CreateDirectory(dir);
//}
- //Parallel.For(1, count.I + 1, (i) =>
- for (int i = 1; i <= count.I; i++)
+ lock (_resultCalcLock)
{
- HOperatorSet.SelectObj(images, out HObject image, i);
-
- //string fileName = Path.Combine(dir, $"{i}.tif");
- //using (HImage temp = image.ConvertHObjectToHImage())
- //{
- // temp.WriteImage("tiff", 0, fileName);
- //}
-
- keys.Where(u => u.ImageSeq == i).ToList().ForEach(k =>
+ //Parallel.For(1, count.I + 1, (i) =>
+ for (int i = 1; i <= count.I; i++)
{
- Dictionary<string, double> resultDict = null;
+ HOperatorSet.SelectObj(images, out HObject image, i);
- var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList();
+ //string fileName = Path.Combine(dir, $"{i}.tif");
+ //using (HImage temp = image.ConvertHObjectToHImage())
+ //{
+ // temp.WriteImage("tiff", 0, fileName);
+ //}
- string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath;
- if (!_halconToolDict.ContainsKey(keyToolKey))
+ keys.Where(u => u.ImageSeq == i).ToList().ForEach(k =>
{
- LogAsync(DateTime.Now, $"{k.AliasName}妫�娴嬬畻娉曟湭鍒濆鍖�", "");
- }
- else
- {
- _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image;
- _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0;
- _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Y"] = scanParam.Resolution_Y / 1000000.0;
- _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0;
- _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif";
- if (!_halconToolDict[keyToolKey].RunProcedure(out string error))
+ Dictionary<string, double> resultDict = null;
+
+ var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList();
+
+ string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath;
+ if (!_halconToolDict.ContainsKey(keyToolKey))
{
- LogAsync(DateTime.Now, $"{k.AliasName}妫�娴嬬畻娉曞紓甯革紝{error}", "");
+ LogAsync(DateTime.Now, $"{k.AliasName}妫�娴嬬畻娉曟湭鍒濆鍖�", "");
}
else
{
- var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList();
- if (results.Count == 0 || results.Any(u => u < 0))
+ _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image;
+ _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0;
+ _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Y"] = scanParam.Resolution_Y / 1000000.0;
+ _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0;
+ _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif";
+ if (!_halconToolDict[keyToolKey].RunProcedure(out string error))
{
- LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁寮傚父", "");
+ LogAsync(DateTime.Now, $"{k.AliasName}妫�娴嬬畻娉曞紓甯革紝{error}", "");
}
else
{
- //LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁", $"{string.Join(" ", results)}");
-
- results = results.Select(u => u - Config.PlanCompensation).ToList();
- resultDict = k.KeyResultList.ToDictionary(u => u, u =>
+ var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList();
+ if (results.Count == 0 || results.Any(u => u < 0))
{
- int index = k.KeyResultList.IndexOf(u);
- return results[index];
- });
+ LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁寮傚父", "");
+ }
+ else
+ {
+ //LogAsync(DateTime.Now, $"{k.AliasName}鍘熷鏁版嵁", $"{string.Join(" ", results)}");
+
+ results = results.Select(u => u - Config.PlanCompensation).ToList();
+ resultDict = k.KeyResultList.ToDictionary(u => u, u =>
+ {
+ int index = k.KeyResultList.IndexOf(u);
+ return results[index];
+ });
+ }
}
}
- }
- keyBindList.ForEach(kb =>
- {
- kb.KeyImages.Add(image.ConvertHObjectToHImage());
- kb.FillKeyValues(resultDict);
+ keyBindList.ForEach(kb =>
+ {
+ kb.KeyImages.Add(image.ConvertHObjectToHImage());
+ kb.FillKeyValues(resultDict);
+ });
});
- });
- image.Dispose();
- image = null;
+ image.Dispose();
+ image = null;
+ }
+ //);
}
- //);
imgSet.HImage.Dispose();
imgSet.HImage = null;
diff --git a/src/Bro.M071.Process/Properties/AssemblyInfo.cs b/src/Bro.M071.Process/Properties/AssemblyInfo.cs
index 86af5ac..900ca23 100644
--- a/src/Bro.M071.Process/Properties/AssemblyInfo.cs
+++ b/src/Bro.M071.Process/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//鍙互鎸囧畾鎵�鏈夎繖浜涘�硷紝涔熷彲浠ヤ娇鐢ㄢ�滅敓鎴愬彿鈥濆拰鈥滀慨璁㈠彿鈥濈殑榛樿鍊�
//閫氳繃浣跨敤 "*"锛屽涓嬫墍绀�:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.4.1")]
-[assembly: AssemblyFileVersion("1.0.4.1")]
+[assembly: AssemblyVersion("1.0.5.0")]
+[assembly: AssemblyFileVersion("1.0.5.0")]
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
index a98bd9b..ddfc076 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
@@ -53,6 +53,7 @@
this.lblOperator = new System.Windows.Forms.Label();
this.stStripHint = new System.Windows.Forms.StatusStrip();
this.tsslError = new System.Windows.Forms.ToolStripStatusLabel();
+ this.button1 = new System.Windows.Forms.Button();
this.contextMenuStrip1.SuspendLayout();
this.plImage.SuspendLayout();
this.tscEditLocation.ContentPanel.SuspendLayout();
@@ -342,11 +343,23 @@
this.tsslError.Size = new System.Drawing.Size(131, 17);
this.tsslError.Text = "toolStripStatusLabel1";
//
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(591, 13);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 8;
+ this.button1.Text = "button1";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Visible = false;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
// M071_MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1069, 351);
+ this.Controls.Add(this.button1);
this.Controls.Add(this.stStripHint);
this.Controls.Add(this.lblOperator);
this.Controls.Add(this.btnReset);
@@ -403,5 +416,6 @@
private System.Windows.Forms.Label lblOperator;
private System.Windows.Forms.StatusStrip stStripHint;
private System.Windows.Forms.ToolStripStatusLabel tsslError;
+ private System.Windows.Forms.Button button1;
}
}
\ No newline at end of file
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index 1266611..8849ca7 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -24,6 +24,9 @@
M071Config Config => Process?.IConfig as M071Config;
M071Process Process_M071 => Process as M071Process;
+ System.Threading.Timer _refreshUITimer = null;
+
+
public M071_MainForm()
{
InitializeComponent();
@@ -36,6 +39,7 @@
tscEditLocation.Visible = tsmiShowEditor.Checked = false;
+ _refreshUITimer = new System.Threading.Timer(OnRefreshUI, null, -1, -1);
this.Load += async (s, e) =>
{
await Task.Delay(300);
@@ -44,7 +48,7 @@
cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle;
cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle;
- timer1.Enabled = true;
+ //timer1.Enabled = true;
btnReset.Text = $"澶嶄綅锛堥暱鎸墈Config.FullResetRequiredDuration}绉掑ぇ澶嶄綅锛�";
@@ -279,6 +283,12 @@
#endregion
#region 鏍囩缁撴灉鏄剧ず
+
+ private void OnRefreshUI(object state)
+ {
+ cvImage.Invoke(new Action(() => Refresh()));
+ }
+
private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj)
{
//this.Invoke(new Action(() =>
@@ -307,7 +317,8 @@
(ele as KeyIndicator).Text = keyIndicator.Text;
(ele as KeyIndicator).ResultState = keyIndicator.ResultState;
- this.Invalidate();
+ //this.Invalidate();
+ _refreshUITimer.Change(1000, -1);
}));
}
@@ -533,7 +544,7 @@
private void timer1_Tick(object sender, EventArgs e)
{
- cvImage.Refresh();
+ //cvImage.Refresh();
}
private void lblOperator_DoubleClick(object sender, EventArgs e)
@@ -574,5 +585,51 @@
}));
});
}
+
+ bool isStart = true;
+ private void button1_Click(object sender, EventArgs e)
+ {
+ Task.Run(async () =>
+ {
+ try
+ {
+ for (int j = 0; j < 10000; j++)
+ {
+ int i = 0;
+
+ if (isStart)
+ {
+ cvImage.Elements.ToList().ForEach(ele =>
+ {
+ if (ele is KeyIndicator indicator)
+ {
+ indicator.Text = "";
+ indicator.ResultState = null;
+ }
+ });
+ }
+ else
+ {
+ cvImage.Elements.ToList().ForEach(ele =>
+ {
+ if (ele is KeyIndicator indicator)
+ {
+ indicator.Text = (i++).ToString();
+ indicator.ResultState = true;
+ }
+ });
+ }
+ isStart = !isStart;
+ cvImage.BeginInvoke(new Action(() => Refresh()));
+ LogAsync(DateTime.Now, $"UI Refresh {j}", "");
+ await Task.Delay(300);
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+
+ });
+ }
}
}
diff --git a/src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs b/src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs
index 6387310..cb0810f 100644
--- a/src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs
+++ b/src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//鍙互鎸囧畾鎵�鏈夎繖浜涘�硷紝涔熷彲浠ヤ娇鐢ㄢ�滅敓鎴愬彿鈥濆拰鈥滀慨璁㈠彿鈥濈殑榛樿鍊�
//閫氳繃浣跨敤 "*"锛屽涓嬫墍绀�:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.1.0")]
+[assembly: AssemblyFileVersion("1.0.1.0")]
diff --git a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
index 978e513..582061d 100644
--- a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
+++ b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
@@ -67,8 +67,21 @@
#endregion
#region 閲嶇粯
+ volatile bool _isInRepaint = false;
+ object _isInRepaintLock = new object();
protected override void OnPaint(PaintEventArgs e)
{
+ //if (_isInRepaint)
+ // return;
+
+ //lock (_isInRepaintLock)
+ //{
+ // if (_isInRepaint)
+ // return;
+ //}
+
+ //_isInRepaint = true;
+
try
{
Rectangle rect = ClientRectangle;
@@ -78,6 +91,9 @@
Graphics g = myBuffer.Graphics;
g.SmoothingMode = SmoothingMode.HighSpeed;
g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
+ g.InterpolationMode = InterpolationMode.Low;
+ g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
+ g.CompositingQuality = CompositingQuality.HighSpeed;
g.Clear(BackColor);
g.MultiplyTransform(Matrix);
@@ -173,6 +189,8 @@
catch (Exception)
{
}
+
+ _isInRepaint = false;
}
private void halfTransparent()
--
Gitblit v1.8.0