blob: 0b7704130c9e435a741f6366fcb67b9216dbbe7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/python
import time,serial,signal,sys,struct
serIn = serial.Serial(
port='/dev/rfcomm0',
baudrate=38400
)
def signal_handler(signal, frame):
print "closing",serIn.port
serIn.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
S=struct.Struct('<HIH')
while 1:
r=bytearray()
remaining=8
while remaining > 0:
if serIn.inWaiting() >0:
r.extend(serIn.read())
remaining=8-len(r)
#time.sleep(1) #doesn't work for some reason
print S.unpack_from(buffer(r))
|