views:

118

answers:

1

Hi,

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...

+2  A: 

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).

Oliver
Would it add any value that it's via USB?
argh
No, cause at the end it just shows up as another serial port within your system. Maybe there exists something you can ask through device manager to enumerate all devices in your machine and check the DeviceID or something like that, but i don't know very much about this level of software.
Oliver