views:

395

answers:

2

Hi guys, i have a few devices that communicate through serial port. Since, they are not always connected to the same serial port, so i need to know exactly which device i'm communicating with when i send data. How can I check which device is connected to which com port.

+1  A: 

The solution that is most often used is to "ping" each serial port and then check the reply. Program your device to reply with a certain message when it receives a special request, e.g. if it receives "Hello" it will reply "Hi, I'm device X". This way you can send "Hello" to each serial port in sequence, wait a second or so, and if you receive the reply you were expecting, then you know what serial port to use.

This might confuse some devices connected to the serial port though, so you need to consider what kind of devices your users have connected. In most cases, if you pick a keyword that the device is not expecting to receive, it will simply discard of the request you send it and wait for another request.

Marius
Thanks Marius. There is one problem though, i am only integrating these devices in my app and not actually programming the devices per se. It seems i will need to get in touch with the manufacturers and see if they already have any such built-in mechanism. Or is there another possibility...
Xience
If you know how the devises work, find out if there is something they reply to from the computer. In some cases (eg, barcode/RFID reader) this might not be true.
Marius
A: 

In some cases rs-232 P'n'P features may be usable

vitaly.v.ch