I want to automatically find the COM port for a specific USB device. I use the VISA find resource function but I can't get the manufacturer's ID. VISA says the device doesn't have this information. The find resource function does narrow my search (and often finds the port depending on what other usb devices are connected). In the case where it finds multiple possible ports, can I safely send a message to each port to determine if it is the correct device? I know it will work for my purposes but I don't know if I am asking for trouble by sending messages to unidentified devices. Any thoughts on how I can identify my device port will be appreciated. Thank you - Dave F
This is how i see it...
Normally COM ports are used for RS232 type serial comms. A USB device will not normally have a COM port associated with it. The exception is USB to Serial adapters such as FTDI devices. In this case the FTDI driver can be set up to create a virtual COM port, which you should be able to connect to with VISA. You do need to have the right device driver installed though.
You can use a system profiler or device manager/ USBView etc to see how your system is seeing the USB devices plugged in to it. This will also give you the VID & PID, location etc. I too would avoid polling each device unless there is no other alternative! -dependent upon how robust the coding is on the devices it could be asking for problems...
Short answer is, you risk locking up a device if you send it a command (message) that it does not understand.
It has been my experience that virtual com ports are somethimes not reliable in "keeping thier place". In other words, upon one reboot, the device may be on COM4, next week it's on COM6. This often happens when you are continually connecting/unconnecting different stuff to the computer. So, watch out for that.
You can do it using WMI. I have C# code I am supposed to convert into LabVIEW foing something similar to what you want to do. In my case, I am testing a USB device and need to know which port on the hub is which COM port (the device creates a virtual COM port for communication). Using WMI, you can find the hardware path to the device and know that COM10 is USB hub Port 1 for example. Unfortunately, I cannot share the C# code.
You can download the WMI Code Creator tool from Microsoft, which should help you tremendously find the proper method of getting your info.
You basically want to look at all the W32_USB devices for the specific device you are looking for. Once you have that, you can look for the COM Port associated with it. I don't know when I will get to coding this up in LabVIEW, but will report back when I do, assuming you haven't found the solution by then.
I know this is an old thread...
But.. there is a solution, at least for FTDI devices:
Use the VI examples from FTDI... the D2XX driver allows you to get a list of all FTDI devices connected and you can get their COM port numbers.
The D2XX and VCP drivers are both installed with the CDM (combined driver model) btw.
Ok I will ask the same question.
Is it possible to Get the COM port number associated to a USB device with LabVIEW?
Is there any function that can help to do this in LabVIEW?
My device is a Numato USB GPIO 8. It use Microchip micro controller.
I already tried with registry key with VID & PID number to retrieve the com port with no success.
Anyone have an idea to achieve that?
I have this code in VB that do the trick:
Function FirstNumatoComPortFound FirstNumatoComPortFound = "Numato module not found" For Each objItem in GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Se
lect * from Win32_SerialPort") If instr(objItem.PNPDeviceID,"VID_04D8&PID_000A") <> 0 then FirstNumatoComPortFound = objItem.DeviceID Exit For End if Next End Function
But I need to translate it in LabVIEW, I can't figure out how to do it ?
Anyone have an idea?
Finally I found a solution with the VB script:
If that can help some one else
I get an error when trying your method above:: "Error 3005 occurred at Automation Open: Object specified is not creatable in Find COM Port.vi". I am new to using script control and vbs. Do I have to get something installed?
Hi there, my program states that initialization failed because system unable to communicate with motor. How do I check which com port my device is connect to? Many thanks!