1
Support Questions / Re: How to add a serial port selection dropdown or menu
« on: November 02, 2022, 09:06:37 AM »
You could try this.
Private Sub SerialPort1_ErrorReceived(sender As Object, e As SerialErrorReceivedEventArgs) Handles SerialPort1.ErrorReceived
Try
SerialPort1.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles BtnConnect.Click
Try
'Remove all the Items in the ComboBox
For i As Integer = 0 To ComboBox1.Items.Count - 1
ComboBox1.Items.RemoveAt(i)
Next
'Add all the live comports back to the comboBox
For Each sp As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(sp)
Next
Try
'Re Open the com port
SerialPort1.Open()
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub
Private Sub SerialPort1_ErrorReceived(sender As Object, e As SerialErrorReceivedEventArgs) Handles SerialPort1.ErrorReceived
Try
SerialPort1.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles BtnConnect.Click
Try
'Remove all the Items in the ComboBox
For i As Integer = 0 To ComboBox1.Items.Count - 1
ComboBox1.Items.RemoveAt(i)
Next
'Add all the live comports back to the comboBox
For Each sp As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(sp)
Next
Try
'Re Open the com port
SerialPort1.Open()
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub