Find Com Port

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 14
Reputation: Tony Barber is an unknown quantity at this point 
Solved Threads: 0
Tony Barber Tony Barber is offline Offline
Newbie Poster

Find Com Port

 
0
  #1
Jul 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 143
Reputation: cutepinkbunnies is an unknown quantity at this point 
Solved Threads: 8
cutepinkbunnies's Avatar
cutepinkbunnies cutepinkbunnies is offline Offline
Junior Poster

Re: Find Com Port

 
0
  #2
Aug 1st, 2008
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.
Last edited by cutepinkbunnies; Aug 1st, 2008 at 12:16 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 14
Reputation: Tony Barber is an unknown quantity at this point 
Solved Threads: 0
Tony Barber Tony Barber is offline Offline
Newbie Poster

Re: Find Com Port

 
0
  #3
Aug 1st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 14
Reputation: Tony Barber is an unknown quantity at this point 
Solved Threads: 0
Tony Barber Tony Barber is offline Offline
Newbie Poster

Re: Find Com Port

 
0
  #4
Aug 1st, 2008
Hello all,
I have found the solution to my problem and here is the code for it.
List the com ports on the computer.

  1. Imports System
  2. Imports System.IO.Ports
  3. Imports System.Threading
  4.  
  5.  
  6. Public Class frmMain
  7.  
  8. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  9.  
  10. ' Get a list of serial port names.
  11. Dim ports As String() = SerialPort.GetPortNames()
  12. ' Show a label with Action information on it
  13. lblComFound.Text = "The following serial ports were found:"
  14.  
  15. ' Put each port name Into a comboBox control.
  16. Dim port As String
  17. For Each port In ports
  18. cmbo1.Items.Add(port)
  19.  
  20. Next port
  21. ' Select the first item in the combo control
  22. cmbo1.SelectedIndex = 0
  23.  
  24. End Sub
  25.  
  26.  
  27. End Class

Best regards,
Tony
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC