I like my apps to be able to auto-connect to USB serial converters without the user having to select a COM port. In order to do this, I need to
Iterate over USB devices looking for VID/PID match (I can do this with MBS).
Look for “COM” in the device’s FriendlyName (cannot do with MBS).
Iterate over System.SerialPort() looking for a match with the FriendlyName.
Call SerialConnection.Connect on the index of the matching SerialPort.
I do this now with a collection of DLLs published by Chris Carter long ago
and it works OK but it’s 32-bit only. I would like to modernize and streamline using MBS but the lack of the FriendlyName property prevents me from doing so.
WindowsSerialPortsMBS would be perfect, except that there seems to be a bug: when I pass False to the constructor for OnlyPresent I get no devices, even though one is definitely present and connected:
When I pass True to the constructor I get a bunch of stale registry entries as expected, and no way to tell which are present and which are not.
With WindowsDevicesMBS I can get the Friendly Name and Manufacturer and only currently-present devices, but no PID info.
I could conceivably use WindowsDevices to find candidate ports that are present, and then do a second pass using WindowsSerialPorts to filter on PID.
But if “OnlyPresent” worked correctly with WindowsSerialPorts, it would be sufficient on its own and I wouldn’t need to use WindowsDevicesMBS.
Well, the WindowsSerialPortMBS class queries the install database from Windows to find the COM ports. For me it finds the virtual port I created. For an USB device, the Device path may have VID and PID included.
The WindowsDeviceMBS class searches the same database, but for all kinds of devices. You should find the port there, too. Pick up the physical device name.
You may need to check the WMI query classes. Maybe do there a search for USB devices, for Serial Ports and maybe find something to match between both.
Even when you instantiate it with “OnlyPresent” = True? For me it finds my port (and others not present) if this is False, but it does not find any ports if it’s True.
Yes, but it does not report VID/PID. For VID/PID I have to use WindowsSerialPorts.
It turns out that WindowsDeviceMBS does in fact provide VID & PID info, in the DeviceID property, e.g. “FTDIBUS\VID_0403+PID_6001”
I just hadn’t noticed because it’s not included in the information displayed by the example app and the documentation just says “here you have the ID string for this device”.