Identifying specific USB devices

I have the vendor id and product id of a specific usb device I’m looking to open a serial connection to. I know the device will support the connection. What I need to do is create a list of only the paths for this particular class of device. There could be more than one of the same device connected.

The current code just does

Var DeviceBound As Integer = SerialDevice.Count - 1
For Idx As Integer = 0 To DeviceBound
  Var Device As SerialDevice = SerialDevice.At(Idx)
  // Do stuff
Next Idx

But this of course shows me all devices without a way for me to determine which of them are for the device I’m looking for. On Mac this has been solved with IORegistry. On Windows, I don’t really know where to begin. MBS plugins are an option. Anybody have any ideas?

I just dug my barcode scanner out and threw this together, let me know if you don’t want to go via a shell and powershall and I’ll see what I can do, it returns COM5 in a string which you can use with your code above.

Dim sh As New shell
sh.TimeOut = -1
sh.ExecuteMode = shell.ExecuteModes.Synchronous
sh.Execute("powershell (Get-WmiObject -Class Win32_SerialPort -Filter \""PNPDeviceID='USB\\VID_080C&PID_0400\\S/N_E10D05648'\"").DeviceID")
system.DebugLog(sh.Result)

Yeah unfortunately, as far as I’m aware, PowerShell isn’t generally available enough. Thank you though.

Then there’s wmic, but you’ll need to cut the com port out of the ()'s

wmic path win32_pnpentity where PNPDeviceID="USB\\VID_080C&PID_0400\\S/N_E10D05648" get Name /format:csv

or the registry (not 100% on this one as I just did a registry search for the vendor id and found it, not read into it much, seems like a cache of assigned ports)

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\COM Name Arbiter\Devices

Just a note that future wmic may run into problems

Ah ok, powershell is the replacement then, good to know, thanks Brian

1 Like