Rev Author Line No. Line
3374 kaklik 1 #!/usr/bin/python
2  
3453 kaklik 3 # Python driver for MLAB ALTIMET01A module with HMC5888L Magnetometer sensor wrapper class
3374 kaklik 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")
3413 kaklik 76 ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
3376 kaklik 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()
3413 kaklik 83  
84 ser.write(':DISP?\n')
3414 kaklik 85 Prefstart = eval(ser.readline(100))
3413 kaklik 86  
3376 kaklik 87 gauge1.route()
88 (t1, p1) = gauge1.get_tp()
89 gauge2.route()
90 (t2, p2) = gauge2.get_tp()
91 gauge3.route()
92 (t3, p3) = gauge3.get_tp()
93 gauge4.route()
94 (t4, p4) = gauge4.get_tp()
95 gauge5.route()
96 (t5, p5) = gauge5.get_tp()
97 gauge6.route()
98 (t6, p6) = gauge6.get_tp()
99 # gauge7.route()
100 # (t7, p7) = gauge7.get_tp()
101 gauge8.route()
102 (t8, p8) = gauge8.get_tp()
103  
3413 kaklik 104 ser.write(':DISP?\n')
3414 kaklik 105 Prefstop = eval(ser.readline(100))
3413 kaklik 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 ))
3375 kaklik 108 note = sys.stdin.readline()
3413 kaklik 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, ))
3374 kaklik 110 sys.stdout.flush()
3413 kaklik 111 # time.sleep(0.5)
112  
3374 kaklik 113 except KeyboardInterrupt:
3413 kaklik 114 ser.close()
3374 kaklik 115 sys.exit(0)
116