LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find all serial ports on PC

We have a laptop which has connected to it a powered 4-port StarTech USB hub.

These USB ports generally show up as COM21 to COM24 but not always. 

We have instruments connected to these ports that we can query.

 

The brute force way is to start at COM3 and go through COM30.

 

But is there a more efficient way of finding all the serial ports such as reading Windows registry etc?

 

 

0 Kudos
Message 1 of 16
(10,501 Views)

You can use Find VISA Resource to very quickly narrow down the list.  You can then do some quick communication on each one to see what is connected to which port.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 16
(10,481 Views)

Keep in mind that if you plug that 4 port hub into a different USB port, the COM numbers may be different.  I don't know if that is always the case but I've had it happen to me before.

aputman
0 Kudos
Message 3 of 16
(10,400 Views)

@aputman wrote:

Keep in mind that if you plug that 4 port hub into a different USB port, the COM numbers may be different.  I don't know if that is always the case but I've had it happen to me before.


One reason of many that I try to avoid USB instruments with automated test setups.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 16
(10,395 Views)

@aputman wrote:

Keep in mind that if you plug that 4 port hub into a different USB port, the COM numbers may be different.  I don't know if that is always the case but I've had it happen to me before.


I have found that modern version of Windows (7+) remember the UUID of the USB device and always give the same USB device the same Com port.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 16
(10,384 Views)

@RTSLVU wrote:

@aputman wrote:

Keep in mind that if you plug that 4 port hub into a different USB port, the COM numbers may be different.  I don't know if that is always the case but I've had it happen to me before.


I have found that modern version of Windows (7+) remember the UUID of the USB device and always give the same USB device the same Com port.


I am running Windows 7 and still run into the issue.  I literally just moved a USB-Serial adapter from port 3 to port 1 on my USB hub and all of my ports were changed.  So still keep that warning in the back of your mind.  This is also why I say to make sure you have some way to make sure you have the right device at the port (ID querry, etc.).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 16
(10,372 Views)

@billko wrote:

@aputman wrote:

Keep in mind that if you plug that 4 port hub into a different USB port, the COM numbers may be different.  I don't know if that is always the case but I've had it happen to me before.


One reason of many that I try to avoid USB instruments with automated test setups.


I avoid USB like the bloody plague.  Unfortunately, the units I am testing use USB.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(10,371 Views)

This problem has nothing to do with Windows 7 versus 10 versus any other OS.  what I mean is that while the OS may choose to implement things differently, the underlying problem is a USB problem, not an OS problem.

 

Within the USB Specification, part of the device descriptor (which each device MUST have, otherwise the device won't enumerate) there is an entry for a serial number.  There are no rules enforced as to the contents of this serial number.  Some manufacturers are nice people and guarantee that each device they manufacture has a unique serial number so that the OS interfacing witht he device can uniquely identify it.  These devices tend to retain their COM Port numbers when removing and re-adding them.

 

Other manufacturers like to see developers in pain and will not even bother to implement a serial number properly.  When the OS sees this device, it has no way of knowing whether it's the same device as perviously or whether it's another isntance of the same type of decive and as such has absolutely no way of knowing which COM Ports to assign it.

 

This is the root cause of the problem.  Some OSs make things even more weird by attributing the enumeration of the USB port address (which controller, which port and so on) into the unique identifier of the device.  This can lead to the same device with a valid serial number to be enumerated as a completely new device if it is connected to a different port.  This is an OS problem.

 

So if you want to minimise the headache associated with USB, make sure that the devices you are using have valid entries for the device serial number as included in the device descriptor.  Here is a random like I have not tested to get the USB descriptor of your device.  Linux probably has a load of really robust tools for this.

0 Kudos
Message 8 of 16
(10,346 Views)

I made the attached .v. once I had the same issues.

Maybe You can use it.

It scans the windows registry for connected ports.

 

/B

Don't forget to rate a good Answer....
---------------------------------------------------------
Here should be some cool signature

But there's NOT

LabVIEW 2012-2017
---------------------------------------------------------
0 Kudos
Message 9 of 16
(10,337 Views)

Hi BCL,

 

your VI only works for your specific case…

 

For me I had to change the key name to "\Device\VCP0" instead of "..\Serial0". And ofcourse my VCP isn't named "Prolific"…

 

Btw. you should change your signature when you use LV2017 nowadays!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 16
(10,328 Views)