-
Notifications
You must be signed in to change notification settings - Fork 2
/
usb_import.py
57 lines (49 loc) · 1.14 KB
/
usb_import.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: cp1252 -*-
import time
import signal
import sys
import serial
ser = serial.Serial()
ser.port = 3 # May change from system to system. Validate to be sure.
ser.baudrate = 57600
if ser.isOpen():
ser.close()
ser.open()
else:
ser.open()
def decode(code):
deco = []
for a in code:
deco.append(ord(a))
return deco
def listen(b):
msg = b
while 1:
a = ser.read(1)
if a == '\x7E':
msg += a
return msg
else:
msg += a
return msg
def main():
d = open('messages.txt','w')
while True:
try:
b = ser.read(1)
if b == '\x7E':
print "7E found"
msg_array = decode(listen(b))
print map(hex,msg_array)
stringtofile = ""
for a in msg_array:
stringtofile += str(hex(a)) + " "
d.write(stringtofile + "\n")
except KeyboardInterrupt:
print "Bye"
print map(hex,msg_array)
ser.close()
d.close()
sys.exit()
if __name__ == '__main__':
main()