From f9c7928bff92596686e05a15fef21d499e954088 Mon Sep 17 00:00:00 2001 From: wells.liu <wells.liu@broconcentric.com> Date: 星期一, 06 七月 2020 18:17:41 +0800 Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071 --- src/Bro.M071.Process/M071Process.cs | 212 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 125 insertions(+), 87 deletions(-) diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs index 68b79c6..52d0f48 100644 --- a/src/Bro.M071.Process/M071Process.cs +++ b/src/Bro.M071.Process/M071Process.cs @@ -2,6 +2,7 @@ using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; +using Bro.M071.Model; using Bro.Process; using HalconDotNet; using System; @@ -13,6 +14,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using static Bro.Common.Helper.EnumHelper; namespace Bro.M071.Process { @@ -33,8 +35,10 @@ #region 浜嬩欢 public event Action OnMeasureStart; - public event Action<string> OnBarcodeChanged; + public event Action OnClearBarcode; public event Action<IShapeElement> OnElementUpdated; + public event Action<MachineState> OnMachineStateChanged; + public event Action OnFullResetDone; #endregion public override void Open() @@ -43,19 +47,22 @@ base.Open(); - CheckMachineState(); - } + SwitchBeep(false); + SwitchLightGreen(false); + SwitchLightRed(false); + SwitchLightYellow(false); - /// <summary> - /// 妫�鏌ヨ澶囩姸鎬� - /// </summary> - private void CheckMachineState() - { - throw new NotImplementedException(); + Reset(null, null, null); + FullReset(null); } private void InitialSetting() { + //鏁版嵁搴撹縼绉绘鏌� + DatabaseInitialize.Initialize(); + + MotionCardSettingCheck(); + Config.SnapshotPointCollection.ForEach(u => { u.GetHalconToolPathList().ForEach(path => @@ -110,7 +117,7 @@ if (keyRespone.Count == 0) throw new ProcessException($"{u.GetDisplayText()}瀵瑰簲鐨勫崟閿笉瀛樺湪鎴栦笉鍙敤"); - if (b.KeyResult == "All") + if (b.KeyResultId == "All") { keyRespone.SelectMany(kr => kr.KeyResultList).ToList().ForEach(r => { @@ -119,61 +126,48 @@ } else { - b.MeasureValueDict[b.KeyResult] = null; + b.MeasureValueDict[b.KeyResultId] = null; } }); }); } - #region InitialHalconTool - //protected override void InitialHalconTool() - //{ - // base.InitialHalconTool(); - - // Config.SnapshotPointCollection.ForEach(u => - // { - // u.GetHalconToolPathList().ForEach(path => - // { - // if (!string.IsNullOrWhiteSpace(path)) - // { - // string directoryPath = Path.GetDirectoryName(path); - // string fileName = Path.GetFileNameWithoutExtension(path); - - // HDevEngineTool tool = new HDevEngineTool(directoryPath); - // tool.LoadProcedure(fileName); - - // //浣跨敤鈥渱鈥濅綔涓洪棿闅旂 - // _halconToolDict[u.Id + "|" + path] = tool; - // } - // }); - // }); - //} - #endregion - - private string barCode = ""; - public string BarCode + #region 娴佺▼涓姏鍑哄紓甯� + public override void ExceptionRaisedInMonitor(Exception ex) { - get => barCode; - set + if (ex is ProcessException pEx) { - if (barCode != value) + if (pEx.Level >= ExceptionLevel.Fatal) { - barCode = value; - OnBarcodeChanged?.Invoke(value); + RaisedAlarm(pEx.Message); + MachineState = MachineState.Alarm; } } + else + { + RaisedAlarm(ex.Message); + MachineState = MachineState.Alarm; + } } + #endregion + + public string BarCode { get; set; } List<ProductionMeasurement> productionList = new List<ProductionMeasurement>(); [ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)] public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { + if (MachineState != MachineState.Ready) + throw new ProcessException("鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�", null, ExceptionLevel.Fatal); + if (string.IsNullOrWhiteSpace(BarCode)) { + OnClearBarcode?.Invoke(); throw new ProcessException("鏈緭鍏ヤ骇鍝佹潯鐮侊紝璇峰嬁寮�濮嬫祴閲�"); } + MachineState = MachineState.Running; OnMeasureStart?.BeginInvoke(null, null); var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone(); @@ -186,6 +180,7 @@ { Barcode = BarCode, Measurements = measurements, + StartTime = DateTime.Now, }; var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode); @@ -217,14 +212,25 @@ var response = motionDevice.Run(s.MotionOp.OpConfig); if (!response.Result) { - throw new ProcessException($"{device.Name}寮傚父锛寋response.Message}", null, ExceptionLevel.Info); + throw new ProcessException($"{device.Name}寮傚父锛寋response.Message}", null, ExceptionLevel.Fatal); } CameraBase camera = DeviceCollection.FirstOrDefault(u => u.Id == s.CameraOp.Device) as CameraBase; if (camera == null) return; - HImage hImage = CollectHImage(camera, s.CameraOp.OpConfig, out string imgSetId); + string imgSetId = ""; + HImage hImage = null; + try + { + hImage = CollectHImage(camera, s.CameraOp.OpConfig, out imgSetId); + } + catch (ProcessException pEx) + { + pEx.Level = ExceptionLevel.Fatal; + throw pEx; + } + if (string.IsNullOrWhiteSpace(imgSetId)) { return; @@ -234,42 +240,64 @@ }); BarCode = ""; + LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", ""); return new ProcessResponse(true); } - /// <summary> - /// 鏆傚仠鏍囧織 - /// WaitHandle 鏆傚仠鍙ユ焺 榛樿涓洪潪闃诲 鍙墽琛� - /// WaitResult 鏆傚仠鏍囧織 true 姝e父鎵ц false 鏆傚仠涓� - /// </summary> - ManualWaitConfirm _pauseHandle = new ManualWaitConfirm() + #region 鍙屾墜鍚姩 + bool isLeftStart = false; + bool IsLeftStart { - WaitHandle = new ManualResetEvent(true), - WaitResult = true, - }; - - [ProcessMethod("", "PauseJob", "鏆傚仠娴佺▼", InvokeType.TestInvoke)] - public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) - { - if (_pauseHandle.WaitResult) + get => isLeftStart; + set { - #region 鏉垮崱鏆傚仠鍔ㄤ綔 - #endregion - - _pauseHandle.WaitHandle.Reset(); + isLeftStart = value; + StartCheck(); } - else - { - #region 鏉垮崱鎭㈠鍔ㄤ綔 - #endregion - - _pauseHandle.WaitHandle.Set(); - } - - _pauseHandle.WaitResult = !_pauseHandle.WaitResult; - return new ProcessResponse(_pauseHandle.WaitResult); } + + bool isRightStart = false; + bool IsRightStart + { + get => isRightStart; + set + { + isRightStart = value; + StartCheck(); + } + } + + private void StartCheck() + { + if (isRightStart && isLeftStart) + { + StartJob(null, null, null); + } + } + + [ProcessMethod("", "Start_Left", "宸︽墜鍚姩", InvokeType.TestInvoke)] + public ProcessResponse Start_Left(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) + { + if (opConfig.InputPara != null && opConfig.InputPara.Count > 0) + { + IsLeftStart = opConfig.InputPara[0] == 1; + } + + return new ProcessResponse(); + } + + [ProcessMethod("", "Start_Right", "鍙虫墜鍚姩", InvokeType.TestInvoke)] + public ProcessResponse Start_Right(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) + { + if (opConfig.InputPara != null && opConfig.InputPara.Count > 0) + { + IsRightStart = opConfig.InputPara[0] == 1; + } + + return new ProcessResponse(); + } + #endregion #region 绉佹湁鏂规硶 private void MeasureProduction_PropertyChanged(object sender, PropertyChangedEventArgs e) @@ -332,18 +360,28 @@ { return; } - - //MES杈撳嚭 todo - - //Excel鎶ヨ〃杈撳嚭 todo - - //鏁版嵁搴撲繚瀛� todo - - SaveWholeImage(pMeasure); - - productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode); - pMeasure.Dispose(); } + + pMeasure.EndTime = DateTime.Now; + bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true); + OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0); + OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds); + + LogAsync(DateTime.Now, $"{pMeasure.Barcode} 妫�娴嬪畬鎴愶紝缁撴灉 {(pResult ? "OK" : "NG")}", ""); + + if (MachineState == MachineState.Running) + MachineState = MachineState.Ready; + + //MES杈撳嚭 todo + + //Excel鎶ヨ〃杈撳嚭 todo + + //鏁版嵁搴撲繚瀛� todo + + SaveWholeImage(pMeasure); + + productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode); + pMeasure.Dispose(); } } @@ -379,7 +417,7 @@ } } - private void SaveKeyImages(string barCode, MeasurementUint measureUnit) + private void SaveKeyImages(string barCode, MeasurementUnit measureUnit) { string measureName = measureUnit.GetDisplayText(); if (Config.ImageSaveOption.IsSaveOriginImage) @@ -410,7 +448,7 @@ } } - private async void SaveKeyImages(MeasurementUint measureUnit, string measureName, string dir) + private async void SaveKeyImages(MeasurementUnit measureUnit, string measureName, string dir) { await Task.Run(() => { @@ -430,7 +468,7 @@ } #endregion - private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUint> measureList) + private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) { await Task.Run(() => { -- Gitblit v1.8.0