How to program automatic detect serial port in vb.net
04:42 03 Mar 2013

I am working on a project where RS232 is connected via USB port of laptop / PC. I already created the vb.net application. As the application loads for the first time, it needs to detect the serial port. As of now, I manually put the portname in the properties of the serialport but if I deploy my application and if I use other laptop / PC, there would be an error: System.IO.IOException as I run my GUI. I want to program the automatic detect of serialport but I am new to serial port programming in vb.net.

Can anyone help me? thanks!

This is some part of my program:

Imports System.IO.Ports

Public Class Form1

'Dim myPort As Array 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try

        'myPort = IO.Ports.SerialPort.GetPortNames() 

        SerialPort1.Open()
        Timer1.Enabled = True
    Catch ex As Exception
        MsgBox(ex.ToString)

    End Try
End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    '==zigbee sent data to the app====
    Console.Beep(3000, 1000) 'high tone buzzer whenever there is a notification received

    MsgBox("THERE IS A NOTIFICATION RECEIVED!")

    uart_rx = Me.SerialPort1.ReadExisting
    toDisplay = toDisplay + uart_rx

    flag = 1 'there is a notification sent


End Sub

....

After myPort = IO.Ports.SerialPort.GetPortNames() , I don't know what to do next.

vb.net serial-port