Thank you for the detailed instructions. The qbossac -p /dev/ttyACM0 -a -i -R
command does trigger the port renaming most of the times, and sometimes it gives the output below. The loop number in the first line is usually 5, but I have seen loop=0 and loop=6 occasionally too. When it changes port, I change /dev/ttyACM0
to /dev/ttyACM1
so it will trigger the port change again to change it back.
$ ~/.arduino15/packages/qnimble/tools/qbossa/1.9.7/qbossac -p /dev/ttyACM0 -a -i -R
Restablished Connection on loop=5
Device : qNimble BOSSAv1
Version : v0.5.1 [Arduino:XYZ] May 5 2023
Address : 0x300000
Pages : 32768
Page Size : 256 bytes
Total Size : 8192KB
Planes : 1
Lock Regions : 32
Locked : 16
Security : false
Boot Flash : false
BOD : false
BOR : false
The python program you attached can work consistently if I wait for a few seconds from deleting the ser
object to connecting again. If I put the serial connection and deleting code in a loop, with 1 s sleep between each loop, then I can see 1 failure every 4 successes very consistently. The code I tested with is attached below:
import serial
dev = '/dev/ttyACM0'
counters = []
for kk in range(50):
try:
ser = serial.Serial(dev, 1200, timeout=1)
del ser
counters.append(1)
except:
counters.append(0)
time.sleep(1)
print(counters)
I get an output of [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0]
. I never see the devices renamed when I run the code while running ls
in /dev
. When it fails, ls
simply does not show any /dev/ttyACM*
device. If I change the sleep time to 5 s, it succeeds consistently.