3489 |
kaklik |
1 |
#!/usr/bin/python |
|
|
2 |
|
|
|
3 |
import time |
|
|
4 |
import datetime |
|
|
5 |
import sys |
|
|
6 |
from pymlab import config |
|
|
7 |
|
|
|
8 |
#### Script Arguments ############################################### |
|
|
9 |
|
|
|
10 |
if len(sys.argv) != 2: |
|
|
11 |
sys.stderr.write("Invalid number of arguments.\n") |
|
|
12 |
sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], )) |
|
|
13 |
sys.exit(1) |
|
|
14 |
|
|
|
15 |
port = eval(sys.argv[1]) |
|
|
16 |
#### Sensor Configuration ########################################### |
|
|
17 |
|
|
|
18 |
cfg = config.Config( |
|
|
19 |
port = port, |
|
|
20 |
bus = [ |
|
|
21 |
{ |
|
|
22 |
"name": "counter", |
|
|
23 |
"type": "acount02", |
|
|
24 |
}, |
|
|
25 |
], |
|
|
26 |
) |
|
|
27 |
cfg.initialize() |
|
|
28 |
|
3492 |
kaklik |
29 |
print "Frequency counter readout example \r\n" |
3489 |
kaklik |
30 |
fcount = cfg.get_device("counter") |
|
|
31 |
time.sleep(0.5) |
3492 |
kaklik |
32 |
frequency = fcount.get_freq() |
3489 |
kaklik |
33 |
|
|
|
34 |
#### Data Logging ################################################### |
|
|
35 |
|
|
|
36 |
try: |
3492 |
kaklik |
37 |
with open("temperature.log", "a") as f: |
|
|
38 |
while True: |
|
|
39 |
now = datetime.datetime.now() |
|
|
40 |
if (now.second == 15) or (now.second == 35) or (now.second == 55): |
|
|
41 |
frequency = fcount.get_freq() |
|
|
42 |
now = datetime.datetime.now() |
3489 |
kaklik |
43 |
|
3492 |
kaklik |
44 |
sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second) + "\r") |
|
|
45 |
f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency)) |
3489 |
kaklik |
46 |
|
3492 |
kaklik |
47 |
sys.stdout.flush() |
|
|
48 |
time.sleep(1) |
3489 |
kaklik |
49 |
except KeyboardInterrupt: |
3492 |
kaklik |
50 |
sys.stdout.write("\r\n") |
3489 |
kaklik |
51 |
sys.exit(0) |
3492 |
kaklik |
52 |
f.close() |