-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (32 loc) · 743 Bytes
/
main.py
File metadata and controls
36 lines (32 loc) · 743 Bytes
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
#!/usr/bin/python
# -*- coding:utf-8 -*-
import serial
import time
ser = serial.Serial("/dev/ttyS0", 9600)
def sendToMCU(message):
ser.write(message)
ser.flushInput()
time.sleep(0.1)
def recvHandle(buff):
if buff == '@':
print 'MCU Handshake'
if buff == 'faketoken':
print buff
sendToMCU('RAPI0#')
print 'Unlock Successful'
else:
print buff
sendToMCU('RAPI1#')
print 'Unlock Failed'
def main():
while True:
count = ser.inWaiting()
if count != 0:
recv = ser.read(count)
recvHandle(recv)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
if ser != None:
ser.close()