I have this small app that I want to communicate with an Arduino device through the USB port. So far I managed to communicate with it using the open source ORSSerial
framework.
However, I want this Arduino device to be plug and play, and the path to the serial port (/dev/cu.usbserial-XXX
) will change depending on what USB-port I'm using on the Mac.
How would I solve this to be able to have "plug and play" capabilites? Is there some way that the Arduino can let my macOS app know when it get connected, and by this get the correct serial port path?
One possible way that might work (I have not tested):
- When Arduino is connected to computer, in the
setup()
function send a "special message" for the macOS to listen to and then reveal which serial port it came from.
- When macOS app starts, send a "special message" to all ports, and have the Arduino respond to this specific message, revealing its port.
question from:
https://stackoverflow.com/questions/65601848/automatically-detect-correct-serial-connection-to-arduino-device-from-macos-xco 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…