0
votes

I need to determine the COM-Port of a Plug-And-Play-Device. I have the PnPDeviceID. It's a bluetooth usb dongle.

So, I retrieve information about the device using WMI like in the first example at this website. The result of the WMI-query contains a property "DeviceID" which is a string. The value in my case is "COM3".

I get the same value, when I do (instead of using WMI)

string[] names = System.IO.Ports.SerialPort.GetPortNames();

Now I am wondering, if the DeviceId of COM-Devices always has the format "COMx"? I actually need a property called "Port" with an integer as value.

There is another approach, to go over the registry, but I don't know, if this is suggested.

1
It is a driver implementation detail. They can name it whatever they want but, sure, it is common they name it "COMx". There is no significance to the number so it is really best to let the user pick from a list.Hans Passant
@SonerGönül I pretty much get that information over WMI. But there is no int PortOneWorld

1 Answers

0
votes

See comment of Hans Passant. They are commonly named COMx. And u should let the user pick.

More important to me: Mostly it is not necessary to get the com port number as integer, since the Com-port name (string) is used as identifier widely, e.g. with System.io... They take the string "COM3" or the driver specific name.