1 import serial, os, time, atexit
8 os.system(
"rm -f /tmp/dev_ttyUSB*")
11 if os.path.exists(lockfilepath):
12 os.remove(lockfilepath)
14 atexit.register(removelockfile)
18 ser.reset_input_buffer()
22 while ser.inWaiting() > 0:
23 line = ser.readline().strip()
25 if not line == idstring:
26 print(
"incorrect board id: "+line)
29 print(
"connected to: "+line)
34 global lockfilepath, portnum
37 port =
'/dev/ttyUSB'+str(portnum)
39 print(
"trying port: "+port)
41 lockfilepath =
"/tmp/dev_ttyUSB"+str(portnum)
44 if os.path.exists(lockfilepath):
45 print(
"port busy: "+port)
52 print(
"giving up on port: "+port)
56 open(lockfilepath,
'w')
59 ser = serial.Serial(port, 115200, timeout=TIMEOUT)
60 except serial.SerialException:
61 print(
"port exception: "+port)
62 os.remove(lockfilepath)
73 if os.path.exists(lockfilepath):
74 os.remove(lockfilepath)
79 print(
"device not found")
def usbdiscover(idstring, TIMEOUT)
def checkBoardId(idstring, ser)