Previously I had my Due connected via Programming Port for weeks, and it never changed serial ports after pressing the reset button. Recently I switched to having it connected via the Native Port instead, and was surprised to see that it changes port numbers every time I press the reset button.
For example if it was on ttyATM1 beforehand, after pressing reset it'll be on ttyATM2 instead. It changes numbers like this after every reset. Is this normal behavior?
I have a python script sending serial data to the Due, and I have to change the port number in the python code every time the Due changes ports.
1 Answer 1
It happens because of Linux, not because of the Arduino. Since you unplug/reset the DUE while the port is still open, when it's back online, the old file name is still in use, so a new one is created. Just close the port before resetting the DUE and you will see that after the reset it will have the same one.
You can easily reproduce the same issue with a serial to usb adapter (/dev/ttyUSBS0,1,2,etc) and screen or minicom.
To make your program more robust, you should listen for kernel events and open the port accordingly.
-
Thanks! I'm glad you mentioned that it's possible to make a check for those events. I found this nice page with lots of info on how to do it: stackoverflow.com/questions/2530096/…. And then the command: "# ls /dev/serial/by-id" neatly lists the Due as: "usb-Arduino_LLC_Arduino_Due-if00". Maybe it won't be as difficult as I had thought.Jerry– Jerry2015年11月01日 11:56:28 +00:00Commented Nov 1, 2015 at 11:56
-
There is a problem with that: if you have 2 devices with the same id, your program might get confused, if it has to tell them apart. In such case, if you do not change the way they are plugged, but simply restart them, like with the Arduino reset, you can inspect the usb device tree.Igor Stoppa– Igor Stoppa2015年11月01日 12:41:33 +00:00Commented Nov 1, 2015 at 12:41
-
Thanks. I also frequently plug/unplug the units. If I'm expecting to only have one Due in the foreseeable future, would it be suitable to just detect the text for "Due"?Jerry– Jerry2015年11月01日 12:52:59 +00:00Commented Nov 1, 2015 at 12:52
-
1Or for whatever is the id shown by your device. Yes, it's ok as long as you are aware of the potential issue and document it in the code, so that later on you or someone else doesn't have to remember it.Igor Stoppa– Igor Stoppa2015年11月01日 12:55:04 +00:00Commented Nov 1, 2015 at 12:55