tags:

views:

170

answers:

1

I'm using an Arduino with the Firmata library for communication to a C# application, and I want to eliminate a COM port configuration component since it can change from machine to machine...

Is it possible to:

  1. Enumerate list of COM ports in the system? (In my googling I've seen some fairly ugly Win32 API code, hoping there's maybe a cleaner version now)
  2. Auto-detect which COM port(s) are connected to an Arduino?
+1  A: 
  1. You can use SerialPort.GetPortNames() to return an array of string COM port names.
  2. I dont think you can auto detect the ports, youd have to ping the device in order to see if the device is connected.
SwDevMan81
I'm fine with opening the ports and sending a command/listening for response... just don't know if there's a best practice "ping" that an Arduino would respond to.. and also find out if the port is already in use by something else, etc.
routeNpingme
This (http://stackoverflow.com/questions/195483/c-check-if-a-com-serial-port-is-already-open) post talks about finding if a port is in use. Basically you need to try and open them. If you get an exception, then its probably in use. If it opens fine, you can check the IsOpen property to verify that its connected. I would find the smallest message or a revision response message from the Arduino board to verify that you are actually connected to the board and not some other device.
SwDevMan81