1 |
#!/usr/bin/python |
1 |
#!/usr/bin/python |
2 |
|
2 |
|
3 |
# Python driver for MLAB MAG01A module with HMC5888L Magnetometer sensor wrapper class |
3 |
# Python driver for MLAB ALTIMET01A module with HMC5888L Magnetometer sensor wrapper class |
4 |
|
4 |
|
5 |
import time |
5 |
import time |
6 |
import datetime |
6 |
import datetime |
7 |
import sys |
7 |
import sys |
8 |
import serial |
8 |
import serial |
9 |
|
9 |
|
10 |
from pymlab import config |
10 |
from pymlab import config |
11 |
|
11 |
|
12 |
|
12 |
|
13 |
#### Script Arguments ############################################### |
13 |
#### Script Arguments ############################################### |
14 |
|
14 |
|
15 |
if len(sys.argv) != 2: |
15 |
if len(sys.argv) != 2: |
16 |
sys.stderr.write("Invalid number of arguments.\n") |
16 |
sys.stderr.write("Invalid number of arguments.\n") |
17 |
sys.stderr.write("Usage: %s #I2CPORT\n" % (sys.argv[0], )) |
17 |
sys.stderr.write("Usage: %s #I2CPORT\n" % (sys.argv[0], )) |
18 |
sys.exit(1) |
18 |
sys.exit(1) |
19 |
|
19 |
|
20 |
port = eval(sys.argv[1]) |
20 |
port = eval(sys.argv[1]) |
21 |
|
21 |
|
22 |
|
22 |
|
23 |
#### Sensor Configuration ########################################### |
23 |
#### Sensor Configuration ########################################### |
24 |
|
24 |
|
25 |
cfg = config.Config( |
25 |
cfg = config.Config( |
26 |
port = port, |
26 |
port = port, |
27 |
bus = [ |
27 |
bus = [ |
28 |
{ |
28 |
{ |
29 |
"type": "i2chub", |
29 |
"type": "i2chub", |
30 |
"address": 0x72, |
30 |
"address": 0x72, |
31 |
|
31 |
|
32 |
"children": [ |
32 |
"children": [ |
33 |
{ |
33 |
{ |
34 |
"type": "i2chub", |
34 |
"type": "i2chub", |
35 |
"address": 0x70, |
35 |
"address": 0x70, |
36 |
"channel": 3, |
36 |
"channel": 3, |
37 |
"children": [ |
37 |
"children": [ |
38 |
{"name": "altimet1", "type": "altimet01" , "channel": 0, }, |
38 |
{"name": "altimet1", "type": "altimet01" , "channel": 0, }, |
39 |
{"name": "altimet2", "type": "altimet01" , "channel": 3, }, |
39 |
{"name": "altimet2", "type": "altimet01" , "channel": 3, }, |
40 |
{"name": "altimet3", "type": "altimet01" , "channel": 4, }, |
40 |
{"name": "altimet3", "type": "altimet01" , "channel": 4, }, |
41 |
{"name": "altimet4", "type": "altimet01" , "channel": 5, }, |
41 |
{"name": "altimet4", "type": "altimet01" , "channel": 5, }, |
42 |
{"name": "altimet5", "type": "altimet01" , "channel": 6, }, |
42 |
{"name": "altimet5", "type": "altimet01" , "channel": 6, }, |
43 |
{"name": "altimet6", "type": "altimet01" , "channel": 7, }, |
43 |
{"name": "altimet6", "type": "altimet01" , "channel": 7, }, |
44 |
], |
44 |
], |
45 |
}, |
45 |
}, |
46 |
{"name": "altimet8", "type": "altimet01" , "channel": 6, }, |
46 |
{"name": "altimet8", "type": "altimet01" , "channel": 6, }, |
47 |
], |
47 |
], |
48 |
}, |
48 |
}, |
49 |
|
49 |
|
50 |
# { |
50 |
# { |
51 |
# "type": "i2chub", |
51 |
# "type": "i2chub", |
52 |
# "address": 0x72, |
52 |
# "address": 0x72, |
53 |
# "children": [ |
53 |
# "children": [ |
54 |
# {"name": "altimet", "type": "altimet01" , "channel": 6, }, |
54 |
# {"name": "altimet", "type": "altimet01" , "channel": 6, }, |
55 |
# ], |
55 |
# ], |
56 |
# }, |
56 |
# }, |
57 |
|
57 |
|
58 |
|
58 |
|
59 |
], |
59 |
], |
60 |
) |
60 |
) |
61 |
cfg.initialize() |
61 |
cfg.initialize() |
62 |
|
62 |
|
63 |
gauge1 = cfg.get_device("altimet1") |
63 |
gauge1 = cfg.get_device("altimet1") |
64 |
gauge2 = cfg.get_device("altimet2") |
64 |
gauge2 = cfg.get_device("altimet2") |
65 |
gauge3 = cfg.get_device("altimet3") |
65 |
gauge3 = cfg.get_device("altimet3") |
66 |
gauge4 = cfg.get_device("altimet4") |
66 |
gauge4 = cfg.get_device("altimet4") |
67 |
gauge5 = cfg.get_device("altimet5") |
67 |
gauge5 = cfg.get_device("altimet5") |
68 |
gauge6 = cfg.get_device("altimet6") |
68 |
gauge6 = cfg.get_device("altimet6") |
69 |
|
69 |
|
70 |
gauge8 = cfg.get_device("altimet8") |
70 |
gauge8 = cfg.get_device("altimet8") |
71 |
time.sleep(0.5) |
71 |
time.sleep(0.5) |
72 |
|
72 |
|
73 |
#### Data Logging ################################################### |
73 |
#### Data Logging ################################################### |
74 |
|
74 |
|
75 |
sys.stdout.write("ALTIMET data acquisition system started \n") |
75 |
sys.stdout.write("ALTIMET data acquisition system started \n") |
76 |
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) |
76 |
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) |
77 |
|
77 |
|
78 |
try: |
78 |
try: |
79 |
with open("temperature.log", "a") as f: |
79 |
with open("temperature.log", "a") as f: |
80 |
while True: |
80 |
while True: |
81 |
sys.stdout.write("Start measurement now? [ENTER]") |
81 |
sys.stdout.write("Start measurement now? [ENTER]") |
82 |
sys.stdin.readline() |
82 |
sys.stdin.readline() |
83 |
|
83 |
|
84 |
ser.write(':DISP?\n') |
84 |
ser.write(':DISP?\n') |
85 |
Prefstart = eval(ser.readline(100)) |
85 |
Prefstart = eval(ser.readline(100)) |
86 |
|
86 |
|
87 |
gauge1.route() |
87 |
gauge1.route() |
88 |
(t1, p1) = gauge1.get_tp() |
88 |
(t1, p1) = gauge1.get_tp() |
89 |
gauge2.route() |
89 |
gauge2.route() |
90 |
(t2, p2) = gauge2.get_tp() |
90 |
(t2, p2) = gauge2.get_tp() |
91 |
gauge3.route() |
91 |
gauge3.route() |
92 |
(t3, p3) = gauge3.get_tp() |
92 |
(t3, p3) = gauge3.get_tp() |
93 |
gauge4.route() |
93 |
gauge4.route() |
94 |
(t4, p4) = gauge4.get_tp() |
94 |
(t4, p4) = gauge4.get_tp() |
95 |
gauge5.route() |
95 |
gauge5.route() |
96 |
(t5, p5) = gauge5.get_tp() |
96 |
(t5, p5) = gauge5.get_tp() |
97 |
gauge6.route() |
97 |
gauge6.route() |
98 |
(t6, p6) = gauge6.get_tp() |
98 |
(t6, p6) = gauge6.get_tp() |
99 |
# gauge7.route() |
99 |
# gauge7.route() |
100 |
# (t7, p7) = gauge7.get_tp() |
100 |
# (t7, p7) = gauge7.get_tp() |
101 |
gauge8.route() |
101 |
gauge8.route() |
102 |
(t8, p8) = gauge8.get_tp() |
102 |
(t8, p8) = gauge8.get_tp() |
103 |
|
103 |
|
104 |
ser.write(':DISP?\n') |
104 |
ser.write(':DISP?\n') |
105 |
Prefstop = eval(ser.readline(100)) |
105 |
Prefstop = eval(ser.readline(100)) |
106 |
|
106 |
|
107 |
sys.stdout.write(" Temperature: %.2f %.2f %.2f %.2f %.2f %.2f %.2f Pressure: %d %d %d %d %d %d %d %s %s Note: " % (t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, Prefstart, Prefstop )) |
107 |
sys.stdout.write(" Temperature: %.2f %.2f %.2f %.2f %.2f %.2f %.2f Pressure: %d %d %d %d %d %d %d %s %s Note: " % (t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, Prefstart, Prefstop )) |
108 |
note = sys.stdin.readline() |
108 |
note = sys.stdin.readline() |
109 |
f.write("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\n" % (time.time(), datetime.datetime.now().isoformat(),t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, Prefstart, Prefstop, note, )) |
109 |
f.write("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\n" % (time.time(), datetime.datetime.now().isoformat(),t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, Prefstart, Prefstop, note, )) |
110 |
sys.stdout.flush() |
110 |
sys.stdout.flush() |
111 |
# time.sleep(0.5) |
111 |
# time.sleep(0.5) |
112 |
|
112 |
|
113 |
except KeyboardInterrupt: |
113 |
except KeyboardInterrupt: |
114 |
ser.close() |
114 |
ser.close() |
115 |
sys.exit(0) |
115 |
sys.exit(0) |
116 |
|
116 |
|