def search(self):
#Return the 1st board founded with Exode installed
logCore("Searching for a board...")
boardList=[]
# Search a port
if platform.system() == 'Windows':
ports = windows_ports()
elif platform.system() == 'Darwin':
ports = [i[0] for i in list_ports.comports()]
else:
ports = glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*")
for p in ports:
try:
logCore("Try to connect to :"+p)
sr = serial.Serial(p, 9600)
except (serial.serialutil.SerialException, OSError) as e:
continue
time.sleep(2)
# This bit array execute the function checkExode()
# on the board
sr.write(bytearray([2, 0, ID('checkExode')]))
sr.flush()
time.sleep(0.25)
# the board should answer 202,404
ans= [0,0]
if sr.inWaiting()>0:
ans[0] = int.from_bytes(sr.read(), byteorder='little')
ans[1] = int.from_bytes(sr.read(4), byteorder='little', signed=False)
logCore(p+" answered "+str(ans))
if ans != [202,404]:
continue
else:
logCore("Arduino board detected with Exode at : "+p)
boardList.append(p)
return boardList
评论列表
文章目录