public void RunAllTool() { HTuple /*start = null, */ end = null; //帧率统计增加 fps.IncreaseFrameNum(); fpsCount++; if (fpsCount > 10) { fps.UpdateFps(); fpsCount = 0; } RunStatus runStatus = new RunStatus(settingIndex, cameraIndex); runStatus.FpsStr = string.Format("FPS:{0:F1}|帧:{1}|", fps.GetFps(), fps.GetTotalFrameCount()); List <ToolBase> runToolList = ToolsFactory.GetToolList(settingIndex); Tools.CreateImage.CreateImageTool createImageTool = runToolList[0] as Tools.CreateImage.CreateImageTool; HWndCtrl hWndCtrl = cameraShowUnit.HWndUnit.HWndCtrl; try { HTuple toolStart = new HTuple(), toolEnd = new HTuple(); StatusManger statusManger = StatusManger.Instance; statusManger.RuningStatus = RuningStatus.图像检测中; runningResultFlag = false; toolErr = null; //开始运行所有工具 HOperatorSet.CountSeconds(out toolStart); //外部触发处理 if (isExtTrigger || isGrabber) { createImageTool.SettExtTriggerData(ImageData); isGrabber = false; } else { createImageTool.SetExtTriggerDataOff(); } StringBuilder MyStringBuilder = new StringBuilder(); //string yy = MyStringBuilder.ToString(); string datSend = ""; foreach (var item in runToolList) { if (item is IToolRun) { try { item.Run(); string result = item.IsOk ? "OK" : "NG"; Util.Notify(string.Format("{0}_{1} T={2:f2}ms,结果: {3}", item.Name, result, item.ExecutionTime, item.Result)); MyStringBuilder.Append(string.Format("{0}_{1}_T={2:f2}ms\r\n", item.Name, result, item.ExecutionTime)); if (item.IsOutputResults) { string dat = item.GetSendResult(); if (dat != string.Empty) { datSend += dat; datSend += toolDelimiter; } } runStatus.RunStatusList.Add(item.IsOk); } catch (Exception ex) { //Util.WriteLog(this.GetType(), ex); Util.Notify(Level.Err, string.Format("工具{0}运行出现异常{1}", item.Name, ex.Message)); runStatus.RunStatusList.Add(false); } } else { runStatus.RunStatusList.Add(true); } } runStatus.ResultMessage = MyStringBuilder.ToString(); //时间统计 HOperatorSet.CountSeconds(out toolEnd); double toolTime = (toolEnd - toolStart) * 1000.0; //toolStart) * 1000.0; Util.Notify(string.Format("工具组{0}图像处理用时{1:f2}ms", settingIndex, toolTime)); #region 3 查找是否存在运行错误的工具 toolErr = runToolList.Find(x => x.IsOk == false && x is IToolRun); if (toolErr == null && ToolsFactory.ToolsDic.Count > 0) { runningResultFlag = true; ok++; } else { runningResultFlag = false; ng++; Util.Notify(string.Format("工具{0}图像处理检测到异常", toolErr.Name)); } if (runningResultFlag == true) { datSend = Util.TrimEndString(datSend, toolDelimiter); datSend = Util.TrimStartString(datSend, toolDelimiter); } else { datSend = ("Image" + Environment.NewLine + "Done" + Environment.NewLine); } if (isOffLineMode == false) //这个变量与AutoUnit中的isTestMode不是同一个,这里是指AutoUnit的测试模式与离线模式。 { //SerialHelper.Instance.WriteCommdToSerial(datSend); //非相机输出模式下就直接输出文本信息 if (!CommHandle.Instance.CommunicationParam.IsCamIOOutput && datSend != string.Empty) { Util.Notify(string.Format("发送结果: {0}", datSend)); autoUnit.RunCommWriteDataThread.WriteData(datSend); } else { if (StatusManger.Instance.IsInterlocking && CameraManger.CameraDic.ContainsKey(settingIndex) && runningResultFlag == false) { CameraManger.CameraDic[settingIndex].Output(); //结果NG时相机外部输出信号导通。 } } } else { if (runningResultFlag == false) { Util.Notify(string.Format("测试结果:{0}", "NG")); } else { Util.Notify(string.Format("测试结果:{0}", "OK")); } } #endregion #region 4 显示所有的图形 //HTuple showStart; //HOperatorSet.CountSeconds(out showStart); autoUnit.Invoke(new Action <HWndCtrl, List <ToolBase>, bool>((h, l, f) => { ShowResult(h, l, f); }), hWndCtrl, runToolList, runningResultFlag); #endregion HTuple end1; HOperatorSet.CountSeconds(out end1); double time1 = (end1 - toolEnd) * 1000.0; Util.Notify(string.Format("工具组{0}分析显示用时{1:f2}ms", settingIndex, time1)); } catch (Exception) { //Util.WriteLog(this.GetType(), ex); Util.Notify(string.Format("图像处理异常")); } finally { HOperatorSet.CountSeconds(out end); double runTime = 0; runTime = (end - startExTime) * 1000.0; runStatus.OKCount = ok; runStatus.NgCount = ng; runStatus.CylceTime = runTime; RunStatus runStatusTmp = runStatus.DeepClone(); autoUnit.RefreshUI(runStatusTmp); //指示可以来图像处理 Util.Notify(string.Format("---工具组{0}运行完成,用时{1:f2}ms\r\n", settingIndex, runTime)); imageRunFinishSignalFlow.Set(); //离线模式 if (isOffLineMode && createImageTool.OffLineMode == true && createImageTool.AllReadFinish == false) { Task.Run(async delegate { await Task.Delay(1000); if (isOffLineMode) { TrigerRun(this.settingIndex, true); //离线测试模式时,接着触发下次离线测试。 } }); } else { isOffLineMode = false; //将该对象的离线模式标志复位,不再执行离线。 } } }