05-23-2025 05:28 AM
Our systems have several COM ports. There is always one of them connnect to an FTDI chip. I want to automatically obtain that specific COM port number.
At the moment I use a wmic command using the command prompt:
wmic path Win32_PnPEntity where "Name like '%(COM%)' and PNPDeviceID like '%VID_%'" get Name, PNPDeviceID
It returns something like this:
Name PNPDeviceID
USB Serial Device (COM14) USB\VID_2886&PID_802F&MI_00\7&1A14DB68&0&0000
USB Serial Port (COM8) FTDIBUS\VID_0403+PID_6001+A5069RR4A\0000
Unfortunately, wmic is being depecated.
So I'm looking into alternatives. I know I can use VISA Find Resources, but I have found it to be unreliable (it sometimes get stuck on this VI, using task manager to kill LabVIEW as the only way out), and it doesn't provide any way to the get the manufacturer name using VISA properties as far as I have found.
wmic is being replaced by WMI, which runs in powershell. You can run powershell commands in the command prompt:
powershell -NoProfile -Command "Get-PnpDevice -PresentOnly | Where-Object { $_.InstanceId -like '*VID_*' -and $_.FriendlyName -like '*(COM*)' } | Select-Object FriendlyName, InstanceId"
But it is very slow, >1 second.
Is there any LabVIEW native way to achieve my goal?
Solved! Go to Solution.
05-23-2025 06:03 AM
Never mind, I posted too fast and I figured it out. You can use WMI using .net functions. I'll leave my quick prototype here in case anyone is interested.