hi.
I have a device connected via comm - usb adaptor to computer.
(comm in device and usb in computer)

When i connect the device, Windows recognizes it as COM6.(it may be any other port name, but for examples i'll take com6)

Then i run my code for finding the device by going from com1 to com16, trying to open current port , in case it opens i send "hello" to the device and wait some time for the response, say "hello, i'm ..".

The code works fine and finds the device port when it can open the port (COM6).
BUT
There are cases when other application takes COM6, even if in physical usb(comm) exit no device is connected. Then when i connect my device, Windows again recognizes it as COM6, and in the code i fail to open it, since it in use.

SO, what relationship is between the pysical usb (comm adaptor) and logical (1 - 256) ports?
When pysical comm exit gets it's name (COM6 and not 7 or 180)?
How can i find free logical comm name and "connect" / relate it to the physical exit?
(The fact that i can open the port doesn't define that this port is free to use, there is a case that other devise connected via this port, but right on this time it didn't took it.)
Where can i find any information on this ?

Thanks a lot,
anastacia