How to find which COM port a particular device is installed on

  • Thread starter Thread starter Michael_Burgess
  • Start date Start date
M

Michael_Burgess

Hi there,

I've got a problem that should be easy to solve, but I'm having a
nightmare in doing so.

We have an app deployed to a large number of laptops and I've
discovered a problem. We've made an assumption that the GPRS card will
always been on COM4. This isn't always the case and I need to code
something that dynamically sets the correct value in the app before
trying to dial.

The client app is in C#. I've been looking at Win32 APIs, such as
SetupDiEnumDeviceInfo and GetDefaultCommConfig, but I can't see how
these are going to help.

I've managed to get a list of all COM ports using a ManagementObject. I
know I can disregard COM1, but I could be left with more than 1 other
port, so need a way of establishing if it's the correct device. Does
anyone have any ideas how I could programatically identify a particular
piece of hardware on these COM ports?

The old VB code the app was translated from just took a list of COM
ports, disregarded COM1 and tried to open a stream on each remaining
one, 'assuming' that the first to respond was the GPRS card. This is
not reliable and I'm not happy replicating that in my code.

It's late, i'm stuck for ideas and really want to get this out the door
tomorrow. Can anyone suggest anything please that ideally doesn't
involve tons of calls to Win32 APIs, although if they're going to bring
something to the table then I'll happily go down that route.

Many thanks,
Michael.
 
SerialPort.GetPortNames (); gives the valid com ports.

Then try each one for valid pins (CtsHolding, DsrHolding, CDHolding and
RtsEnable) according to your device, and if acceptable see if it gives you
the data you expect.

JR
 
Thanks for the response. In the end I managed to use the
"Win32_POTSModem" class in the WMI and from that am able to determine
all the attached modems. I can disregard the internal modem as the
'DeviceType' property states 'Internal Modem' and then pass an AT
signal strength query to the device in question and work it out from
the response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top