-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfca3103_tool.py
More file actions
executable file
·110 lines (97 loc) · 4.92 KB
/
fca3103_tool.py
File metadata and controls
executable file
·110 lines (97 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /usr/bin/env python3
# -*- coding: utf-8 -*
'''
Terminal tool to make Time Interval measures using the Tektronix FCA3103
@file
@date Created on Sep. 16, 2015
@author Felipe Torres (torresfelipex1<AT>gmail.com)
@copyright LGPL v2.1
'''
# ----------------------------------------------------------------------------|
# GNU LESSER GENERAL PUBLIC LICENSE |
# ------------------------------------ |
# This source file is free software; you can redistribute it and/or modify it |
# under the terms of the GNU Lesser General Public License as published by the|
# Free Software Foundation; either version 2.1 of the License, or (at your |
# option) any later version. This source is distributed in the hope that it |
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warrant |
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
# General Public License for more details. You should have received a copy of |
# the GNU Lesser General Public License along with this source; if not, |
# download it from http://www.gnu.org/licenses/lgpl-2.1.html |
# ----------------------------------------------------------------------------|
# -----------------------------------------------------------------------------
# Import --
# -----------------------------------------------------------------------------
import datetime
import argparse as arg
from subprocess import check_output
from FCA3103 import FCA3103
def main() :
'''
Tool for automatize the control of Tektronix FCA3103 Timer/Counter
'''
parser = arg.ArgumentParser(description='Tektronix FCA3103 tool')
parser.add_argument('--function', '-f', help='Measuring Function', choices=['mtint','tint'],\
required=True)
parser.add_argument('--interval', '-t', help='Time between samples', type=int)
parser.add_argument('--samples', '-s', help='Number of samples', type=int, \
default=1)
parser.add_argument('--debug', '-d', help="Enable debug output", action="store_true", \
default=False)
parser.add_argument('--device', '-l', help="Device port", type=int, default=1)
parser.add_argument('--output', '-o', help='Output data file', type=str)
parser.add_argument('--ref', '-r', help='Input channel for the reference',type=int, \
choices=[1,2],default=1)
parser.add_argument('--trigl','-g',help='Input trigger level', type=float, \
default=1.5)
parser.add_argument('--skip','-i',help='Ignore values far from mean plus error',type=int, \
default=0)
parser.add_argument('--tstamp','-x', help='Add timestamping for each measure',action="store_true", \
default=False)
args = parser.parse_args()
valid_port = False
ports = check_output(["""ls /dev | grep usbtmc"""],shell=True)[:-1]
for p in ports.splitlines():
p = p.decode('utf-8')
if int(p[-1]) == args.device:
valid_port = True
if not valid_port:
print("No device found at /dev/usbtmc%d" % (args.device))
exit(6) # No such device or address
device = FCA3103(args.device, args.ref, 2 if args.ref == 1 else 1)
device.show_dbg = args.debug
device.t_samples = args.interval
device.n_samples = args.samples
device.skip_values = True if args.skip > 0 else False
device.error = args.skip
# TODO: Add de posibility of using different trigger values for the inputs
device.trig_level[0] = device.trig_level[1] = args.trigl
# try:
if args.function == 'mtint':
print("Measuring Mean Time Interval between the inputs (%d secs)..." % (args.samples))
mean = device.mean_time_interval(args.samples, args.interval)
print("Mean Time Interval for %d samples: %g" % (args.samples, mean))
elif args.function == 'tint':
print("Measuring Time Interval between the inputs (%d secs)..." % (args.samples+10))
values = device.time_interval(args.samples, tstamp=args.tstamp)
if args.output:
with open(args.output,'a+') as file:
file.write("# Time Interval Measurement (%d samples) with Tektronix FCA3103 (50ps)\n" % args.samples)
file.write("# %s\n" % datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
for v in values:
if args.tstamp:
file.write("%g\t%g\n" % (v[0], v[1]))
else:
file.write(str(v))
file.write("\n")
print("Output writed to '%s'" % (args.output))
else:
print("Time Interval Measurement (%d samples) with Tektronix FCA3103 (50ps)" % args.samples)
print("%s\n" % datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
for v in values:
print(v)
# except Exception as e:
# print(e)
if __name__ == "__main__" :
main()