src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -138,7 +138,7 @@ [Category("板卡操作")] [Description("板卡操作配置基类集合,依次执行")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))] [Editor(typeof(ComplexCollectionEditor<MotionCardOperationSet>), typeof(UITypeEditor))] public List<MotionCardOperationSet> OperationCollection { get; set; } = new List<MotionCardOperationSet>(); public string GetDisplayText() @@ -155,6 +155,7 @@ [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(IORefrenceItemCollectionEditor), typeof(UITypeEditor))] public List<IORefrenceItem> PreCheckIOCollection { get; set; } = new List<IORefrenceItem>(); [Category("IO操作配置")] [Description("超时设置,单位:ms")] [DisplayName("IO预检查超时")] src/Bro.Common.Device/Helper/AspectHelper.cs
@@ -88,7 +88,7 @@ // new ProcessException(ex); //} args.FlowBehavior = FlowBehavior.ThrowException; args.FlowBehavior = FlowBehavior.Return; } } #endregion src/Bro.Common.Model/Interface/IMenuNode.cs
@@ -25,7 +25,7 @@ public interface ILogOutput { Action<LogMsg> OnLogMsgOutput { get; set; } event Action<LogMsg> OnLogMsgOutput; void LogDisplay(LogMsg msg); } } src/Bro.M071.Process/Bro.M071.Process.csproj
@@ -12,6 +12,8 @@ <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <Deterministic>true</Deterministic> <NuGetPackageImportStamp> </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -90,6 +92,9 @@ <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> <Reference Include="PostSharp, Version=6.2.7.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7, processorArchitecture=MSIL"> <HintPath>..\..\packages\PostSharp.Redist.6.2.7\lib\net45\PostSharp.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> src/Bro.M071.Process/M071Models.cs
@@ -209,6 +209,10 @@ public List<IShapeElement> ElementList = new List<IShapeElement>(); public DateTime? StartTime = null; public DateTime? EndTime = null; public event PropertyChangedEventHandler PropertyChanged; public void Dispose() src/Bro.M071.Process/M071Process.cs
@@ -13,6 +13,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; namespace Bro.M071.Process { @@ -35,6 +36,8 @@ public event Action OnMeasureStart; public event Action OnClearBarcode; public event Action<IShapeElement> OnElementUpdated; public event Action<MachineState> OnMachineStateChanged; public event Action OnFullResetDone; #endregion public override void Open() @@ -43,15 +46,8 @@ base.Open(); CheckMachineState(); } /// <summary> /// 检查设备状态 /// </summary> private void CheckMachineState() { //throw new NotImplementedException(); Reset(null, null, null); FullReset(null); } private void InitialSetting() @@ -125,29 +121,23 @@ }); } #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; // } // }); // }); //} #region 流程中抛出异常 public override void ExceptionRaisedInMonitor(Exception ex) { if (ex is ProcessException pEx) { if (pEx.Level >= ExceptionLevel.Fatal) { RaisedAlarm(pEx.Message); MachineState = MachineState.Alarm; } } else { RaisedAlarm(ex.Message); MachineState = MachineState.Alarm; } } #endregion public string BarCode { get; set; } @@ -157,12 +147,16 @@ [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(); @@ -175,6 +169,7 @@ { Barcode = BarCode, Measurements = measurements, StartTime = DateTime.Now, }; var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode); @@ -206,14 +201,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; @@ -223,9 +229,64 @@ }); BarCode = ""; LogAsync(DateTime.Now, $"{pMeasure.Barcode}测量动作完成", ""); return new ProcessResponse(true); } #region 双手启动 bool isLeftStart = false; bool IsLeftStart { get => isLeftStart; set { isLeftStart = value; StartCheck(); } } 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) @@ -289,6 +350,16 @@ return; } 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 src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -16,11 +16,11 @@ { public partial class M071Process { Timer _resetTimer = null; public Timer ResetTimer = null; const int FULLRESETTIME = 5; MachineState machineState = MachineState.Unknown; MachineState MachineState public MachineState MachineState { get => machineState; set @@ -40,6 +40,8 @@ default: break; } OnMachineStateChanged?.Invoke(machineState); } } @@ -66,21 +68,26 @@ MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice); if (_resetTimer == null) RaisedAlarm(""); MachineState = MachineState.Ready; if (ResetTimer == null) { _resetTimer = new Timer(FullReset, null, -1, -1); ResetTimer = new Timer(FullReset, null, -1, -1); } if (opConfig.InputPara.Count > 0) { //大复位信号 _resetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1); ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1); } //if (invokeDevice is MotionCardBase motionCard) //{ // motionCard.Run(opConfig); //} LogAsync(DateTime.Now, "普通复位动作完成", ""); return new ProcessResponse(true); } @@ -116,8 +123,14 @@ // motionCard.Run(opConfig); //} //MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice); MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice); productionList.ForEach(u => u.Dispose()); productionList.Clear(); OnFullResetDone?.Invoke(); LogAsync(DateTime.Now, "大复位动作完成", ""); return new ProcessResponse(true); } @@ -135,14 +148,22 @@ [ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)] public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { if (_pauseHandle.WaitResult) if (!_pauseHandle.WaitResult) { #region 板卡暂停动作 #endregion _pauseHandle.WaitHandle.Reset(); } else _pauseHandle.WaitResult = !_pauseHandle.WaitResult; return new ProcessResponse(_pauseHandle.WaitResult); } [ProcessMethod("", "ResumeJob", "继续流程", InvokeType.TestInvoke)] public ProcessResponse ResumeJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { if (_pauseHandle.WaitResult) { #region 板卡恢复动作 #endregion src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
@@ -45,7 +45,10 @@ this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.lvMeasures = new System.Windows.Forms.ListView(); this.propGridKeyIndicator = new System.Windows.Forms.PropertyGrid(); this.btnStartMeasure = new System.Windows.Forms.Button(); this.btnReset = new System.Windows.Forms.Button(); this.contextMenuStrip1.SuspendLayout(); this.plImage.SuspendLayout(); this.tscEditLocation.ContentPanel.SuspendLayout(); this.tscEditLocation.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); @@ -113,7 +116,7 @@ this.lblProductionState.AutoSize = true; this.lblProductionState.BackColor = System.Drawing.Color.Lime; this.lblProductionState.Font = new System.Drawing.Font("Tahoma", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134))); this.lblProductionState.ForeColor = System.Drawing.Color.White; this.lblProductionState.ForeColor = System.Drawing.Color.DarkGreen; this.lblProductionState.Location = new System.Drawing.Point(405, 13); this.lblProductionState.Name = "lblProductionState"; this.lblProductionState.Size = new System.Drawing.Size(39, 24); @@ -125,7 +128,7 @@ this.lblMachineState.AutoSize = true; this.lblMachineState.BackColor = System.Drawing.Color.Lime; this.lblMachineState.Font = new System.Drawing.Font("Tahoma", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134))); this.lblMachineState.ForeColor = System.Drawing.Color.White; this.lblMachineState.ForeColor = System.Drawing.Color.DarkGreen; this.lblMachineState.Location = new System.Drawing.Point(22, 12); this.lblMachineState.Name = "lblMachineState"; this.lblMachineState.Size = new System.Drawing.Size(79, 24); @@ -138,6 +141,7 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.plImage.ContextMenuStrip = this.contextMenuStrip1; this.plImage.Controls.Add(this.tscEditLocation); this.plImage.Location = new System.Drawing.Point(1, 47); this.plImage.Name = "plImage"; this.plImage.Size = new System.Drawing.Size(796, 304); @@ -149,11 +153,11 @@ // tscEditLocation.ContentPanel // this.tscEditLocation.ContentPanel.Controls.Add(this.tableLayoutPanel1); this.tscEditLocation.ContentPanel.Size = new System.Drawing.Size(209, 326); this.tscEditLocation.ContentPanel.Size = new System.Drawing.Size(209, 279); this.tscEditLocation.Dock = System.Windows.Forms.DockStyle.Right; this.tscEditLocation.Location = new System.Drawing.Point(591, 0); this.tscEditLocation.Location = new System.Drawing.Point(587, 0); this.tscEditLocation.Name = "tscEditLocation"; this.tscEditLocation.Size = new System.Drawing.Size(209, 351); this.tscEditLocation.Size = new System.Drawing.Size(209, 304); this.tscEditLocation.TabIndex = 0; this.tscEditLocation.Text = "toolStripContainer1"; this.tscEditLocation.Visible = false; @@ -172,7 +176,7 @@ this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.Size = new System.Drawing.Size(209, 326); this.tableLayoutPanel1.Size = new System.Drawing.Size(209, 279); this.tableLayoutPanel1.TabIndex = 0; // // btnConfirmEdit @@ -181,7 +185,7 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.btnConfirmEdit.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnConfirmEdit.Location = new System.Drawing.Point(3, 293); this.btnConfirmEdit.Location = new System.Drawing.Point(3, 246); this.btnConfirmEdit.Name = "btnConfirmEdit"; this.btnConfirmEdit.Size = new System.Drawing.Size(98, 30); this.btnConfirmEdit.TabIndex = 0; @@ -195,7 +199,7 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.btnCancelEdit.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnCancelEdit.Location = new System.Drawing.Point(107, 293); this.btnCancelEdit.Location = new System.Drawing.Point(107, 246); this.btnCancelEdit.Name = "btnCancelEdit"; this.btnCancelEdit.Size = new System.Drawing.Size(99, 30); this.btnCancelEdit.TabIndex = 0; @@ -218,8 +222,8 @@ // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.propGridKeyIndicator); this.splitContainer1.Size = new System.Drawing.Size(203, 284); this.splitContainer1.SplitterDistance = 163; this.splitContainer1.Size = new System.Drawing.Size(203, 237); this.splitContainer1.SplitterDistance = 136; this.splitContainer1.TabIndex = 1; // // lvMeasures @@ -231,7 +235,7 @@ this.lvMeasures.Location = new System.Drawing.Point(0, 0); this.lvMeasures.MultiSelect = false; this.lvMeasures.Name = "lvMeasures"; this.lvMeasures.Size = new System.Drawing.Size(203, 163); this.lvMeasures.Size = new System.Drawing.Size(203, 136); this.lvMeasures.TabIndex = 0; this.lvMeasures.UseCompatibleStateImageBehavior = false; this.lvMeasures.View = System.Windows.Forms.View.List; @@ -242,26 +246,59 @@ this.propGridKeyIndicator.Dock = System.Windows.Forms.DockStyle.Fill; this.propGridKeyIndicator.Location = new System.Drawing.Point(0, 0); this.propGridKeyIndicator.Name = "propGridKeyIndicator"; this.propGridKeyIndicator.Size = new System.Drawing.Size(203, 117); this.propGridKeyIndicator.Size = new System.Drawing.Size(203, 97); this.propGridKeyIndicator.TabIndex = 0; this.propGridKeyIndicator.ToolbarVisible = false; // // btnStartMeasure // this.btnStartMeasure.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnStartMeasure.BackColor = System.Drawing.Color.Lime; this.btnStartMeasure.Cursor = System.Windows.Forms.Cursors.Hand; this.btnStartMeasure.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134))); this.btnStartMeasure.ForeColor = System.Drawing.Color.DarkGreen; this.btnStartMeasure.Location = new System.Drawing.Point(678, 8); this.btnStartMeasure.Name = "btnStartMeasure"; this.btnStartMeasure.Size = new System.Drawing.Size(110, 35); this.btnStartMeasure.TabIndex = 5; this.btnStartMeasure.Text = "开始测量"; this.btnStartMeasure.UseVisualStyleBackColor = false; this.btnStartMeasure.Click += new System.EventHandler(this.btnStartMeasure_Click); // // btnReset // this.btnReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnReset.BackColor = System.Drawing.Color.Orange; this.btnReset.Cursor = System.Windows.Forms.Cursors.Hand; this.btnReset.Font = new System.Drawing.Font("宋体", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134))); this.btnReset.ForeColor = System.Drawing.Color.DarkGreen; this.btnReset.Location = new System.Drawing.Point(531, 8); this.btnReset.Name = "btnReset"; this.btnReset.Size = new System.Drawing.Size(141, 35); this.btnReset.TabIndex = 5; this.btnReset.Text = "复位(长按5s大复位)"; this.btnReset.UseVisualStyleBackColor = false; this.btnReset.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnReset_MouseDown); this.btnReset.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnReset_MouseUp); // // M071_MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 351); this.Controls.Add(this.btnReset); this.Controls.Add(this.btnStartMeasure); this.Controls.Add(this.lblCT); this.Controls.Add(this.txtBarcode); this.Controls.Add(this.lblProductionState); this.Controls.Add(this.lblMachineState); this.Controls.Add(this.plImage); this.Controls.Add(this.tscEditLocation); this.KeyPreview = true; this.Name = "M071_MainForm"; this.Text = "M071_MainForm"; this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.M071_MainForm_KeyUp); this.contextMenuStrip1.ResumeLayout(false); this.plImage.ResumeLayout(false); this.tscEditLocation.ContentPanel.ResumeLayout(false); this.tscEditLocation.ResumeLayout(false); this.tscEditLocation.PerformLayout(); @@ -293,5 +330,7 @@ private System.Windows.Forms.Label lblProductionState; private System.Windows.Forms.TextBox txtBarcode; private System.Windows.Forms.Label lblCT; private System.Windows.Forms.Button btnStartMeasure; private System.Windows.Forms.Button btnReset; } } src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static Bro.Common.Helper.EnumHelper; namespace Bro.M071.Process.UI { @@ -17,6 +18,7 @@ { Canvas cvImage = new Canvas(); M071Config Config => Process?.IConfig as M071Config; M071Process Process_M071 => Process as M071Process; public M071_MainForm() { @@ -69,8 +71,21 @@ txtBarcode.ReadOnly = Config.IsBarcodeManulInputBlocked; (Process as M071Process).OnClearBarcode -= M071_MainForm_OnClearBarcode; (Process as M071Process).OnClearBarcode += M071_MainForm_OnClearBarcode; Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode; Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode; Process_M071.OnUpdateResult -= M071_MainForm_UpdateResult; Process_M071.OnUpdateResult += M071_MainForm_UpdateResult; Process_M071.OnUpdateCT -= M071_MainForm_UpdateCT; Process_M071.OnUpdateCT += M071_MainForm_UpdateCT; Process_M071.OnMeasureStart -= M071_MainForm_MeasureStart; Process_M071.OnMeasureStart += M071_MainForm_MeasureStart; Process_M071.OnMachineStateChanged -= M071_MainForm_MachineStateChanged; Process_M071.OnMachineStateChanged += M071_MainForm_MachineStateChanged; Process_M071.OnFullResetDone -= Process_M071_FullResetDone; Process_M071.OnFullResetDone += Process_M071_FullResetDone; } #region 图片区右键菜单 @@ -157,7 +172,7 @@ private void txtBarcode_TextChanged(object sender, EventArgs e) { (Process as M071Process).BarCode = txtBarcode.Text.Trim(); Process_M071.BarCode = txtBarcode.Text.Trim(); } private void M071_MainForm_OnClearBarcode() @@ -166,7 +181,169 @@ } #endregion #region 机台状态 private async void M071_MainForm_MachineStateChanged(MachineState state) { lblMachineState.BeginInvoke(new Action(() => { switch (state) { case MachineState.Alarm: btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Red; btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White; lblMachineState.Text = "警报"; btnStartMeasure.Enabled = false; break; case MachineState.Pause: btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Yellow; btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black; lblMachineState.Text = "暂停"; //btnStartMeasure.Text = "暂停测量"; btnStartMeasure.Enabled = true; break; case MachineState.Ready: btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White; lblMachineState.Text = "就绪"; btnStartMeasure.Enabled = true; break; case MachineState.Running: btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen; lblMachineState.Text = "运行"; btnStartMeasure.Enabled = true; break; case MachineState.Unknown: btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control; btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText; lblMachineState.Text = "未知"; break; } })); await Task.Delay(100); } #endregion #region 产品结果 private async void M071_MainForm_UpdateCT(float ct) { lblCT.BeginInvoke(new Action(() => { lblCT.Text = ct.ToString("f2") + " 秒"; })); await Task.Delay(100); } private async void M071_MainForm_UpdateResult(DateTime arg1, int result) { this.BeginInvoke(new Action(() => { if (result == 1) { lblProductionState.BackColor = Color.Green; lblProductionState.ForeColor = Color.White; lblProductionState.Text = "OK"; } else { lblProductionState.BackColor = Color.Red; lblProductionState.ForeColor = Color.White; lblProductionState.Text = "NG"; } btnStartMeasure.Text = "开始测量"; })); await Task.Delay(100); } private async void M071_MainForm_MeasureStart() { this.BeginInvoke(new Action(() => { lblProductionState.BackColor = SystemColors.Control; lblProductionState.ForeColor = SystemColors.ControlText; lblProductionState.Text = "测试中"; lblCT.Text = ""; })); await Task.Delay(100); } #endregion #endregion private async void btnStartMeasure_Click(object sender, EventArgs e) { btnStartMeasure.Enabled = false; bool isBreak = false; if (btnStartMeasure.Text == "开始测量") { await Task.Run(() => { try { Process_M071.StartJob(null, null, null); } catch (Exception ex) { isBreak = true; LogAsync(DateTime.Now, "流程异常", ex.Message); Process_M071.ExceptionRaisedInMonitor(ex); btnStartMeasure.Text = "开始测量"; } }); if (!isBreak) btnStartMeasure.Text = "暂停测量"; } else if (btnStartMeasure.Text == "继续测量") { Process_M071.ResumeJob(null, null, null); btnStartMeasure.Text = "暂停测量"; } else { Process_M071.PauseJob(null, null, null); btnStartMeasure.Text = "继续测量"; } btnStartMeasure.Enabled = true; } #region 复位操作 private async void Process_M071_FullResetDone() { btnStartMeasure.BeginInvoke(new Action(() => { btnStartMeasure.Enabled = true; btnStartMeasure.Text = "开始测量"; })); await Task.Delay(100); } private void btnReset_MouseDown(object sender, MouseEventArgs e) { if (Process_M071.MachineState != MachineState.Running) { Process_M071.Reset(null, null, null); } Process_M071.ResetTimer.Change(-1, 1000 * 5); } private void btnReset_MouseUp(object sender, MouseEventArgs e) { Process_M071.ResetTimer.Change(-1, -1); } #endregion } } src/Bro.M071.Process/packages.config
@@ -3,5 +3,6 @@ <package id="Autofac" version="4.9.4" targetFramework="net452" /> <package id="DockPanelSuite" version="3.0.6" targetFramework="net452" /> <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" /> <package id="PostSharp.Redist" version="6.2.7" targetFramework="net452" /> <package id="WeifenLuo.WinFormsUI.Docking" version="2.1.0" targetFramework="net452" /> </packages> src/Bro.Process/ProcessControl.cs
@@ -32,8 +32,8 @@ #region AutoFac注册 GlobalVar.Builder.RegisterInstance(this).As<IProcess>().ExternallyOwned(); GlobalVar.Builder.RegisterInstance(IConfig).As<IProcessConfig>().ExternallyOwned(); GlobalVar.Builder.RegisterInstance(DeviceCollection).ExternallyOwned(); GlobalVar.Builder.RegisterInstance(ProcessMethodCollection).ExternallyOwned(); GlobalVar.Builder.RegisterInstance(DeviceCollection); GlobalVar.Builder.RegisterInstance(ProcessMethodCollection); //if (isBuild) //{ @@ -520,6 +520,9 @@ return; } if (!ProcessInvokePreCheck()) return; IOperationConfig config = monitorSet.OpConfig; object res = null; int reTryTimes = config.ReTryTimes; @@ -578,6 +581,8 @@ } LogAsync(DateTime.Now, methodCode + "异常信息", ex.GetExceptionMessage()); ExceptionRaisedInMonitor(ex); } } @@ -600,6 +605,23 @@ sw.Stop(); LogAsync(DateTime.Now, $"{device.Name}调用{methodCode}完成,耗时{sw.ElapsedMilliseconds}ms", ""); TimeRecordCSV(DateTime.Now, device.Name, $"{methodCode}调用完成", (int)sw.ElapsedMilliseconds); } /// <summary> /// 流程执行的预检查 /// </summary> /// <returns></returns> public virtual bool ProcessInvokePreCheck() { return true; } /// <summary> /// 监听流程中异常抛出 在具体业务中具体处理 /// </summary> /// <param name="ex">监听流程中异常对象</param> public virtual void ExceptionRaisedInMonitor(Exception ex) { } #endregion @@ -698,6 +720,11 @@ OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null); } public virtual void RaisedAlarm(string alarmMsg) { OnAlarmUpdate?.Invoke(alarmMsg); } #endregion #region ILogger src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs
@@ -38,7 +38,7 @@ } #region ILogoutput public Action<LogMsg> OnLogMsgOutput { get; set; } public event Action<LogMsg> OnLogMsgOutput; public void LogDisplay(LogMsg msg) { @@ -157,11 +157,18 @@ { OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}调用开始", "")); ProcessResponse response = _method.Invoke(Process, new object[] { opConfig, _invokeDevice, _sourceDevice }) as ProcessResponse; if (response != null) try { OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}调用完成", $"反馈:{JsonConvert.SerializeObject(response)}")); ProcessResponse response = _method.Invoke(Process, new object[] { opConfig, _invokeDevice, _sourceDevice }) as ProcessResponse; if (response != null) { OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}调用完成", $"反馈:{JsonConvert.SerializeObject(response)}")); } } catch (Exception ex) { OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}调用异常", ex.GetExceptionMessage())); } }); } src/Bro.UI.Config/MainFrm.cs
@@ -90,7 +90,9 @@ private void RegisterEvent(MenuFrmBase dockFrm) { dockFrm.OnUploadProcess = DockFrm_OnUploadProcess; dockFrm.OnLogMsgOutput = DockFrm_OnLogMsgOutput; dockFrm.OnLogMsgOutput -= DockFrm_OnLogMsgOutput; dockFrm.OnLogMsgOutput += DockFrm_OnLogMsgOutput; //if (dockFrm is FrmDevices) //{ @@ -167,9 +169,14 @@ }); } private void Process_OnAlarmUpdate(string alarmMsg) private async void Process_OnAlarmUpdate(string alarmMsg) { tsslWarning.Text = alarmMsg; this.BeginInvoke(new Action(() => { tsslWarning.Text = alarmMsg; })); await Task.Delay(100); } private ToolStripMenuItem GetMatchNode(ToolStripItemCollection items, string parentMenuCode) src/Bro.UI.Config/MenuForms/FrmCalib.cs
@@ -16,7 +16,8 @@ ctrlMethodInvoker.Dock = DockStyle.Fill; plMain.Controls.Add(ctrlMethodInvoker); ctrlMethodInvoker.OnLogMsgOutput = OnLogMsgOutput; ctrlMethodInvoker.OnLogMsgOutput -= LogAsync; ctrlMethodInvoker.OnLogMsgOutput += LogAsync; } public override void OnProcessUpdated() src/Bro.UI.Config/MenuForms/FrmStatistic.cs
@@ -359,8 +359,10 @@ Process.OnAlarmUpdate -= Process_OnAlarmUpdate; Process.OnAlarmUpdate += Process_OnAlarmUpdate; Process.OnUpdateResult = UpdateResultOK; Process.OnUpdateCT = UpdateCT; Process.OnUpdateResult -= UpdateResultOK; Process.OnUpdateCT -= UpdateCT; Process.OnUpdateResult += UpdateResultOK; Process.OnUpdateCT += UpdateCT; _availableTimer = new System.Threading.Timer(AvailableTimerCallBack, null, -1, -1); _idleTimer = new System.Threading.Timer(IdleTimerCallBack, null, -1, -1); src/Bro.UI.Config/MenuForms/FrmTest.cs
@@ -16,7 +16,8 @@ ctrlMethodInvoker.Dock = DockStyle.Fill; plMain.Controls.Add(ctrlMethodInvoker); ctrlMethodInvoker.OnLogMsgOutput = OnLogMsgOutput; ctrlMethodInvoker.OnLogMsgOutput -= LogAsync; ctrlMethodInvoker.OnLogMsgOutput += LogAsync; } public override void OnProcessUpdated() src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs
@@ -10,7 +10,7 @@ public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput { public Action<string, IProcess> OnUploadProcess { get; set; } public Action<LogMsg> OnLogMsgOutput { get; set; } public event Action<LogMsg> OnLogMsgOutput; public string Id { get; set; } = Guid.NewGuid().ToString(); private IProcess process = null;