def recvByte():
i = tty.read()
- while len(i)==0:
- time.sleep(0.03)
- i = tty.read()
return ord(i)
+def recvByteTO(b): #with timeout
+ j = 0
+ i = tty.read()
+ while len(i)==0 and j < 400:
+ time.sleep(0.03)
+ i = tty.read()
+ j = j + 1
+ if j == 400:
+ print "ack it!"
+ sendByte(0x23)
+ if(recvByte() != 0xaa):
+ raise Exception #ok, something really failed
+ else:
+ if(ord(i) != b):
+ raise Exception
+
def sendByte(byte):
time.sleep(0.005) # just to get sure, wait 5ms
tty.write(chr(byte))