I'm writing a program in C++, and it is required to communicate to an Arduino via USB. Each time the Arduino restarts, it is possible that the port the Arduino is connected to changes (for example, located at /dev/ttyAMC0
, Arduino restart, connected at /dev/ttyAMC1
).
The code I am using is
#include <fcntl.h>
...
arduino = open("/dev/ttyAMC0", O_RDWR | O_NOCTTY | O_NDELAY);
if(arduino != -1)
fcntl(_arduino, F_SETFL, 0);
...
Each time the Arduino changes port locations, I have to manually change this in my code and then re-compile my program.
Is there a way to determine exactly which port the Arduino connected to, and have the location returned to me as a string (that is, "/dev/ttyACM1")?