Post by JamiePost by jodlerenHello
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