argh
argh

Reputation: 933

COM port - how to identify a device (.net/c#)

I'm programming for Windows CE and I need to connect to a scanner. There is no problem - I know that it is on port COM0, but if I plug in another device earlier it gets another COM port... to get all com ports the easy way is:

SerialPort.GetPortNames()

But I don't know how to identify a device? Is there any standard way? I can't 'ping' it since there is one device that only sends data... it spams data all the time... and I don't know how to 'ping' a device...

Upvotes: 1

Views: 2226

Answers (1)

Oliver
Oliver

Reputation: 45071

The problem of a serial connection is that is stateless. You can't know if anyone is on the other side listening or who is listening.

To find this out you just have a few choices:

  • To find out if there is someone use hardware handshake (like RTS, CTS, etc.) if possible.
  • To find who is there, you normally send some kind of identify message where you know the correct answer (e.g. to a modem you'll send AT and you'll receive an OK.

So if you can't use any of the above methods you can't automatically detect which port to use. So the only working model is to ask the user for the correct setting(s) (e.g. ComboBox with available ports or BaudRates, CheckBoxes for the different boolean configuration settings, etc).

Upvotes: 4

Related Questions