| | |
| | | using Bro.Process; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | |
| | | Reset(null, null, null); |
| | | FullReset(null); |
| | | |
| | | } |
| | | |
| | | private void InitialMotionCardBaseAxisAlarm() |
| | |
| | | private void InitialSetting() |
| | | { |
| | | //数据库迁移检查 |
| | | DatabaseInitialize.Initialize(); |
| | | //DatabaseInitialize.Initialize(); |
| | | |
| | | MotionCardSettingCheck(); |
| | | |
| | |
| | | } |
| | | |
| | | MachineState = MachineState.Running; |
| | | OnMeasureStart?.BeginInvoke(null, null); |
| | | OnMeasureStart?.Invoke(); |
| | | |
| | | var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone(); |
| | | measurements.ForEach(m => |
| | |
| | | |
| | | Config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s => |
| | | { |
| | | _pauseHandle.WaitHandle.WaitOne(); |
| | | _pausedHandle.Wait(); |
| | | |
| | | if (MachineState != MachineState.Running) |
| | | if (MachineState == MachineState.Ready) |
| | | return; |
| | | |
| | | if (MachineState != MachineState.Running && MachineState != MachineState.Pause) |
| | | { |
| | | throw new ProcessException("机台状态不在运行中,退出检测"); |
| | | } |
| | |
| | | { |
| | | if (sender is ProductionMeasurement pMeasure) |
| | | { |
| | | lock (pMeasure) |
| | | var production = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode); |
| | | if (production == null) |
| | | return; |
| | | |
| | | lock (production) |
| | | { |
| | | //检查是否全部完成 |
| | | pMeasure.Measurements.ForEach(m => |
| | | pMeasure.Measurements?.ForEach(m => |
| | | { |
| | | if (m.KeyUnitCollection.All(k => k.IsDone != null)) |
| | | { |
| | |
| | | indicator.ResultState = m.Spec.MeasureResult; |
| | | pMeasure.ElementList.Add(indicator); |
| | | //输出图形基元到界面 |
| | | OnElementUpdated?.BeginInvoke(indicator, null, null); |
| | | OnElementUpdated?.Invoke(indicator); |
| | | |
| | | SaveKeyImages(pMeasure.Barcode, m); |
| | | |
| | |
| | | { |
| | | } |
| | | |
| | | ////Excel报表输出 (单个产品的excel导出) |
| | | //ExportProductionExcel(measurementUnitResultAndKeyUnitDataSet); |
| | | //Excel报表输出 (单个产品的excel导出) |
| | | ExportProductionExcel(measurementUnitResultAndKeyUnitDataSet); |
| | | |
| | | ExportProductionInColumns(measurementUnitResultAndKeyUnitDataSet); |
| | | ////数据库保存 |
| | | //SaveProductionData(measurementUnitResultAndKeyUnitDataSet); |
| | | |
| | |
| | | MeasurementUnitResult measurementUnitResult = new MeasurementUnitResult(); |
| | | measurementUnitResult.ProductionMeasurementRecordsId = productionMeasurementRecords.ID; |
| | | measurementUnitResult.ProductionBarcode = productionMeasurementRecords.ProductionBarcode; |
| | | measurementUnitResult.MeasurementName = measurementUnit.Name; |
| | | measurementUnitResult.MeasurementName = measurementUnit.GetDisplayText(); |
| | | measurementUnitResult.MeasurementType = measurementUnit.MeasureType; |
| | | measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue.ToString(); |
| | | measurementUnitResult.MeasurementResult = measurementUnit.Spec.MeasureResult.Value ? "OK" : "NG"; |
| | |
| | | fs.Write(filecontent, 0, filecontent.Length); |
| | | fs.Flush(); |
| | | fs.Close(); |
| | | }); |
| | | } |
| | | |
| | | static object excelExportLock = new object(); |
| | | private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | | return; |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | if (!Directory.Exists(Config.LogPath)) |
| | | { |
| | | Directory.CreateDirectory(Config.LogPath); |
| | | } |
| | | var fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"); |
| | | bool isExisted = File.Exists(fileName); |
| | | using (ExcelPackage package = new ExcelPackage(new FileInfo(fileName))) |
| | | { |
| | | ExcelWorksheet rawDataSheet = null; |
| | | ExcelWorksheet slantSheet = null; |
| | | ExcelWorksheet alignmentSheet = null; |
| | | ExcelWorksheet rowAlignmentSheet = null; |
| | | if (!isExisted) |
| | | { |
| | | package.Workbook.Worksheets.Add("RawData"); |
| | | rawDataSheet = package.Workbook.Worksheets["RawData"]; |
| | | for (int i = 0; i < Config.KeyNameCollection.Count; i++) |
| | | { |
| | | var cell = rawDataSheet.Cells[i + 3, 1]; |
| | | cell.Value = Config.KeyNameCollection[i]; |
| | | cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(31, 73, 125)); |
| | | } |
| | | |
| | | //package.Workbook.Worksheets.Add("Slant"); |
| | | //slantSheet = package.Workbook.Worksheets["Slant"]; |
| | | //for(int i=0;i<exportData.MeasurementUnitResultList) |
| | | //package.Workbook.Worksheets.Add("Alignment"); |
| | | //package.Workbook.Worksheets.Add("RowAlignment"); |
| | | } |
| | | |
| | | rawDataSheet = package.Workbook.Worksheets["RawData"]; |
| | | |
| | | int rowDataStartCol = rawDataSheet.Dimension.Columns; |
| | | var barcodeCell = rawDataSheet.Cells[1, rowDataStartCol + 1, 1, rowDataStartCol + 1 + 4]; |
| | | barcodeCell.Merge = true; |
| | | barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode; |
| | | |
| | | var z1Cell = rawDataSheet.Cells[2, rowDataStartCol + 1]; |
| | | z1Cell.Value = "Z1"; |
| | | |
| | | var z2Cell = rawDataSheet.Cells[2, rowDataStartCol + 2]; |
| | | z2Cell.Value = "Z2"; |
| | | |
| | | var z3Cell = rawDataSheet.Cells[2, rowDataStartCol + 3]; |
| | | z3Cell.Value = "Z3"; |
| | | |
| | | var z4Cell = rawDataSheet.Cells[2, rowDataStartCol + 4]; |
| | | z4Cell.Value = "Z4"; |
| | | |
| | | exportData.KeyUnitDataList.ForEach(k => |
| | | { |
| | | int keyIndex = Config.KeyNameCollection.IndexOf(k.Key); |
| | | int zIndex = int.Parse(k.MeasurementItem.Substring(1)); |
| | | |
| | | var cell = rawDataSheet.Cells[keyIndex + 1 + 2, rowDataStartCol + zIndex]; |
| | | cell.Value = k.ItemValue; |
| | | }); |
| | | |
| | | package.Save(); |
| | | }; |
| | | }); |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif"); |
| | | imgSet.HImage.WriteImage("tiff", 0, fileName); |
| | | |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | |
| | | }); |
| | | } |
| | | |
| | | string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}"); |
| | | string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{DateTime.Now.ToString("yyyyMMdd")}", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}"); |
| | | if (!Directory.Exists(dir)) |
| | | { |
| | | Directory.CreateDirectory(dir); |
| | | } |
| | | |
| | | Parallel.For(1, count.I + 1, (i) => |
| | | //for (int i = 1; i <= count.I; i++) |
| | | //Parallel.For(1, count.I + 1, (i) => |
| | | for (int i = 1; i <= count.I; i++) |
| | | { |
| | | HOperatorSet.SelectObj(images, out HObject image, i); |
| | | |
| | |
| | | var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").HTupleToDouble(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测结果异常", ""); |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据异常", ""); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | |
| | | |
| | | //image.Dispose(); |
| | | } |
| | | ); |
| | | //); |
| | | |
| | | //if (count.I != 1) |
| | | //{ |