领胜LDS 键盘AOI检测项目
wells
2020-07-12 5bf1b91009a182188d6d2245aa71653801eea60b
src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -53,6 +53,8 @@
            if (string.IsNullOrWhiteSpace(Config.BackgroundImagePath))
                return;
            try
            {
            this.Invoke(new Action(() =>
            {
                try
@@ -85,6 +87,10 @@
                    lvMeasures.Items.Add(item);
                });
            }));
            }
            catch (Exception ex)
            {
            }
            Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode;
            Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode;
@@ -104,6 +110,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)
@@ -223,6 +232,26 @@
        }
        #endregion
        #region 标签结果显示
        private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj)
        {
            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 条码
@@ -261,6 +290,8 @@
        #region 机台状态
        private async void M071_MainForm_MachineStateChanged(MachineState state)
        {
            if (lblMachineState.IsHandleCreated)
            {
            lblMachineState.BeginInvoke(new Action(() =>
            {
                switch (state)
@@ -270,37 +301,48 @@
                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
                        lblMachineState.Text = "警报";
                            btnStartMeasure.Text = "开始测量";
                        btnStartMeasure.Enabled = false;
                            btnStartMeasure.BackColor = Color.Red;
                        break;
                    case MachineState.Pause:
                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Yellow;
                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
                        lblMachineState.Text = "暂停";
                        //btnStartMeasure.Text = "暂停测量";
                            btnStartMeasure.Text = "继续测量";
                        btnStartMeasure.Enabled = true;
                            btnStartMeasure.BackColor = Color.Lime;
                        break;
                    case MachineState.Ready:
                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
                        lblMachineState.Text = "就绪";
                            btnStartMeasure.Text = "开始测量";
                        btnStartMeasure.Enabled = true;
                            btnStartMeasure.BackColor = Color.Lime;
                        break;
                    case MachineState.Running:
                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen;
                        lblMachineState.Text = "运行";
                            btnStartMeasure.Text = "暂停测量";
                        btnStartMeasure.Enabled = true;
                            btnStartMeasure.BackColor = Color.Lime;
                        break;
                    case MachineState.Unknown:
                        btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control;
                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText;
                        lblMachineState.Text = "未知";
                            btnStartMeasure.Enabled = false;
                            btnStartMeasure.BackColor = Color.Red;
                        break;
                }
            }));
            }
            await Task.Delay(100);
        }
@@ -333,7 +375,7 @@
                    lblProductionState.Text = "NG";
                }
                btnStartMeasure.Text = "开始测量";
                //btnStartMeasure.Text = "开始测量";
            }));
            await Task.Delay(100);
        }
@@ -347,6 +389,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 +407,6 @@
        private async void btnStartMeasure_Click(object sender, EventArgs e)
        {
            btnStartMeasure.Enabled = false;
            bool isBreak = false;
            if (btnStartMeasure.Text == "开始测量")
            {
                await Task.Run(() =>
@@ -369,31 +417,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 = "暂停测量";
            }
            else
            {
                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, null, null);
                btnStartMeasure.Text = "继续测量";
            }
            btnStartMeasure.Enabled = true;
        }
        #region 复位操作
@@ -414,7 +450,7 @@
                Process_M071.Reset(null, null, null);
            }
            Process_M071.ResetTimer.Change(-1, 1000 * 5);
            Process_M071.ResetTimer.Change(1000 * 5, -1);
        }
        private void btnReset_MouseUp(object sender, MouseEventArgs e)