1 |
#!/usr/bin/python |
1 |
#!/usr/bin/python |
2 |
|
2 |
|
3 |
# Python test script for MLAB ALTIMET01A sensor |
3 |
# Python test script for MLAB ALTIMET01A sensor |
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 |
{"name": "altimet", "type": "altimet01" , "channel": 7, }, |
33 |
{"name": "altimet", "type": "altimet01" , "channel": 7, }, |
34 |
], |
34 |
], |
35 |
}, |
35 |
}, |
36 |
], |
36 |
], |
37 |
) |
37 |
) |
38 |
cfg.initialize() |
38 |
cfg.initialize() |
39 |
gauge = cfg.get_device("altimet") |
39 |
gauge = cfg.get_device("altimet") |
40 |
time.sleep(0.5) |
40 |
time.sleep(0.5) |
41 |
|
41 |
|
42 |
#### Data Logging ################################################### |
42 |
#### Data Logging ################################################### |
43 |
|
43 |
|
44 |
sys.stdout.write("ALTIMET data acquisition system started \n") |
44 |
sys.stdout.write("ALTIMET data acquisition system started \n") |
45 |
|
45 |
|
46 |
try: |
46 |
try: |
47 |
with open("temperature.log", "a") as f: |
- |
|
48 |
while True: |
47 |
while True: |
49 |
gauge.route() |
48 |
gauge.route() |
50 |
(t1, p1) = gauge.get_tp() |
49 |
(t1, p1) = gauge.get_tp() |
51 |
sys.stdout.write(" Temperature: %.2f Pressure: %d \n" % (t1, p1)) |
50 |
sys.stdout.write(" Temperature: %.2f Pressure: %d \n" % (t1, p1)) |
52 |
sys.stdout.flush() |
51 |
sys.stdout.flush() |
53 |
# time.sleep(0.5) |
52 |
# time.sleep(0.5) |
54 |
|
53 |
|
55 |
except KeyboardInterrupt: |
54 |
except KeyboardInterrupt: |
56 |
ser.close() |
55 |
ser.close() |
57 |
sys.exit(0) |
56 |
sys.exit(0) |
58 |
|
57 |
|