领胜LDS 键盘AOI检测项目
patrick.xu
2021-03-06 8a3ab64a65da226636743be07c4bee63f50da25d
1. 解决软件异常崩溃问题
12个文件已修改
591 ■■■■■ 已修改文件
src/Bro.Common.Device/DeviceBase/CameraBase.cs 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Common.Device/DeviceBase/HDevEngineTool.cs 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.Gocator/GocatorConfig.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.Gocator/GocatorDriver.cs 256 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.Gocator/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/M071Config.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/M071Process.cs 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/UI/M071_MainForm.Designer.cs 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/UI/M071_MainForm.cs 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Model.Winform/Properties/AssemblyInfo.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.UI.Model.Winform/UI/CanvasImage.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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()
        //{
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;
        }
    }
}
src/Bro.Device.Gocator/GocatorConfig.cs
@@ -50,6 +50,7 @@
        [Category("数据位配置")]
        [Description("图像数据位数,2位/4位")]
        [Browsable(false)]
        public GocatorDataByteNums ByteNums { get; set; } = GocatorDataByteNums.Byte2;
    }
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();
        }
    }
}
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")]
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("运动机构配置")]
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;
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")]
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;
    }
}
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)
                {
                }
            });
        }
    }
}
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")]
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()