public void UserControl_portShow_Load() { if (tag_Work == null || tag_Work.tag_JSerialPort == null) { return; } PortShowControl_Load(null, null); if (tag_Work == null || tag_Work.tag_JSerialPort == null) { } else { foreach (Button butt in tag_List) { JSerialPort jsp = (JSerialPort)butt.Tag; if (jsp.tag_SerialPort != null && jsp.tag_SerialPort.IsOpen) { butt.Text = jsp.tag_PortParameter.tag_name + "已开"; butt.BackColor = Color.Green; } else { butt.Text = jsp.tag_PortParameter.tag_name + "未开"; butt.BackColor = Color.Yellow; } } } if (tag_Work == null || tag_Work.tag_SocketClient == null) { } else { foreach (Button butt in tag_SocketList) { SocketClient jsp = (SocketClient)butt.Tag; if (jsp.tag_Socket != null && jsp.tag_Socket.Connected) { butt.Text = jsp.tag_IPConfig.tag_name + "已连接"; butt.BackColor = Color.Green; } else { butt.Text = jsp.tag_IPConfig.tag_name + "未连接"; butt.BackColor = Color.Yellow; } } } }
private void OutputBT_Click(object sender, EventArgs e) { Button butt = (Button)sender; JSerialPort jsp = (JSerialPort)butt.Tag; if (jsp.tag_SerialPort != null && jsp.tag_SerialPort.IsOpen) { jsp.tag_SerialPort.Close(); } else { jsp.open(); } }