Hi,
I am connecting a scanner to a USB port.
The scanner works as a com port connection.
Before I can talk to the scanner I need to know which com port the scanner is using.
When I know which com port it is on I can wake it up and ask it if it is ready.
What code could I use to find out what com ports are being used on the computer.
I can see this information in System-Hardware but I need to do it programmaticaly
I think VB.net has a method to do this, am I right?
Many thanks for any help here.
Best Regards,
Tony

Recommended Answers

All 3 Replies

I'm not sure what you're talking about doing exactly, but when I talked to Integrated Circuits via the Serial Port I used the System.IO.Ports Namespace.

Check the "Base Class Libraries - Group 2 Samples" section on the here for hardware/port samples. That is where I started when looking for code dealing with the serial port, hopefully you can find something pertinant in there.

Good luck and let us know how it works out!

EDIT: The Using serial ports with the new Port class sample should have some code in there that enumerates the com ports.

Hi CutepinkBunnies,
Many thanks for your help, that looks very interesting.
I have now solved the problem and will post the solution.
Once again - Thanks.
Best regards,
Tony

Hello all,
I have found the solution to my problem and here is the code for it.
List the com ports on the computer.

Imports System
Imports System.IO.Ports
Imports System.Threading


Public Class frmMain

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Get a list of serial port names.
        Dim ports As String() = SerialPort.GetPortNames()
        ' Show a label with Action information on it
        lblComFound.Text = "The following serial ports were found:"

        ' Put each port name Into a comboBox control.
        Dim port As String
        For Each port In ports
            cmbo1.Items.Add(port)
          
        Next port
        ' Select the first item in the combo control
        cmbo1.SelectedIndex = 0

    End Sub

 
End Class

Best regards,
Tony

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.