forked from henrytwo/BlockChainChain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialgao.py
62 lines (45 loc) · 1.24 KB
/
serialgao.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
58
59
60
61
62
import time
import serial
import dataparsing
import traceback
serial_disabled = False
locked = True
class Andrewino:
def __init__(self, id):
global serial_disabled
print('Hello')
try:
self.s = serial.Serial(id)
print('Serial connected!')
except:
self.s = None
serial_disabled = True
traceback.print_exc()
print('Serial disabled.')
def lock(self, key):
global locked
dataparsing.log(key, 'LOCK')
if not serial_disabled:
self.s.write(b'lock')
else:
locked = True
#print('LOCK! (SERIAL OFFLINE)')
def unlock(self, key):
global locked
dataparsing.log(key, 'UNLOCK')
if not serial_disabled:
self.s.write(b'unlock')
else:
locked = False
#print('LOCK! (SERIAL OFFLINE)')
def status(self):
global locked
if not serial_disabled:
# Is it locked?
self.s.write(b'status')
meh = self.s.readline().decode().strip() == 'true'
print(meh)
return meh
else:
#print('STATUS! (SERIAL OFFLINE)')
return locked