Friday, February 06, 2009 11:55 PMHi,
I am trying to get a list of all available serial port devices. The only thing I could get so far is just a list of available COM ports (SerialPort class).
Additionally I would like to get more detailed information about each device, to filter virtual COM ports and distinguish between USB and Bluetooth devices.
I am using Visual Studio 2005, C#, .Net 2.0
Saturday, February 07, 2009 1:12 AMModeratorUse WMI to query Win32_SerialPort. Good Google search terms.
- Marked As Answer by Untit1ed Saturday, February 07, 2009 5:24 AM
Saturday, February 07, 2009 1:21 AMnobugz said:
Use WMI to query Win32_SerialPort. Good Google search terms.
Thanks, I found it, unfortunately it doesn't show virtual serial ports.
I have 2 devices connected via USB to my PC. And only one of them has 2 real COM ports, the other one has 2 virtual ports (I haven't realized it until now). I am able to see it under port section in Windows Device Manager. So I guess I really need to know how to list virtual ports now =)
Monday, February 23, 2009 11:32 PMWhenever I see "WMI", I run quickly, in the opposite direction.
Here's a discussion on enumerating serial ports:
An example class is linked there:
- Marked As Answer by Untit1ed Tuesday, February 24, 2009 3:56 AM
Tuesday, February 24, 2009 3:56 AMThanks for the example, I'll keep it in mind for future. But I feel more comfortable with WMI now(Win32_SerialPort and Win32_PnPEntity solved my problem perfectly). The example that you provided is confusing to me and it is more than thousand lines of code long, WMI just takes about 10-15 lines.
Is there any particular reason you avoid using WMI?
Tuesday, February 24, 2009 10:17 PMWMI is bulky and slow, very slow. Upon first use it can take 10-30 seconds to load and get itself ready. If performance isn't an issue, WMI is easier, that's the tradeoff.
.NET has an easier facility for enumerating serial ports. If you don't mind using C#, try this:
string SerialPortEnums = System.IO.Ports.SerialPort.GetPortNames();
Tuesday, February 24, 2009 10:30 PMActually it works pretty fast for me. I don't see any delays, it shows me my devices as soon as I plug them in.
And I wrote about SerialPort class in my first comment to this thread, the class doesn't provide any information about COM ports, it just lists available non-virtual COM numbers.