| | |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | | using Bro.M071.DBManager; |
| | | //using Bro.M071.DBManager; |
| | | using Bro.M071.Model; |
| | | using Bro.M071.Model.Model; |
| | | using Bro.M071.Process.UI; |
| | |
| | | |
| | | return new ProcessResponse(); |
| | | } |
| | | |
| | | [ProcessMethod("Demostration", "CheckBasePlan", "基准平面检校", InvokeType.TestInvoke)] |
| | | public ProcessResponse CheckBasePlan(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (opConfig is DemostrationOperationConfig config) |
| | | { |
| | | config.DemoOperations.ForEach(d => |
| | | { |
| | | IDevice device = DeviceCollection.FirstOrDefault(u => u.Id == d.MotionOp.Device); |
| | | if (device != null) |
| | | { |
| | | IMotionCard motionDevice = device as IMotionCard; |
| | | |
| | | if (motionDevice != null) |
| | | { |
| | | var response = motionDevice.Run(d.MotionOp.OpConfig); |
| | | if (!response.Result) |
| | | { |
| | | throw new ProcessException($"{device.Name}异常,{response.Message}", null, ExceptionLevel.Fatal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | CameraBase camera = DeviceCollection.FirstOrDefault(u => u.Id == d.CameraOp.Device) as CameraBase; |
| | | if (camera != null) |
| | | { |
| | | IImageSet set = null; |
| | | try |
| | | { |
| | | set = CollectHImage(camera, d.CameraOp.OpConfig); |
| | | } |
| | | catch (ProcessException pEx) |
| | | { |
| | | pEx.Level = ExceptionLevel.Fatal; |
| | | throw pEx; |
| | | } |
| | | |
| | | if (set != null) |
| | | { |
| | | LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(set.ImageData); |
| | | LogAsync(DateTime.Now, $"扫描参数:{set.ImageData}", ""); |
| | | |
| | | var tool = GetHalconTool(d.CameraOp.OpConfig, config.MonitorSetId); |
| | | if (tool != null) |
| | | { |
| | | using (tool.InputImageDic["INPUT_Image"] = set.HImage) |
| | | { |
| | | tool.InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0; |
| | | |
| | | if (!tool.RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{tool.ProcedureName}执行异常", error); |
| | | } |
| | | else |
| | | { |
| | | var diffX = tool.GetResultTuple("OUTPUT_Result_X").D; |
| | | var diffY = tool.GetResultTuple("OUTPUT_Result_Y").D; |
| | | LogAsync(DateTime.Now, $"检测平面,X方向极差:{diffX.ToString(_precision)},Y方向极差:{diffY.ToString(_precision)}", ""); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return new ProcessResponse(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 私有方法 |
| | |
| | | } |
| | | } |
| | | |
| | | KeyUnitDataManager keyUnitDataManager = new KeyUnitDataManager(); |
| | | MeasurementUnitResultManager measurementUnitResultManager = new MeasurementUnitResultManager(); |
| | | MeasurementAndKeyDataRelationManager measurementAndKeyDataRelationManager = new MeasurementAndKeyDataRelationManager(); |
| | | ProductionMeasurementRecordsManager productionMeasurementRecordsManager = new ProductionMeasurementRecordsManager(); |
| | | //KeyUnitDataManager keyUnitDataManager = new KeyUnitDataManager(); |
| | | //MeasurementUnitResultManager measurementUnitResultManager = new MeasurementUnitResultManager(); |
| | | //MeasurementAndKeyDataRelationManager measurementAndKeyDataRelationManager = new MeasurementAndKeyDataRelationManager(); |
| | | //ProductionMeasurementRecordsManager productionMeasurementRecordsManager = new ProductionMeasurementRecordsManager(); |
| | | |
| | | static object dataSaveLock = new object(); |
| | | |
| | | private async void SaveProductionData(ProductionMeasurementUnitResultAndKeyUnitDataSet measurementUnitResultAndKeyUnitDataSet) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | try |
| | | { |
| | | lock (dataSaveLock) |
| | | { |
| | | // 获取 产品数据 并保存 |
| | | var productionMeasurementRecords = measurementUnitResultAndKeyUnitDataSet.ProductionMeasurementRecord; |
| | | productionMeasurementRecordsManager.CreateModel(productionMeasurementRecords); |
| | | //private async void SaveProductionData(ProductionMeasurementUnitResultAndKeyUnitDataSet measurementUnitResultAndKeyUnitDataSet) |
| | | //{ |
| | | // await Task.Run(() => |
| | | // { |
| | | // try |
| | | // { |
| | | // lock (dataSaveLock) |
| | | // { |
| | | // // 获取 产品数据 并保存 |
| | | // var productionMeasurementRecords = measurementUnitResultAndKeyUnitDataSet.ProductionMeasurementRecord; |
| | | // productionMeasurementRecordsManager.CreateModel(productionMeasurementRecords); |
| | | |
| | | // 获取 原始数据 并保存 |
| | | var keyUnitDatas = measurementUnitResultAndKeyUnitDataSet.KeyUnitDataList; |
| | | keyUnitDataManager.BatchAddKeyUnitData(keyUnitDatas); |
| | | // // 获取 原始数据 并保存 |
| | | // var keyUnitDatas = measurementUnitResultAndKeyUnitDataSet.KeyUnitDataList; |
| | | // keyUnitDataManager.BatchAddKeyUnitData(keyUnitDatas); |
| | | |
| | | // 获取 检测结果数据 并保存 |
| | | var measurementUnitResults = measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList; |
| | | measurementUnitResultManager.BatchAddMeasurementUnitResult(measurementUnitResults); |
| | | // // 获取 检测结果数据 并保存 |
| | | // var measurementUnitResults = measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList; |
| | | // measurementUnitResultManager.BatchAddMeasurementUnitResult(measurementUnitResults); |
| | | |
| | | // 获取 关系数据并保存 |
| | | var measurementAndKeyDataRelationList = measurementUnitResultAndKeyUnitDataSet.MeasurementAndKeyDataRelationList; |
| | | measurementAndKeyDataRelationManager.BatchAddMeasurementAndKeyDataRelation(measurementAndKeyDataRelationList); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, "数据保存异常", ex.GetExceptionMessage()); |
| | | } |
| | | }); |
| | | } |
| | | // // 获取 关系数据并保存 |
| | | // var measurementAndKeyDataRelationList = measurementUnitResultAndKeyUnitDataSet.MeasurementAndKeyDataRelationList; |
| | | // measurementAndKeyDataRelationManager.BatchAddMeasurementAndKeyDataRelation(measurementAndKeyDataRelationList); |
| | | // } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // LogAsync(DateTime.Now, "数据保存异常", ex.GetExceptionMessage()); |
| | | // } |
| | | // }); |
| | | //} |
| | | |
| | | private ProductionMeasurementUnitResultAndKeyUnitDataSet GetMeasurementUnitResultAndKeyUnitData(ProductionMeasurement pData) |
| | | { |
| | |
| | | return measurementUnitResultAndKeyUnitDataSet; |
| | | } |
| | | |
| | | private async void ExportProductionExcel(ProductionMeasurementUnitResultAndKeyUnitDataSet measurementUnitResultAndKeyUnitDataSet) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | | return; |
| | | //private async void ExportProductionExcel(ProductionMeasurementUnitResultAndKeyUnitDataSet measurementUnitResultAndKeyUnitDataSet) |
| | | //{ |
| | | // if (!Config.IsCSVOutputEnabled) |
| | | // return; |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | ExcelExportSet excelExportDto = new ExcelExportSet(); |
| | | excelExportDto.Worksheets = new List<string>() { "原始数据", "检测结果" }; |
| | | var keyUnitColumns = new Dictionary<string, string>() |
| | | { |
| | | {"ProductionBarcode", "产品条码"}, |
| | | {"Key", "键"}, |
| | | {"MeasurementItem", "检测项"}, |
| | | {"ItemValue", "检测值"} |
| | | }; |
| | | var measurementUnitResultColumns = new Dictionary<string, string>() |
| | | { |
| | | {"ProductionBarcode", "产品条码"}, |
| | | {"MeasurementName", "检测名称"}, |
| | | {"MeasurementType", "检测类型"}, |
| | | {"MeasurementValue", "检测值"}, |
| | | {"MeasurementResult", "检测结果"}, |
| | | }; |
| | | excelExportDto.WorksheetColumns[excelExportDto.Worksheets[0]] = keyUnitColumns; |
| | | excelExportDto.WorksheetColumns[excelExportDto.Worksheets[1]] = measurementUnitResultColumns; |
| | | // await Task.Run(() => |
| | | // { |
| | | // ExcelExportSet excelExportDto = new ExcelExportSet(); |
| | | // excelExportDto.Worksheets = new List<string>() { "原始数据", "检测结果" }; |
| | | // var keyUnitColumns = new Dictionary<string, string>() |
| | | // { |
| | | // {"ProductionBarcode", "产品条码"}, |
| | | // {"Key", "键"}, |
| | | // {"MeasurementItem", "检测项"}, |
| | | // {"ItemValue", "检测值"} |
| | | // }; |
| | | // var measurementUnitResultColumns = new Dictionary<string, string>() |
| | | // { |
| | | // {"ProductionBarcode", "产品条码"}, |
| | | // {"MeasurementName", "检测名称"}, |
| | | // {"MeasurementType", "检测类型"}, |
| | | // {"MeasurementValue", "检测值"}, |
| | | // {"MeasurementResult", "检测结果"}, |
| | | // }; |
| | | // excelExportDto.WorksheetColumns[excelExportDto.Worksheets[0]] = keyUnitColumns; |
| | | // excelExportDto.WorksheetColumns[excelExportDto.Worksheets[1]] = measurementUnitResultColumns; |
| | | |
| | | excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[0]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.KeyUnitDataList, keyUnitColumns); |
| | | excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[1]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList, measurementUnitResultColumns); ; |
| | | // excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[0]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.KeyUnitDataList, keyUnitColumns); |
| | | // excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[1]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList, measurementUnitResultColumns); ; |
| | | |
| | | if (!Directory.Exists(Config.LogPath)) |
| | | { |
| | | Directory.CreateDirectory(Config.LogPath); |
| | | } |
| | | var fileName = Path.Combine(Config.LogPath, $"ProductionData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"); |
| | | // if (!Directory.Exists(Config.LogPath)) |
| | | // { |
| | | // Directory.CreateDirectory(Config.LogPath); |
| | | // } |
| | | // var fileName = Path.Combine(Config.LogPath, $"ProductionData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"); |
| | | |
| | | byte[] filecontent = ExcelExportHelper.CreateOrAppendExcel(excelExportDto, fileName); |
| | | FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); |
| | | fs.Write(filecontent, 0, filecontent.Length); |
| | | fs.Flush(); |
| | | fs.Close(); |
| | | }); |
| | | } |
| | | // byte[] filecontent = ExcelExportHelper.CreateOrAppendExcel(excelExportDto, fileName); |
| | | // FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); |
| | | // fs.Write(filecontent, 0, filecontent.Length); |
| | | // fs.Flush(); |
| | | // fs.Close(); |
| | | // }); |
| | | //} |
| | | |
| | | static object excelExportLock = new object(); |
| | | private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData) |
| | |
| | | #endregion |
| | | |
| | | #region Slant |
| | | var slantMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType == "Slant").ToList(); |
| | | var slantMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType.StartsWith("Slant")).ToList(); |
| | | if (slantMeasures.Count > 0) |
| | | { |
| | | int slantStartCol = slantSheet.Dimension.Columns; |
| | |
| | | |
| | | #region Alignment |
| | | { |
| | | var alignmentMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType == "Alignment").ToList(); |
| | | var alignmentMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType.StartsWith("Alignment")).ToList(); |
| | | if (alignmentMeasures.Count > 0) |
| | | { |
| | | List<string> keysList = new List<string>(); |
| | |
| | | |
| | | #region RowAlignment |
| | | { |
| | | var rowAlignmentMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType == "RowAlignment").ToList(); |
| | | var rowAlignmentMeasures = exportData.MeasurementUnitResultList.Where(u => u.MeasurementType.StartsWith("RowAlignment")).ToList(); |
| | | if (rowAlignmentMeasures.Count > 0) |
| | | { |
| | | List<string> keysList = new List<string>(); |