Line 8... |
Line 8... |
8 |
import datetime |
8 |
import datetime |
9 |
import sys |
9 |
import sys |
10 |
import os |
10 |
import os |
11 |
|
11 |
|
12 |
from pymlab import config |
12 |
from pymlab import config |
- |
|
13 |
from mlabutils import ejson |
- |
|
14 |
|
- |
|
15 |
parser = ejson.Parser() |
13 |
|
16 |
|
14 |
#### Script Arguments ############################################### |
17 |
#### Script Arguments ############################################### |
15 |
|
18 |
|
16 |
if len(sys.argv) != 3: |
19 |
if len(sys.argv) != 3: |
17 |
sys.stderr.write("Invalid number of arguments.\n") |
20 |
sys.stderr.write("Invalid number of arguments.\n") |
18 |
sys.stderr.write("Usage: %s PORT_ADDRESS SAMPLE_INTERVAL\n" % (sys.argv[0], )) |
21 |
sys.stderr.write("Usage: %s PORT_ADDRESS CONFIG_FILE\n" % (sys.argv[0], )) |
19 |
sys.exit(1) |
22 |
sys.exit(1) |
20 |
|
23 |
|
21 |
|
24 |
|
- |
|
25 |
port = eval(sys.argv[1]) |
- |
|
26 |
|
- |
|
27 |
value = parser.parse_file(sys.argv[2]) |
- |
|
28 |
path = value['data_path'] |
- |
|
29 |
interval = value['raw_sample_interval'] |
- |
|
30 |
stationName = value['origin'] |
- |
|
31 |
|
22 |
|
32 |
|
23 |
port = eval(sys.argv[1]) |
- |
|
24 |
interval = eval(sys.argv[2]) |
- |
|
25 |
|
33 |
|
26 |
if (interval<5) or (interval>3600): |
34 |
if (interval<5) or (interval>3600): |
27 |
sys.stderr.write("Invalid sample interval arguments.\n") |
35 |
sys.stderr.write("Invalid sample interval arguments.\n") |
28 |
sys.stderr.write("The interval has to be in the range from 5 to 3600 seconds\n") |
36 |
sys.stderr.write("The interval has to be in the range from 5 to 3600 seconds\n") |
29 |
sys.exit(2) |
37 |
sys.exit(2) |
Line 47... |
Line 55... |
47 |
}, |
55 |
}, |
48 |
], |
56 |
], |
49 |
) |
57 |
) |
50 |
cfg.initialize() |
58 |
cfg.initialize() |
51 |
|
59 |
|
52 |
print "Current loop sensor example \r\n" |
60 |
sys.stdout.write("Current loop sensor example \r\n") |
53 |
print "Time, channel #1, channel #2, channel #3 , channel #4, channel #5 \r\n" |
61 |
sys.stdout.write("Time, channel #1, channel #2, channel #3 , channel #4, channel #5 \r\n") |
54 |
sensor1 = cfg.get_device("current_sensor1") |
62 |
sensor1 = cfg.get_device("current_sensor1") |
55 |
sensor2 = cfg.get_device("current_sensor2") |
63 |
sensor2 = cfg.get_device("current_sensor2") |
56 |
#time.sleep(0.5) |
64 |
#time.sleep(0.5) |
57 |
|
65 |
|
58 |
#### Data Logging ################################################### |
66 |
#### Data Logging ################################################### |
59 |
|
67 |
|
60 |
try: |
68 |
try: |
61 |
before = time.time()-interval |
69 |
before = time.time()-interval |
62 |
while True: |
70 |
while True: |
63 |
|
71 |
|
64 |
filename = time.strftime("%Y%m%d%H", time.gmtime())+".csv" |
72 |
filename = path + time.strftime("%Y%m%d%H", time.gmtime()) +"_"+ stationName + "_data.csv" |
65 |
now = time.time() |
73 |
now = time.time() |
66 |
|
74 |
|
67 |
if (now - before >= interval - 2.5): # 0.5*5 channels= 2.5s |
75 |
if (now - before >= interval - 2.5): # 0.5*5 channels= 2.5s |
68 |
with open(filename, "a") as f: |
76 |
with open(filename, "a") as f: |
69 |
|
77 |
|