Thursday, September 03, 2009

Automatic detect COM Port List

This is for you (and for me, as my personal note :D) who are using Visual Basic 2008.

Get in touch with Serial Programming?
Maybe you are wondering how to detect list of communication port so that the user wouldn’t have to type it manually in the text box anymore.

Step 1:
Drag and drop Combo Box from Toolbox.
If you don't see your Toolbox panel, just press Ctrl+Alt+x, or go find it in View-Toolbox.
Go to the properties, and name it, such as "COMPortsBox".

Step 2:
Add these lines to the top of source code.
Imports System
Imports System.IO.Ports
Imports System.Threading.Thread


Step 3:
When load the main form, add these lines
  Private Sub MaxiTester_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  For Each COMString As String In My.Computer.Ports.SerialPortNames ' Load all available COM ports.
  COMPortsBox.Items.Add(COMString)
  Next
  End Sub


Ps: MaxiTester is the name of main form.

Last step:
Try to run it, and smile :)

Reference: here.

No comments: