From eafdcc5ad6a55d3dfdec6c4787c3f3a9f32efc7f Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期二, 29 九月 2020 13:27:50 +0800 Subject: [PATCH] 1. M071B机台配置 2. GTS板卡添加回原点捕获模式和输入信号模式 3. CameraBase使用Dictionary类型做图片缓存 4. M071流程显式Copy,原来是为了避免内存泄漏,但目前来看不是这方面原因 5. Gocator驱动添加GoDataSet之类KObject资源显式回收,怀疑其中也有非托管对象资源,测试确实起到内存回收作用 --- src/Bro.M071.Process/UI/M071_MainForm.cs | 240 ++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 161 insertions(+), 79 deletions(-) diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs index 17b79c9..7035785 100644 --- a/src/Bro.M071.Process/UI/M071_MainForm.cs +++ b/src/Bro.M071.Process/UI/M071_MainForm.cs @@ -40,6 +40,10 @@ cvImage.SetScreenSize(); cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle; cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle; + + timer1.Enabled = true; + + btnReset.Text = $"澶嶄綅锛堥暱鎸墈Config.FullResetRequiredDuration}绉掑ぇ澶嶄綅锛�"; }; } @@ -53,38 +57,44 @@ if (string.IsNullOrWhiteSpace(Config.BackgroundImagePath)) return; - this.Invoke(new Action(() => + try { - try - { - Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath); - cvImage.LoadImage(image); - cvImage.SetScreenSize(); - } - catch (Exception ex) - { - LogAsync(new LogMsg(DateTime.Now, "杞藉叆鑳屾櫙鍥惧紓甯�", ex.Message)); - return; - } + this.Invoke(new Action(() => + { + try + { + Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath); + cvImage.LoadImage(image); + cvImage.SetScreenSize(); + } + catch (Exception ex) + { + LogAsync(new LogMsg(DateTime.Now, "杞藉叆鑳屾櫙鍥惧紓甯�", ex.Message)); + return; + } - cvImage.Elements.Clear(); - lvMeasures.Items.Clear(); + cvImage.Elements.Clear(); + lvMeasures.Items.Clear(); - txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked; + txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked; - Config.MeasurementUnitCollection.ForEach(u => - { - if (!u.IsEnabled) - return; + Config.MeasurementUnitCollection.ForEach(u => + { + if (!u.IsEnabled) + return; - var ele = new KeyIndicator(u.Id, u.DisplayLocation); - cvImage.Elements.Add(ele); + var ele = new KeyIndicator(u.Id, u.DisplayLocation); + cvImage.Elements.Add(ele); - ListViewItem item = new ListViewItem(u.GetDisplayText()); - item.Tag = u.Id; - lvMeasures.Items.Add(item); - }); - })); + ListViewItem item = new ListViewItem(u.GetDisplayText()); + item.Tag = u.Id; + lvMeasures.Items.Add(item); + }); + })); + } + catch (Exception ex) + { + } Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode; Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode; @@ -104,6 +114,9 @@ Config.PropertyChanged -= Config_PropertyChanged; Config.PropertyChanged += Config_PropertyChanged; + + Process_M071.OnElementUpdated -= Process_M071_OnElementUpdated; + Process_M071.OnElementUpdated += Process_M071_OnElementUpdated; } private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e) @@ -126,6 +139,27 @@ { tscEditLocation.Visible = tsmiShowEditor.Checked; tscEditLocation.BringToFront(); + } + + private void tsmiRefreshLabels_Click(object sender, EventArgs e) + { + cvImage.Elements.Clear(); + lvMeasures.Items.Clear(); + + Config.MeasurementUnitCollection.ForEach(u => + { + if (!u.IsEnabled) + return; + + var ele = new KeyIndicator(u.Id, u.DisplayLocation); + cvImage.Elements.Add(ele); + + ListViewItem item = new ListViewItem(u.GetDisplayText()); + item.Tag = u.Id; + lvMeasures.Items.Add(item); + }); + + this.Invalidate(); } #endregion @@ -223,6 +257,43 @@ } #endregion + #region 鏍囩缁撴灉鏄剧ず + private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj) + { + //this.Invoke(new Action(() => + //{ + // if (obj is KeyIndicator keyIndicator) + // { + // var ele = cvImage.Elements.FirstOrDefault(u => u.ID == keyIndicator.ID); + + // //(ele as KeyIndicator).Text = keyIndicator.Text; + // //(ele as KeyIndicator).ResultState = keyIndicator.ResultState; + // if (ele != null) + // { + // ele = keyIndicator; + // } + + // this.Invalidate(); + // } + //})); + + if (obj is KeyIndicator keyIndicator) + { + this.Invoke(new Action(() => + { + var ele = cvImage.Elements.FirstOrDefault(u => u.ID == keyIndicator.ID); + + (ele as KeyIndicator).Text = keyIndicator.Text; + (ele as KeyIndicator).ResultState = keyIndicator.ResultState; + + this.Invalidate(); + })); + } + + await Task.Delay(100); + } + #endregion + #region 涓婃柟鐘舵�佸尯 #region 鏉$爜 @@ -233,6 +304,10 @@ if (keyStr.Length == 1) { _barcode += keyStr.ToUpper(); + } + else if (keyStr.Length == 2 && keyStr.StartsWith("D")) + { + _barcode += keyStr.Substring(1).ToUpper(); } if (e.KeyValue == 13) @@ -261,46 +336,54 @@ #region 鏈哄彴鐘舵�� private async void M071_MainForm_MachineStateChanged(MachineState state) { - lblMachineState.BeginInvoke(new Action(() => + if (lblMachineState.IsHandleCreated) { - switch (state) + lblMachineState.Invoke(new Action(() => { - case MachineState.Alarm: - btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Red; - btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White; - lblMachineState.Text = "璀︽姤"; + 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 = 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.Text = "缁х画娴嬮噺"; + btnStartMeasure.Enabled = true; + break; + case MachineState.Ready: + btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; + btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black; + lblMachineState.Text = "灏辩华"; - btnStartMeasure.Enabled = true; - break; - case MachineState.Running: - btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; - btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen; - lblMachineState.Text = "杩愯"; + btnStartMeasure.Text = "寮�濮嬫祴閲�"; + btnStartMeasure.Enabled = true; + break; + case MachineState.Running: + btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Transparent; + 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; - } - })); + btnStartMeasure.Text = "鏆傚仠娴嬮噺"; + btnStartMeasure.Enabled = true; + break; + case MachineState.Unknown: + btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control; + btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText; + lblMachineState.Text = "鏈煡"; + + btnStartMeasure.Enabled = false; + break; + } + })); + } await Task.Delay(100); } @@ -333,7 +416,7 @@ lblProductionState.Text = "NG"; } - btnStartMeasure.Text = "寮�濮嬫祴閲�"; + //btnStartMeasure.Text = "寮�濮嬫祴閲�"; })); await Task.Delay(100); } @@ -347,6 +430,15 @@ lblProductionState.Text = "娴嬭瘯涓�"; lblCT.Text = ""; + + cvImage.Elements.ToList().ForEach(e => + { + if (e is KeyIndicator indicator) + { + indicator.Text = ""; + indicator.ResultState = null; + } + }); })); await Task.Delay(100); } @@ -356,9 +448,6 @@ private async void btnStartMeasure_Click(object sender, EventArgs e) { - btnStartMeasure.Enabled = false; - bool isBreak = false; - if (btnStartMeasure.Text == "寮�濮嬫祴閲�") { await Task.Run(() => @@ -369,31 +458,19 @@ } 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.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 0 } }, null, null); - btnStartMeasure.Text = "鏆傚仠娴嬮噺"; + Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 10 } }, null, null); } else { - Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, null, null); - btnStartMeasure.Text = "缁х画娴嬮噺"; + Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 11 } }, null, null); } - - btnStartMeasure.Enabled = true; } #region 澶嶄綅鎿嶄綔 @@ -414,7 +491,7 @@ Process_M071.Reset(null, null, null); } - Process_M071.ResetTimer.Change(-1, 1000 * 5); + Process_M071.ResetTimer.Change(1000 * Config.FullResetRequiredDuration, -1); } private void btnReset_MouseUp(object sender, MouseEventArgs e) @@ -422,5 +499,10 @@ Process_M071.ResetTimer.Change(-1, -1); } #endregion + + private void timer1_Tick(object sender, EventArgs e) + { + cvImage.Refresh(); + } } } -- Gitblit v1.8.0