I have a few Arduino powered devices that have to communicate with a simple C++ program on my computer. At the moment I just tell the user to enter the COM port number of the device when the program is launched.
But I want to automate this process. So I thought it might be a good idea to make the Arduino return an id when a certain command is sent from my program to the Arduino, so that I can find it by sending the command to all COM ports..
I feel like this is a really bad approach though because who knows what other devices will do when they receive seemingly random data.
So is there any way to get the Arduino to appear as a real USB device (in a way that I can easily identify it) that allows a simple serial-like communication?
At the moment all I can think of is attaching a Bluetooth module to the Arduino and make the communication work through that. But surely there is a better way, right?
If you can detect the unique ID on the USB/TTL adapter, you can tell which com port belongs to which arduino. Say my arduino compatible device has an ID of AL02J6ISA. This can be extracted with proper C++ library calls, I suppose. On a Mac computer, the port name contains a portion of this unique ID, making it easier to tell. I use python on windows. It is able to extract this ID so I suppose C++ has similar utility for it.
That's very good to know. Thank you, I think I can figure it out now!
I use python on windows. It is able to extract this ID
Please post the Python snippet that does that.
for w in a:
print("Port:", w.device,"\tSerial#:", w.serial_number)
You need python 3.5, pyserial 3.1
Thanks. I will bookmark that.
Could you have the Arduino sending out a hello message continually (say once per second) and you open each com port in turn looking for this message (no need to send anything) when/if you open a com port that's sending the hello message you reply to it and the Arduino shuts up and is ready to work until it is once more reset.
Could you have the Arduino sending out a hello message continually (say once per second) and you open each com port in turn looking for this message
Normally an Arduino will reset when the PC opens the serial port and there will be a delay of a few seconds before it can send the "hello". The PC program would have to wait long enough to be sure the "hello" was not going to come and that would make the process very slow if there were several serial ports to be tested.