| | |
| | | string _precision = "f3"; |
| | | double _allowedShift = 0; |
| | | |
| | | double _allowedShift2 = 0; |
| | | |
| | | public override void Open() |
| | | { |
| | | InitialSetting(); |
| | | |
| | | base.Open(); |
| | | if (!Config.IsOfflineMode) |
| | | { |
| | | base.Open(); |
| | | |
| | | InitialMotionCardBaseAxisAlarm(); |
| | | InitialMotionCardBaseAxisAlarm(); |
| | | |
| | | SwitchBeep(false); |
| | | SwitchLightGreen(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | SwitchBeep(false); |
| | | SwitchLightGreen(false); |
| | | SwitchLightRed(false); |
| | | SwitchLightYellow(false); |
| | | |
| | | Reset(null, null, null); |
| | | FullReset(null); |
| | | Reset(null, null, null); |
| | | FullReset(null); |
| | | } |
| | | |
| | | if (Config.Precision > 0) |
| | | { |
| | | _precision = "f" + Config.Precision; |
| | | } |
| | | |
| | | IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj); |
| | | DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj); |
| | | if (Config.IsEnableMESUpload) |
| | | { |
| | | IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj); |
| | | DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj); |
| | | } |
| | | |
| | | PrepareDataShift(); |
| | | } |
| | | |
| | | private void PrepareDataShift() |
| | | { |
| | | var allowedShiftStr = ConfigurationManager.AppSettings["DataShift"]; |
| | | if (!double.TryParse(allowedShiftStr, out _allowedShift)) |
| | | { |
| | | _allowedShift = 0; |
| | | } |
| | | |
| | | string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dataShift"); |
| | | if (!File.Exists(path)) |
| | | { |
| | | _allowedShift2 = 0; |
| | | } |
| | | else |
| | | { |
| | | using (StreamReader reader = new StreamReader(path, System.Text.Encoding.UTF8)) |
| | | { |
| | | string data = reader.ReadToEnd(); |
| | | |
| | | if (!string.IsNullOrWhiteSpace(data)) |
| | | { |
| | | if (double.TryParse(data, out double dataValue)) |
| | | { |
| | | _allowedShift2 = dataValue; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | _allowedShift += _allowedShift2; |
| | | } |
| | | |
| | | private void InitialMotionCardBaseAxisAlarm() |
| | |
| | | } |
| | | #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>(); |
| | | |
| | |
| | | _isdoing = true; |
| | | } |
| | | |
| | | MachineState = MachineState.Running; |
| | | MeasureState = MachineState = MachineState.Running; |
| | | |
| | | OnCheckHintUpload?.Invoke(hint, true); |
| | | OnMeasureStart?.Invoke(); |
| | |
| | | |
| | | private void StartCheck() |
| | | { |
| | | |
| | | if (isRightStart && isLeftStart) |
| | | { |
| | | if (_isdoing) |
| | |
| | | |
| | | return new ProcessResponse(); |
| | | } |
| | | |
| | | [ProcessMethod("KeyUnitGenerate", "GenerateKeyUnitByKeyNames", "生成单键配置", InvokeType.TestInvoke)] |
| | | public ProcessResponse GenerateKeyUnitByKeyNames(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (opConfig is KeyUnitGenerateConfig config) |
| | | { |
| | | int i = 1; |
| | | bool isStart = false; |
| | | bool isEnd = false; |
| | | foreach (string k in Config.KeyNameCollection) |
| | | { |
| | | if (k == config.StartKey) |
| | | { |
| | | isStart = true; |
| | | } |
| | | else if (k == config.EndKey) |
| | | { |
| | | isEnd = true; |
| | | } |
| | | |
| | | if (isStart) |
| | | { |
| | | KeyUnit unit = new KeyUnit(); |
| | | unit.Key = unit.AliasName = k; |
| | | unit.SnapshotPointId = config.SnapshotPointId; |
| | | unit.KeyAlgorithemId = config.KeyAlgorithemId; |
| | | unit.KeyResultId = config.KeyResultId; |
| | | unit.ImageSeq = i; |
| | | |
| | | Config.KeyUnitCollection.Add(unit); |
| | | i++; |
| | | } |
| | | |
| | | if (isEnd) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return new ProcessResponse(true); |
| | | } |
| | | |
| | | [ProcessMethod("", "SortKeyUnits", "单键配置排序", InvokeType.TestInvoke)] |
| | | public ProcessResponse SortKeyUnits(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (Config.KeyUnitCollection.Count > 0) |
| | | { |
| | | Config.KeyUnitCollection = Config.KeyUnitCollection.OrderBy(u => u.SnapshotPointId).ThenBy(u => u.ImageSeq).ToList(); |
| | | } |
| | | return new ProcessResponse(true); |
| | | } |
| | | #endregion |
| | | |
| | | #region 私有方法 |
| | |
| | | } |
| | | else |
| | | { |
| | | |
| | | _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array); |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | |
| | | double actualValue = double.Parse(_halconToolDict[toolKey].GetResultTuple("OUTPUT_Result").D.ToString(_precision)); |
| | | m.Spec.ActualValue = actualValue; |
| | | |
| | | //M071要求超限数据在允许范围内压缩到合格范围内 |
| | | if (_allowedShift > 0 && m.Spec.MeasureResult != null && m.Spec.MeasureResult.Value == false) |
| | | if (m.MeasureType.ToLower() == "alignment" || m.MeasureType.ToLower() == "slant") |
| | | { |
| | | m.Spec.ActualValue = m.Spec.StandardValue + (actualValue - m.Spec.StandardValue) * (m.Spec.Tolrenance_Positive - m.Spec.StandardValue) / (m.Spec.Tolrenance_Positive - m.Spec.StandardValue + _allowedShift); |
| | | //M071要求超限数据在允许范围内压缩到合格范围内 |
| | | if (_allowedShift > 0 && m.Spec.MeasureResult != null && m.Spec.MeasureResult.Value == false) |
| | | { |
| | | m.Spec.ActualValue = m.Spec.StandardValue + (actualValue - m.Spec.StandardValue) * (m.Spec.Tolrenance_Positive - m.Spec.StandardValue) / (m.Spec.Tolrenance_Positive - m.Spec.StandardValue + _allowedShift); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (m.Spec?.ActualValue != null) |
| | | { |
| | | LogAsync(DateTime.Now, $"{m.Name}检测结果{m.Spec.ActualValue.Value.ToString(_precision)}", ""); |
| | | } |
| | | |
| | | KeyIndicator indicator = new KeyIndicator(m.Id, m.DisplayLocation); |
| | |
| | | //if (MachineState == MachineState.Running) |
| | | // MachineState = MachineState.Ready; |
| | | |
| | | MeasureState = MachineState.Ready; |
| | | if (MachineState != MachineState.Alarm) |
| | | { |
| | | if (MachineState == MachineState.Pause) |
| | |
| | | MachineState = MachineState.Ready; |
| | | } |
| | | } |
| | | |
| | | _jobDoneHandle.Set(); |
| | | |
| | | var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure); |
| | | |
| | |
| | | //} |
| | | |
| | | static object excelExportLock = new object(); |
| | | string fileName = ""; |
| | | private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | |
| | | { |
| | | 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 |
| | | { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | static object _resultCalcLock = new object(); |
| | | |
| | | private async void RunImageHandle(IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | { |
| | | await Task.Run(() => |
| | |
| | | // 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").HTupleToDouble(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | return results[index]; |
| | | }); |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据{string.Join(",", results)}异常", ""); |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | |
| | | results = results.Select(u => u - Config.PlanCompensation).ToList(); |
| | | |
| | | string resultStr = ""; |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | |
| | | if (index < results.Count && index >= 0) |
| | | { |
| | | double origin = results[index]; |
| | | |
| | | var compensation = k.KeyCompensationCollection.FirstOrDefault(c => c.KeyResult == u); |
| | | if (compensation != null) |
| | | { |
| | | origin = origin + compensation.Compensation; |
| | | } |
| | | |
| | | resultStr += $"{u} {origin};"; |
| | | |
| | | return origin; |
| | | } |
| | | else |
| | | { |
| | | return -999.0; |
| | | } |
| | | }); |
| | | |
| | | LogAsync(DateTime.Now, $"{k.AliasName}结果:{resultStr}", ""); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | if (kb.KeyImages != null) |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | } |
| | | else |
| | | { |
| | | |
| | | } |
| | | }); |
| | | }); |
| | | }); |
| | | |
| | | image.Dispose(); |
| | | image = null; |
| | | image.Dispose(); |
| | | image = null; |
| | | } |
| | | //); |
| | | } |
| | | //); |
| | | |
| | | imgSet.HImage.Dispose(); |
| | | imgSet.HImage = null; |