Discussion:
Find right COM port
(too old to reply)
jodleren
2008-10-31 10:19:31 UTC
Permalink
Hello

I communicate with an USB device, which acts as a COM port by the
driver. I am really new to using USB, so forgive my lack of knowledge
here.

Anyway, in the Device Manager I can find the right com port to use by
the name of the driver there.
As Windows can supply that, then I can find my comport there... if I
just know which one it is...

How do I track down the right comport, how can I find the drivers
name?

WBR
Sonnich
Jamie
2008-11-01 01:24:11 UTC
Permalink
Post by jodleren
Hello
I communicate with an USB device, which acts as a COM port by the
driver. I am really new to using USB, so forgive my lack of knowledge
here.
Anyway, in the Device Manager I can find the right com port to use by
the name of the driver there.
As Windows can supply that, then I can find my comport there... if I
just know which one it is...
How do I track down the right comport, how can I find the drivers
name?
WBR
Sonnich
Normally com ports are mapped in and are not intended to be
analyzed in that manner.
The USB types should be looked at in the same manner as a
read 232 would be..

IN other words, you treat them as real serial ports and ignore
the fact that USB 232 ports exist.

In windows, only one handle can be opened to a serial device at one
time. The simplest way I know of in searching for ports is to go into a
1..15 loop attempting file openings to each Comport.

File name using "COM1:","COM2:" etc..
if one fails, it means either its already in use or, it does not exist
and most likely any more attempts above that will fail.

Make sure you closet the handle on each one. Once you have compiled a
list of Comports that were valid, you then, open each one as you go
along and operate a test sequence looking for a expected response or,
looking for the state of some inputs..
etc..

P.S.
it's not good to poll the registry for hardware information because
it can cause conflicting configuration issues in cases like this..

USB 232/485 etc, normally are mapped in the systems com table. I
suppose there could be special devices that does not have its drivers,
mapped in as a serial port. In that case, you should already
known the expected name of the device and use the \\\.\\ method
etc...


http://webpages.charter.net/jamie_5"
Paul E. Schoen
2008-11-03 23:26:24 UTC
Permalink
Post by Jamie
Post by jodleren
Hello
I communicate with an USB device, which acts as a COM port by the
driver. I am really new to using USB, so forgive my lack of knowledge
here.
Anyway, in the Device Manager I can find the right com port to use by
the name of the driver there.
As Windows can supply that, then I can find my comport there... if I
just know which one it is...
How do I track down the right comport, how can I find the drivers
name?
WBR
Sonnich
Normally com ports are mapped in and are not intended to be
analyzed in that manner.
The USB types should be looked at in the same manner as a
read 232 would be..
IN other words, you treat them as real serial ports and ignore
the fact that USB 232 ports exist.
In windows, only one handle can be opened to a serial device at one
time. The simplest way I know of in searching for ports is to go into a
1..15 loop attempting file openings to each Comport.
File name using "COM1:","COM2:" etc..
if one fails, it means either its already in use or, it does not exist
and most likely any more attempts above that will fail.
Make sure you closet the handle on each one. Once you have compiled a
list of Comports that were valid, you then, open each one as you go along
and operate a test sequence looking for a expected response or, looking
for the state of some inputs..
etc..
P.S.
it's not good to poll the registry for hardware information because
it can cause conflicting configuration issues in cases like this..
USB 232/485 etc, normally are mapped in the systems com table. I
suppose there could be special devices that does not have its drivers,
mapped in as a serial port. In that case, you should already
known the expected name of the device and use the \\\.\\ method
etc...
I have a similar situation with a device I originally designed to use a
standard COM port. Now I have included a USB PIC which has its own unique
VID, PID, and serial number, which causes it to enumerate always as the
same COMnn number, no matter what hub it is plugged into, but it may be
different on various computers.

It has its own descriptor string that appears in the hardware manager. I
can search the registry and find this information, but I have not yet
attempted to do so with function calls in my program. The way I find my
special hardware is to open each available COM port (as determined by using
a procedure in my serial component SerialNG), and then I send a test
character. If I get the expected response, then I know that is the correct
COM port, and I remember it in a setup file so I can try it first next time
the program runs. But it would be better to check for the unique USB
descriptor and not write to unknown COM ports, which may possibly cause
problems for a device which might be connected.

I have never tried to use registry functions, so any suggestions on how to
find and use the entries for this purpose would be appreciated. I don't
want to screw up the registry.

Paul
Jamie
2008-11-05 01:46:14 UTC
Permalink
Post by Paul E. Schoen
Post by Jamie
Post by jodleren
Hello
I communicate with an USB device, which acts as a COM port by the
driver. I am really new to using USB, so forgive my lack of knowledge
here.
Anyway, in the Device Manager I can find the right com port to use by
the name of the driver there.
As Windows can supply that, then I can find my comport there... if I
just know which one it is...
How do I track down the right comport, how can I find the drivers
name?
WBR
Sonnich
Normally com ports are mapped in and are not intended to be
analyzed in that manner.
The USB types should be looked at in the same manner as a
read 232 would be..
IN other words, you treat them as real serial ports and ignore
the fact that USB 232 ports exist.
In windows, only one handle can be opened to a serial device at one
time. The simplest way I know of in searching for ports is to go into a
1..15 loop attempting file openings to each Comport.
File name using "COM1:","COM2:" etc..
if one fails, it means either its already in use or, it does not exist
and most likely any more attempts above that will fail.
Make sure you closet the handle on each one. Once you have compiled a
list of Comports that were valid, you then, open each one as you go along
and operate a test sequence looking for a expected response or, looking
for the state of some inputs..
etc..
P.S.
it's not good to poll the registry for hardware information because
it can cause conflicting configuration issues in cases like this..
USB 232/485 etc, normally are mapped in the systems com table. I
suppose there could be special devices that does not have its drivers,
mapped in as a serial port. In that case, you should already
known the expected name of the device and use the \\\.\\ method
etc...
I have a similar situation with a device I originally designed to use a
standard COM port. Now I have included a USB PIC which has its own unique
VID, PID, and serial number, which causes it to enumerate always as the
same COMnn number, no matter what hub it is plugged into, but it may be
different on various computers.
It has its own descriptor string that appears in the hardware manager. I
can search the registry and find this information, but I have not yet
attempted to do so with function calls in my program. The way I find my
special hardware is to open each available COM port (as determined by using
a procedure in my serial component SerialNG), and then I send a test
character. If I get the expected response, then I know that is the correct
COM port, and I remember it in a setup file so I can try it first next time
the program runs. But it would be better to check for the unique USB
descriptor and not write to unknown COM ports, which may possibly cause
problems for a device which might be connected.
I have never tried to use registry functions, so any suggestions on how to
find and use the entries for this purpose would be appreciated. I don't
want to screw up the registry.
Paul
TO get around that, during a setup procedure of your program, like when
you are installing the software. Instruct the user to not have the
device plugged in.
While in the install, query the list of available ports. Com ports
can also be found in the hardware map in the registry ( the mapped
one's), when a log has been done. Instruct the user to insert the device
or turn it on, then perform another scan and see which comport arrived.

This shouldn't be a problem since many are accustom to installing USB
devices in this manner.
The only problem with this approach is if you have more than one USB
serial device on board of the same type and may be changed.
I normally don't worry to much about testing an unknown serial port
because most of the time, if it's in use, you shouldn't be able to open
it any way.


http://webpages.charter.net/jamie_5"

Loading...