05-28-2020 11:17 AM
A nice simple question for you guys and girls. Is there anyway to programatically find devices that are plugged in through usb without having to hard code the com ports that they are usually in?
Solved! Go to Solution.
05-28-2020 11:48 AM
Here is a little system that will find all of the connected drives on your computer. You can look for removable types and get a list. You could then look at serial number to get the connection that you want. I did not write this code. I got it from someone here on the forum a long time ago. It does still work. I made some code using this. The code finds the first removable drive for a system so I could synchronize the data to a thumb drive.You will even see references to Windows NT in the vi's if that tells you how old this is.
05-28-2020 12:29 PM - edited 05-28-2020 12:31 PM
@crash_override wrote:
A nice simple question for you guys and girls. Is there anyway to programatically find devices that are plugged in through usb without having to hard code the com ports that they are usually in?
Assuming they show up as serial COM ports, you can use this code from my library.

The goal of this code was to detect when a new port showed up. That is the point of the top half of the filter loop.
05-28-2020 12:43 PM
I can interpret this question a couple ways. The first interpretation would be "Can I show the user a dropdown of all currently connected COM ports"; the answer is Yes, using either crossrulz's suggestion to programmatically find them, or right click a VISA control and select "I/O Name Filtering".
The second way, and the way I assume you actually intend, is "Can I have my system recognize my device automatically without requiring the user to specify which COM port it's connected to?"
The answer to that is yes, sort of. You cannot automatically detect a given device. For example, if you connect a power supply to a USB port and it shows up as COM3, it might show up as COM4 tomorrow on a different USB port. It might not, but that's a Windows decision, not a LabVIEW one. The most straightforward way to do this is to use crossrulz' method to programmatically get a list of COM ports, then ask each one to identify themselves. Many devices that comply with SCPI commands will respond to a *IDN? command with some identifier string, which you can use to determine the instrument (see this article for a little more info). Unfortunately, lots of things aren't SCPI-compliant, so you will need to get with the manufacturer of the device to see if it has a command you can use to ask the device what its name is. You can then match up each COM port to the device it is talking to, but this isn't automatic- you have to do it yourself. This should work for nearly all devices unless they don't support unique identifiers, and it's a bit of a pain as you have to actually talk to each device, which means configuring the serial port to match each device's specifications and manually enumerate the entire list.
I believe there is a third way that involves using property nodes to determine the VID or PID of the USB to Serial converter (if it uses one... GPIB devices or devices with actual serial ports don't!). That method might get you a unique serial number or identifier you can use to query the instrument without doing actual serial communications with it, but it's not a universal solution.
09-16-2020 12:09 PM
Hi there, I have two different USB test devices (all have FTDI driver) that I'm trying to identify in LabVIEW2019. I've tried *IDN? the command and it didn't work. I've tried the VISA property nodes but all the available ones return exactly the same information. On Device Manager, I can see they have different PID. Is anyone able to read VID&PID out using VISA property nodes? Or, the question can be: If I know the COM port of the device, how do I read out the hardware ids in LabVIEW? If anyone can help me out, I'd really appreciate it.
09-16-2020 09:46 PM
You do realize that "*IDN?" is a command from a very specific instrument programming language? How do you even know these unspecified devices are even SCPI-compliant?
What does "didn't work" mean?
I think you have to get very much more specific before we can offer any advice.
09-17-2020 04:13 AM - edited 09-17-2020 04:23 AM
You can query all (USB) devices with this nifty powershell command:
This is only the tip of the iceberg.
I've used it to get a list of connected camera's:
powershell.exe Get-CimInstance Win32_PnPEntity | where CompatibleID -match 'USB\\Class_0e&SubClass_03'
See Get-CimInstance.
A typical (truncated) output from my PC:
Caption : USB Composite Device
Description : USB Composite Device
InstallDate :
Name : USB Composite Device
Status : OK
Availability :
ConfigManagerErrorCode : 0
ConfigManagerUserConfig : False
CreationClassName : Win32_PnPEntity
DeviceID : USB\VID_046D&PID_C31C\5&16B2CD1E&0&1
ErrorCleared :
ErrorDescription :
LastErrorCode :
PNPDeviceID : USB\VID_046D&PID_C31C\5&16B2CD1E&0&1
PowerManagementCapabilities :
PowerManagementSupported :
StatusInfo :
SystemCreationClassName : Win32_ComputerSystem
SystemName : MYPC
ClassGuid : {36fc9e60-c465-11cf-8056-444553540000}
CompatibleID : {USB\DevClass_00&SubClass_00&Prot_00, USB\DevClass_00&SubClass_00, USB\DevClass_00,
USB\COMPOSITE}
HardwareID : {USB\VID_046D&PID_C31C&REV_6400, USB\VID_046D&PID_C31C}
Manufacturer : (Standard USB Host Controller)
PNPClass : USB
Present : True
Service : usbccgp
PSComputerName :
Caption : USB Composite Device
Description : USB Composite Device
InstallDate :
Name : USB Composite Device
Status : OK
Availability :
ConfigManagerErrorCode : 0
ConfigManagerUserConfig : False
CreationClassName : Win32_PnPEntity
DeviceID : USB\VID_04F2&PID_B446\5&16B2CD1E&0&6
ErrorCleared :
ErrorDescription :
LastErrorCode :
PNPDeviceID : USB\VID_04F2&PID_B446\5&16B2CD1E&0&6
PowerManagementCapabilities :
PowerManagementSupported :
StatusInfo :
SystemCreationClassName : Win32_ComputerSystem
SystemName : MYPC
ClassGuid : {36fc9e60-c465-11cf-8056-444553540000}
CompatibleID : {USB\DevClass_00&SubClass_00&Prot_00, USB\DevClass_00&SubClass_00, USB\DevClass_00,
USB\COMPOSITE}
HardwareID : {USB\VID_04F2&PID_B446&REV_2708, USB\VID_04F2&PID_B446}
Manufacturer : (Standard USB Host Controller)
PNPClass : USB
Present : True
Service : usbccgp
PSComputerName :