-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.py~
64 lines (55 loc) · 1.99 KB
/
arguments.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
import getopt
import sys
from optparse import OptionParser
def help():
sys.stderr.write("""Erabilera: python3.3 main.py [aukerak]
aukerak:
-p, --port=PORT: Erabili nahi den portu seriaren helbidea
-t, --timeout=TIMEOUT: Serie portuaren timeout-a (segundutan)
-d, --timebetweendata=TBD: Behin baino gehiagotan jarriz gero datuak jasotzen, datu bat eta hurrengoaren artean zenbat denbora pasako den (segundutan). GOMENDAGARRIA 5 SEGUNDUTIK GORA
Adibidez:
python3.3 main.py -p /dev/ttyUSB0 -t 1 -d 10
\n""")
def read_arguments2():
values = {}
values['port']=0
values['timeout']=1
values['tbd']=5
parser = OptionParser()
usage = "usage: %prog [options]"
parser.add_option("-p", "--port", dest=values['port'], default="/dev/ttyUSB0", type="string", help="Select serial device port")
parser.add_option("-t", "--timeout", dest=values['timeout'], default=1, type="int", help="Serial calls timeout (sec)")
parser.add_option("-d", "--timebetweendata", dest=values['tbd'], default=30, type="int", help="Time between data updates (sec)")
print values['port']
return values
def read_arguments():
values = {}
values['port']=0
values['timeout']=1
values['tbd']=5
try:
opts, args = getopt.getopt(sys.argv[1:],
"hp:td",
["help", "port=", "timeout", "timebetweendata"]
)
except getopt.GetoptError:
#print help information and exit
help()
sys.exit(2)
#read the arguments
for o,a in opts:
print("opts: "+o)
print("args: "+a)
if o in ("-h", "--help"):
help()
sys.exit()
elif o in ("-p", "--port"):
try:
values['port'] = int(a)
except ValueError:
values['port'] = a
elif o in ("-t", "--timeout"):
values['timeout'] = int(a)
elif o in ("-d", "--timebetweendata"):
values['tbd'] = int(a)
return values