using CleanMachine.Model.BAS; using CleanMachineHMI.Domain.Enums; using CleanMachineHMI.Utils; using Krypton.Toolkit; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CleanMachineHMI.FrmUserControl { [FormType(EnumFormType.MechineCheck)] public partial class frmMechineCheck : UserControl { public frmMechineCheck() { InitializeComponent(); } //注销退出 private void kryptonButton1_Click(object sender, EventArgs e) { Global.LoginForm.Show(); //GlobalHelper.MainForm.Hide(); Global.MainFormNew.Hide(); } private void swtbtn_brush1_LSwitched(object sender, LEventArgs e) { try { if (!PlcOperationHelper.Instance.isConn) { KryptonMessageBox.Show("The PLC is disconnected and unable to operate the equipment."); swtbtn_brush1.L_IsOpen = false; return; } //选中状态,并且跟当前状态有差别则发送选中状态 if (swtbtn_brush1.L_IsOpen) { PlcOperationHelper.Instance.WritePlcItem("Hairbrush1Selection", "True", PlcItemTypeDesc.M); } else { PlcOperationHelper.Instance.WritePlcItem("Hairbrush1Selection", "False", PlcItemTypeDesc.M); } } catch (Exception) { } } private void swtbtn_brush2_LSwitched(object sender, LEventArgs e) { try { if (!PlcOperationHelper.Instance.isConn) { KryptonMessageBox.Show("The PLC is disconnected and unable to operate the equipment."); swtbtn_brush2.L_IsOpen = false; return; } //选中状态,并且跟当前状态有差别则发送选中状态 if (swtbtn_brush2.L_IsOpen) { PlcOperationHelper.Instance.WritePlcItem("Hairbrush2Selection", "True", PlcItemTypeDesc.M); } else { PlcOperationHelper.Instance.WritePlcItem("Hairbrush2Selection", "False", PlcItemTypeDesc.M); } } catch (Exception) { } } private void cbt_ResetSys_MouseDown(object sender, MouseEventArgs e) { try { if (!Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("ResetSys", PlcItemTypeDesc.M))) { PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M); } } catch (Exception) { } } private void cbt_ResetSys_MouseUp(object sender, MouseEventArgs e) { try { PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M); } catch (Exception) { } } //初始化,同步内存监控点状态 private void frmMechineCheck_Load(object sender, EventArgs e) { this.SetFormControlText(); Thread th1 = new Thread(MainDtlRunTh); th1.IsBackground = true; th1.Start(); //毛刷1运行状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush1Selection", PlcItemTypeDesc.M))) { swtbtn_brush1.L_IsOpen = true; } else { swtbtn_brush1.L_IsOpen = false; } if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush2Selection", PlcItemTypeDesc.M))) { swtbtn_brush2.L_IsOpen = true; } else { swtbtn_brush2.L_IsOpen = false; } //毛刷3启用状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush3Selection", PlcItemTypeDesc.M))) { swtbtn_brush3.L_IsOpen = true; } else { swtbtn_brush3.L_IsOpen = false; } } //同步运行状态 private void MainDtlRunTh() { while (Global.SysThIsRunFlag) { try { //系统运行状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("SelfCheckFlag", PlcItemTypeDesc.M))) { Invoke(new Action(() => { cbt_RunStatusTran.BackColor = Color.Lime; })); } else { Invoke(new Action(() => { cbt_RunStatusTran.BackColor = Color.Gray; })); } //毛刷1运行状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush1Selection", PlcItemTypeDesc.M))) { Invoke(new Action(() => { cbt_Brush1StatusTran.BackColor = Color.Lime; })); } else { Invoke(new Action(() => { cbt_Brush1StatusTran.BackColor = Color.Gray; })); } //毛刷2启用状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush2Selection", PlcItemTypeDesc.M))) { Invoke(new Action(() => { cbt_Brush2StatusTran.BackColor = Color.Lime; })); } else { Invoke(new Action(() => { cbt_Brush2StatusTran.BackColor = Color.Gray; })); } //毛刷3启用状态 if (Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("Hairbrush3Selection", PlcItemTypeDesc.M))) { Invoke(new Action(() => { cbt_Brush3StatusTran.BackColor = Color.Lime; })); } else { Invoke(new Action(() => { cbt_Brush3StatusTran.BackColor = Color.Gray; })); } if (Global.CanOperate) { break; } } catch { } Thread.Sleep(50); } } private void kbtn_Pass_Yes_Click(object sender, EventArgs e) { try { //自检结束后发送停止检测信号 PlcOperationHelper.Instance.WritePlcItem("SelfCheckFlag", "False", PlcItemTypeDesc.M); //自检通过后,发送检测通过信号 PlcOperationHelper.Instance.WritePlcItem("SelfCheckPassFlag", "True", PlcItemTypeDesc.M); //系统默认进入自动模式 PlcOperationHelper.Instance.WritePlcItem("ManualOrAuto", "False", PlcItemTypeDesc.M); //GlobalHelper.MainForm.navigatorMain.SetNavPage(Domain.Enums.EnumFormType.MainDetail); frmMainNew.SwitchFrmMenu(EnumFormType.MainDetail, true); //frmMainNew.SwitchFrmMenu(EnumFormType.IoMonitor, false); Global.CanOperate = true; } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } } private void kbtn_Pass_No_Click(object sender, EventArgs e) { try { //自检结束后发送停止检测信号 PlcOperationHelper.Instance.WritePlcItem("SelfCheckFlag", "False", PlcItemTypeDesc.M); //自检通过后,发送检测通过信号 PlcOperationHelper.Instance.WritePlcItem("SelfCheckPassFlag", "False", PlcItemTypeDesc.M); //测试未通过,请检查并重新测试 Global.CanOperate = false; KryptonMessageBox.Show(this.T("测试未通过,请检查设备并重新测试!!", "NoPassShowMsg")); } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } } private void cbt_StartTran_Click_1(object sender, EventArgs e) { try { if (swtbtn_brush1.L_IsOpen || swtbtn_brush2.L_IsOpen || swtbtn_brush3.L_IsOpen) { if (!Convert.ToBoolean(PlcOperationHelper.Instance.ReadPlcItem("SelfCheckFlag", PlcItemTypeDesc.M))) { PlcOperationHelper.Instance.WritePlcItem("SelfCheckFlag", "True", PlcItemTypeDesc.M); } else { KryptonMessageBox.Show("Press Yes or No First !"); } } else { KryptonMessageBox.Show("Brush Need to be Selected First!"); } } catch (Exception) { } } private void swtbtn_brush3_LSwitched(object sender, LEventArgs e) { try { if (!PlcOperationHelper.Instance.isConn) { KryptonMessageBox.Show("The PLC is disconnected and unable to operate the equipment."); swtbtn_brush3.L_IsOpen = false; return; } //选中状态,并且跟当前状态有差别则发送选中状态 if (swtbtn_brush3.L_IsOpen) { PlcOperationHelper.Instance.WritePlcItem("Hairbrush3Selection", "True", PlcItemTypeDesc.M); } else { PlcOperationHelper.Instance.WritePlcItem("Hairbrush3Selection", "False", PlcItemTypeDesc.M); } } catch (Exception) { } } } }