1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/// <summary> /// 检查当前串口是否可用 /// </summary> /// <param name="strSerialNo">串口号</param> /// <returns></returns> public bool CheckPort(string strSerialNo) { try { SerialPort _sp = new SerialPort(strSerialNo, 9600, Parity.None, 8, StopBits.One); _sp.Open(); if (_sp != null) { _sp.Close(); _sp = null; } return true; } catch { MessageBox.Show("当前串口已被占用,请切换串口", "警告提示"); return false; } } |