private void Safesystem1_Load(object sender, EventArgs e) { this.BackColor = Color.Transparent; if (WMIFunc.GetSerialPort(PortName) != "") { SerialPortOpen(); timer1.Enabled = true; } }
public void SerialPortOpen() { comm.BaudRate = 9600; comm.PortName = WMIFunc.GetSerialPort(PortName); try { comm.Open(); } catch { //捕获到异常信息,创建一个新的comm对象,之前的不能用了。 comm = new SerialPort(); } }