Finding number of Com ports on a machine

  • Thread starter Thread starter rollasoc
  • Start date Start date
R

rollasoc

Hi,

I've worked out how to find the 2 COM Ports on my motherboard ok, using
System.Management namespace and looking for Win32_SerialPort.

Problem now, is I have 3 COM Ports on USB connections, but can't seem to
find a way to query for them.

Any suggestions?

rollasoc
 
Ok there was a great article that touched on this sort of thing, I will also
state that I didn't try this but believe the article is relevant to your
problem/issue/question.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncodefun/h
tml/code4fun12102003.asp

Coding in the Blue Glow
Duncan Mackenzie
Microsoft Developer Network
December 11, 2003

He writes a number of nice articles on well stuff he feels like I guess.

Hope it helps.

-Evan
 
I do it by iterating through each possible COM port attempting to open each
one in turn. Something like this:

FOR nPort = 1 to MaxPorts
Attempt to open COM<nPort>
IF (it succeeded)
Add nPort to list of available ports
Close COM<nPort>
ENDIF
ENDFOR
 
Back
Top