c#串口自动扫描程序

xiaoxiao2021-02-28  71

加入一个定时器控件,双击定时器控件,加入以下代码,就可以实现串口自动扫描功能     private void timer1_Tick(object sender, EventArgs e)        {              string[] t = SerialPort.GetPortNames();             if (cc != t.Length)             {                 comboBox1.Items.Clear();             }              cc = t.Length;                       if (!serialPort1.IsOpen)             {                 foreach (string com in SerialPort.GetPortNames())                 {                     if (comboBox1.Items.Count < cc)                         comboBox1.Items.Add(com);                 }             }         }

纯原创   转载请注明出处

转载请注明原文地址: https://www.6miu.com/read-56782.html

最新回复(0)