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