I am running a custom C++ program on Raspbian that power cycles its USB ports every once in a while. However, I've noticed that the /dev/USB* enumeration is inconsistent between power cycles, and need to be able to handle this.
Are there any elegant ways to obtain a string such as "/dev/ttyUSB0" or "/dev/ttyUSB1" based on what's currently in /dev/? It's fair to assume there will only ever be one device connected, but it's not fair to assume what that device is aside from what's necessary for communication.
Things I've tried so far:
- dirent.h - seems clunky to grab all of "/dev/" and search for "ttyUSB"
- Forcing the USB device names to be static - I need my program to not be dependent on the device being used on the serial port
I'm not entirely-opposed to using system calls, but would like to avoid using "ls -l /dev/ttyUSB*" if possible.