| | |
| | | await Task.Delay(300); |
| | | |
| | | cvImage.SetScreenSize(); |
| | | cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle; |
| | | cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle; |
| | | }; |
| | | } |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath); |
| | | cvImage.LoadImage(image); |
| | | cvImage.SetScreenSize(); |
| | | 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(); |
| | | |
| | | txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked; |
| | | |
| | | 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); |
| | | }); |
| | | })); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(new LogMsg(DateTime.Now, "载入背景图异常", ex.Message)); |
| | | return; |
| | | } |
| | | |
| | | 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); |
| | | }); |
| | | |
| | | if (txtBarcode.IsHandleCreated) |
| | | txtBarcode.BeginInvoke(new Action(() => txtBarcode.ReadOnly = Config.IsBarcodeManulInputBlocked)); |
| | | |
| | | Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode; |
| | | Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode; |
| | |
| | | |
| | | Process_M071.OnFullResetDone -= Process_M071_FullResetDone; |
| | | Process_M071.OnFullResetDone += Process_M071_FullResetDone; |
| | | |
| | | 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) |
| | | { |
| | | txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked; |
| | | } |
| | | |
| | | #region 图片区右键菜单 |
| | |
| | | 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 |
| | | |
| | | #region 标签编辑区 |
| | | private async void CvImage_OnElementChangedHandle(Common.Interface.IShapeElement ele) |
| | | { |
| | | this.Invoke(new Action(() => |
| | | { |
| | | if (ele is KeyIndicator indicator) |
| | | { |
| | | if (indicator.State == ElementState.Selected) |
| | | { |
| | | foreach (ListViewItem item in lvMeasures.Items) |
| | | { |
| | | if (item.Tag.ToString() == indicator.ID) |
| | | { |
| | | item.Selected = true; |
| | | |
| | | lvMeasures.EnsureVisible(item.Index); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | })); |
| | | |
| | | await Task.Delay(100); |
| | | } |
| | | |
| | | private void lvMeasures_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (lvMeasures.SelectedItems.Count <= 0) |
| | | return; |
| | | |
| | | foreach (ListViewItem item in lvMeasures.Items) |
| | | { |
| | | item.BackColor = SystemColors.Control; |
| | | } |
| | | |
| | | foreach (ListViewItem item in lvMeasures.SelectedItems) |
| | | { |
| | | item.BackColor = Color.Orange; |
| | | } |
| | | |
| | | var ele = cvImage.Elements.FirstOrDefault(u => u.ID == lvMeasures.SelectedItems[0].Tag.ToString()); |
| | | propGridKeyIndicator.SelectedObject = ele; |
| | |
| | | if (lvMeasures.SelectedItems.Count <= 0) |
| | | return; |
| | | |
| | | cvImage.Elements.ToList().ForEach(u => u.State = ElementState.Normal); |
| | | var ele = cvImage.Elements.FirstOrDefault(u => u.ID == lvMeasures.SelectedItems[0].Tag.ToString()); |
| | | if (ele != null) |
| | | { |
| | | ele.State = ElementState.Selected; |
| | | cvImage.Invalidate(); |
| | | //cvImage.Invalidate(); |
| | | } |
| | | } |
| | | #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 机台状态 |
| | | 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.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.Running: |
| | | btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; |
| | | btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen; |
| | | lblMachineState.Text = "运行"; |
| | | 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 = true; |
| | | break; |
| | | case MachineState.Unknown: |
| | | btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control; |
| | | btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText; |
| | | lblMachineState.Text = "未知"; |
| | | break; |
| | | } |
| | | })); |
| | | btnStartMeasure.Enabled = false; |
| | | break; |
| | | } |
| | | })); |
| | | } |
| | | |
| | | await Task.Delay(100); |
| | | } |
| | |
| | | lblProductionState.Text = "NG"; |
| | | } |
| | | |
| | | btnStartMeasure.Text = "开始测量"; |
| | | //btnStartMeasure.Text = "开始测量"; |
| | | })); |
| | | await Task.Delay(100); |
| | | } |
| | |
| | | lblProductionState.Text = "测试中"; |
| | | |
| | | lblCT.Text = ""; |
| | | |
| | | cvImage.Elements.ToList().ForEach(e => |
| | | { |
| | | if (e is KeyIndicator indicator) |
| | | { |
| | | indicator.Text = ""; |
| | | indicator.ResultState = null; |
| | | } |
| | | }); |
| | | })); |
| | | await Task.Delay(100); |
| | | } |
| | |
| | | |
| | | private async void btnStartMeasure_Click(object sender, EventArgs e) |
| | | { |
| | | btnStartMeasure.Enabled = false; |
| | | bool isBreak = false; |
| | | |
| | | if (btnStartMeasure.Text == "开始测量") |
| | | { |
| | | await Task.Run(() => |
| | |
| | | } |
| | | 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 复位操作 |
| | |
| | | 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) |
| | |
| | | Process_M071.ResetTimer.Change(-1, -1); |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | | } |