-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadduser.py
executable file
·69 lines (58 loc) · 1.53 KB
/
adduser.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
63
64
65
66
67
68
import serial
import anydbm
import re
import os
def connectToArduino():
print 'Waiting for arduino to connect'
while 1:
# Find device
dev = os.listdir('/dev/')
pattern = re.compile('ttyACM.*')
acm = [];
for d in dev:
if pattern.match(d):
acm.append(d)
# Try to connect
ser = None
for d in acm:
#try:
ser = serial.Serial('/dev/'+d, 9600)
# break
#except serial.serialutil.SerialException:
# pass
# Check if connected
if ser is not None:
break
# Wait for ready signal
pattern = re.compile('READY')
print 'Waiting for arduino to be ready'
while 1:
#try:
res = ser.readline()
if pattern.match(res):
print 'Arduino is ready'
break
# except serial.serialutil.SerialException:
# ser = connectToArduino()
return ser
ser = connectToArduino()
# Open user acount
db = anydbm.open('brukere', 'c')
adminMode = False;
pattern = re.compile(u'ID: ([0-9A-F]*)')
while 1:
#try:
res = ser.readline()
res = pattern.findall(res)
if (res !=[]):
id = str(res[0])
print 'Read id: '+id
name = raw_input('Write in name of user: ')
db[id] = name;
db.sync()
print db;
#except serial.serialutil.SerialException:
# ser = connectToArduino()
#except Exception, e:
# print str(e)
# ser = connectToArduino()