From 3322022068ab818912d6f5d9e5eb31f51cc639c2 Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期四, 24 二月 2022 09:12:30 +0800 Subject: [PATCH] 添加配置文件的DataShift2 --- src/Bro.M071.Process/M071Process.cs | 125 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 118 insertions(+), 7 deletions(-) diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs index a281648..18f263e 100644 --- a/src/Bro.M071.Process/M071Process.cs +++ b/src/Bro.M071.Process/M071Process.cs @@ -54,6 +54,8 @@ string _precision = "f3"; double _allowedShift = 0; + double _allowedShift2 = 0; + public override void Open() { InitialSetting(); @@ -84,11 +86,39 @@ 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() @@ -531,6 +561,58 @@ 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 绉佹湁鏂规硶 @@ -582,7 +664,6 @@ } else { - _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array); if (!_halconToolDict[toolKey].RunProcedure(out string error)) { @@ -595,14 +676,22 @@ 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); @@ -1424,21 +1513,43 @@ } else { - var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList(); + 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}鍘熷鏁版嵁{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); - return results[index]; + + 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}", ""); } } } -- Gitblit v1.8.0