Dim getcom As Integer
Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间,用SerialPort,获取计算机的有效串口
Dim port As String
For Each port In ports
Console.WriteLine(port)
Next port
ComboBox1.Items.Clear()
ComboBox1.Text = ""
For Each port In ports
ComboBox1.Items.Add(port) '向combobox中添加项
Next port
getcom = ComboBox1.Items.Count '读ComboBox1的数值
Dim comnum As Integer
Dim textcom As String
ComboBox1.Enabled = False
' Exit Sub
Dim mBaudRate As Integer
Dim mParity As IO.Ports.Parity
Dim mDataBit As Integer
Dim mStopbit As IO.Ports.StopBits
Dim mPortName As String = "COM1"
' Dim rxdata As String = RS232_Data(3)
Label1.Text = "通信未连接"
Label1.ForeColor = Color.Red
Dim textcompare As String = ""
If (Len(gl_string) > 4) Then
textcompare = Mid(gl_string, 1, 5)
End If
'ERROR OR OK+DISC
If ((textcompare = "ERROR") Or (textcompare = "OK+DI")) Then
Label1.Text = "通信已连接"
Label1.ForeColor = Color.Green
setrxnum = 4
End If
' If (RS232.BytesToRead >= 5) Then
'setrxnum = 8 '打开串口自动读取
' Exit For
' End If
If RS232.IsOpen = True Then '尚未开启
RS232.Close() '开启通讯端口
End If