Dim c1 As String
Dim cms() As String = {"COM1","COM2","COM3","COM4"}
For Each c As String In cms
Ports.Add(c)
For Each sp As String In Ports.PortNames
If sp =c Then
c1 =c
Exit For
End If
Next
If c1 > "" Then Exit For
Next
If c1 > ""
With Ports(c1)
.Close()
.Parity = Parity.None
.Handshake = Handshake.None
.StopBits = StopBits.One
.BaudRate = 2400
.DataBits = 8
.ReadBufferSize() = 2048
.WriteBufferSize() = 2048
.Open
End With
else
messagebox.show("没有串口")
End If