Rev Author Line No. Line
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 = [
3498 kakl 21 { "name":"counter", "type":"acount02"},
22 { "name":"clkgen", "type":"clkgen01"},
3489 kaklik 23 ],
24 )
25 cfg.initialize()
26  
3492 kaklik 27 print "Frequency counter readout example \r\n"
3489 kaklik 28 fcount = cfg.get_device("counter")
3498 kakl 29 fgen = cfg.get_device("clkgen")
3489 kaklik 30 time.sleep(0.5)
3492 kaklik 31 frequency = fcount.get_freq()
3498 kakl 32 rfreq = fgen.get_rfreq()
33 hsdiv = fgen.get_hs_div()
34 n1 = fgen.get_n1_div()
35 fdco = 0
36 fxtal = 0
3489 kaklik 37  
3498 kakl 38 fgen.set_rfreq(0x2D1E127AD)
39 fgen.set_hs_div(4)
40 fgen.set_n1_div(8)
41  
3489 kaklik 42 #### Data Logging ###################################################
43  
44 try:
3492 kaklik 45 with open("temperature.log", "a") as f:
46 while True:
47 now = datetime.datetime.now()
48 if (now.second == 15) or (now.second == 35) or (now.second == 55):
49 frequency = fcount.get_freq()
50 now = datetime.datetime.now()
3489 kaklik 51  
3498 kakl 52 rfreq = fgen.get_rfreq()
53 hsdiv = fgen.get_hs_div()
54 n1 = fgen.get_n1_div()
55 fdco = (frequency/1000000) * hsdiv * n1
56 fxtal = fdco / rfreq
57  
58 sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second))
59 sys.stdout.write(" RFREQ: " + str(rfreq) + " HSDIV: " + str(hsdiv) + " N1: " + str(n1))
60 sys.stdout.write(" fdco: " + str(fdco) + " fxtal: " + str(fxtal) + "\r\n")
3492 kaklik 61 f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency))
3489 kaklik 62  
3492 kaklik 63 sys.stdout.flush()
64 time.sleep(1)
3489 kaklik 65 except KeyboardInterrupt:
3492 kaklik 66 sys.stdout.write("\r\n")
3489 kaklik 67 sys.exit(0)
3492 kaklik 68 f.close()