| | |
| | | using Bro.M071.Model.Model; |
| | | using Bro.Process; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | if (camera == null) |
| | | return; |
| | | |
| | | string imgSetId = ""; |
| | | HImage hImage = null; |
| | | IImageSet set = null; |
| | | try |
| | | { |
| | | hImage = CollectHImage(camera, s.CameraOp.OpConfig, out imgSetId); |
| | | set = CollectHImage(camera, s.CameraOp.OpConfig); |
| | | } |
| | | catch (ProcessException pEx) |
| | | { |
| | |
| | | throw pEx; |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(imgSetId)) |
| | | if (set == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | RunImageHandle(camera, s.CameraOp.OpConfig, hImage, s.Id, s.Name, pMeasure.Measurements); |
| | | RunImageHandle(camera, s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements); |
| | | }); |
| | | |
| | | BarCode = ""; |
| | |
| | | |
| | | IShapeElement indicator = null; |
| | | pMeasure.ElementList.Add(indicator); |
| | | //输出图形基元到界面 todo |
| | | //输出图形基元到界面 |
| | | OnElementUpdated?.BeginInvoke(indicator, null, null); |
| | | |
| | | SaveKeyImages(pMeasure.Barcode, m); |
| | |
| | | var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure); |
| | | |
| | | //MES输出 todo |
| | | if (Config.IsEnableMESUpload) |
| | | { |
| | | } |
| | | |
| | | //Excel报表输出 (单个产品的excel导出) |
| | | ExportProductionExcel(measurementUnitResultAndKeyUnitDataSet); |
| | |
| | | measurementUnitResult.ProductionMeasurementRecordsId = productionMeasurementRecords.ID; |
| | | measurementUnitResult.MeasurementName = MeasurementUnitResult.Name; |
| | | measurementUnitResult.MeasurementType = MeasurementUnitResult.MeasureType; |
| | | measurementUnitResult.MeasurementValue = ""; |
| | | measurementUnitResult.MeasurementValue = MeasurementUnitResult.Spec.ActualValue.ToString(); |
| | | measurementUnitResult.MeasurementResult = MeasurementUnitResult.Spec.MeasureResult.Value ? "OK" : "NG"; |
| | | |
| | | measurementUnitResults.Add(measurementUnitResult); |
| | |
| | | { |
| | | foreach (var keyValue in keyUnit.MeasureValueDict)//获取单个键的单个测量item 结果 |
| | | { |
| | | KeyUnitData keyUnitData = new KeyUnitData(); |
| | | keyUnitData.Key = keyUnit.Key; |
| | | keyUnitData.MeasurementItem = keyValue.Key; |
| | | keyUnitData.ItemValue = keyValue.Value.ToString(); |
| | | keyUnitDatas.Add(keyUnitData); |
| | | bool isExist = keyUnitDatas.Any(u => u.Key == keyUnit.Key && u.MeasurementItem == keyValue.Key); |
| | | if (!isExist)//已存在 不重复添加原始数据 |
| | | { |
| | | KeyUnitData keyUnitData = new KeyUnitData(); |
| | | keyUnitData.Key = keyUnit.Key; |
| | | keyUnitData.MeasurementItem = keyValue.Key; |
| | | keyUnitData.ItemValue = keyValue.Value.ToString(); |
| | | keyUnitDatas.Add(keyUnitData); |
| | | |
| | | MeasurementAndKeyDataRelation measurementAndKeyDataRelation = new MeasurementAndKeyDataRelation(); |
| | | measurementAndKeyDataRelation.MeasurementUnitResultId = measurementUnitResult.ID; |
| | | measurementAndKeyDataRelation.KeyUnitDataId = keyUnitData.ID; |
| | | measurementAndKeyDataRelationList.Add(measurementAndKeyDataRelation); |
| | | |
| | | MeasurementAndKeyDataRelation measurementAndKeyDataRelation = new MeasurementAndKeyDataRelation(); |
| | | measurementAndKeyDataRelation.MeasurementUnitResultId = measurementUnitResult.ID; |
| | | measurementAndKeyDataRelation.KeyUnitDataId = keyUnitData.ID; |
| | | measurementAndKeyDataRelationList.Add(measurementAndKeyDataRelation); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | private async void ExportProductionExcel(ProductionMeasurementUnitResultAndKeyUnitDataSet measurementUnitResultAndKeyUnitDataSet) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | | return; |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | ExcelExportSet excelExportDto = new ExcelExportSet(); |
| | |
| | | excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[1]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList, measurementUnitResultColumns); ; |
| | | |
| | | byte[] filecontent = ExcelExportHelper.ExportExcel(excelExportDto, false); |
| | | string dir = Path.Combine(Config.ImageSaveFolder, DateTime.Now.ToString("yyyyMMdd")); |
| | | string dir = Path.Combine(Config.LogPath, DateTime.Now.ToString("yyyyMMdd")); |
| | | if (!Directory.Exists(dir)) |
| | | { |
| | | Directory.CreateDirectory(dir); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | |
| | | var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList(); |
| | | |
| | | string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath; |
| | | HObject images = hImage; |
| | | HObject images = imgSet.HImage; |
| | | LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(imgSet.ImageData); |
| | | |
| | | if (!string.IsNullOrWhiteSpace(toolKey)) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = hImage; |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法异常,{error}", ""); |
| | |
| | | else |
| | | { |
| | | _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z; |
| | | if (!_halconToolDict[keyToolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | |
| | | image.Dispose(); |
| | | }); |
| | | |
| | | if (count.I != 1) |
| | | { |
| | | hImage?.Dispose(); |
| | | hImage = null; |
| | | } |
| | | //if (count.I != 1) |
| | | //{ |
| | | // hImage?.Dispose(); |
| | | // hImage = null; |
| | | //} |
| | | }); |
| | | } |
| | | #endregion |