Is the list of SerialPorts requests using WMI different from the devicemanager?

I have the following serial ports listed in my devicemanager:

  • COM3
  • COM4 (BT)
  • COM5 (BT)
  • COM6 (GlobeTrotter MO67xx - Control Interface)
  • COM7 (GlobeTrotter MO67xx - GPS control interface)
  • COM8 (GlobeTrotter MO67xx - GPS data interface)
  • COM9 (GlobeTrotter MO67xx - Diagnostic Interface)
  • COM11 (USB Serial Port)
  • COM12 (USB Serial Port)
  • COM45 (SUNIX COM Port)
  • COM46 (SUNIX COM Port)

The SUNIX COM port is connected via an internal PCI card. USB Serial Port Connected via USB (FDTI-chip) GlobeTrotter Ports - This is a GlobeTrotter device connected via USB. There is a modem, a USB device, and a network device for this modem.

So, I have several different sources of serial ports.

All I want to do is get a list containing all of these ports using WMI.

For my tests I use WMI Code Creator

Test 1:

root\CIMV2 ; Query: SELECT * FROM Win32_SerialPort returns only the following serial ports:

  • COM3
  • COM4
  • COM5

Test 2:

root\WMI ; The query: SELECT * FROM MSSerial_PortName returns only the following serial ports:

  • COM3
  • COM11
  • COM12
  • COM45
  • COM45

How can I get a complete list of serial ports?

+7
source share
4 answers

I have found a solution.

The following query ( root\CIMV2 ) gets the requested results:

 SELECT * FROM Win32_PnPEntity WHERE ClassGuid="{4d36e978-e325-11ce-bfc1-08002be10318}" 

Refresh

This answer is pretty old. Ein, I asked that I still need to consider WinXP and is using Windows7. Since I no longer deal with serial ports, I cannot give any new information on this issue. At that time, this solution reported all the ports that devicemanager showed. But I know that listing serial ports is not so simple, so this answer may be incorrect in all scenarios.

+4
source

In my case, I have physical serial ports, USB serial ports, and com0com virtual serial ports. I need both full names and COM port addresses.

The query suggested in this answer does not find com0com ports. The request suggested in this answer requires administrator privileges.

SELECT * FROM Win32_PnPEntity find all devices. It returns physical devices like this, and the address can be parsed from Caption :

 Serial Port for Barcode Scanner (COM13) 

However, for com0com Caption ports this is (without address):

 com0com - serial port emulator 

SELECT * FROM Win32_SerialPort returns addresses ( DeviceID ) as well as full names ( Name ). However, it finds only physical serial ports and com0com ports, not USB serial ports.

So in the end I need two WMI calls: SELECT * FROM Win32_SerialPort ( DeviceID address) and SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%' (address can be parsed from Caption ). I narrowed down the Win32_PnPEntity call because it needs to only find devices that were not found on the first call.

+2
source

Win32_SerialPort class used in this article reports physical COM ports. If you want to list all serial ports, including USB-Serial/COM ports, you should use the MSSerial_PortName class located in the root\wmi .

Also try these classes located in the same namespace

  • MSSerial_CommInfo
  • MSSerial_CommProperties
  • MSSerial_HardwareConfiguration
  • MSSerial_PerformanceInformation

Note. If you want to know the properties and methods of this class, you can use WMI Delphi Code Creator.

+1
source

I had similar problems trying to get the application to find the COM port for a USB serial device.

Using the \\localhost\root\CIMV2 to query SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0 , the application was able to find COM ports through each caption returned object or find the exact port by checking caption for the device name.

 ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(@"\\localhost\root\CIMV2", "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"); using (comPortSearcher) { string caption = null; foreach (ManagementObject obj in comPortSearcher.Get()) { if (obj != null) { object captionObj = obj["Caption"]; if (captionObj != null) { caption = captionObj.ToString(); if (caption.Contains("CH340")) { _currentSerialSettings.PortName = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")", string.Empty); } } } } } 

The parsing code was found in [C #]. How to programmatically find a COM port by friendly name

0
source

Source: https://habr.com/ru/post/957601/


All Articles