/
rigolrdout
executable file
·59 lines (56 loc) · 2.99 KB
/
rigolrdout
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
#!/usr/bin/python3
# rigolrdout - Read data and screenshots from Rigol oscilloscopes
# Copyright (C) 2012-2018 Johannes Bauer
#
# This file is part of rigolrdout.
#
# rigolrdout is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; this program is ONLY licensed under
# version 3 of the License, later versions are explicitly excluded.
#
# rigolrdout is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rigolrdout; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Johannes Bauer <JohannesBauer@gmx.de>
import time
import sys
from FriendlyArgumentParser import FriendlyArgumentParser
from Connections import Connection
from RigolDriver import RigolDriver
from OutputFile import OutputFile
from StopWatch import StopWatch
parser = FriendlyArgumentParser()
parser.add_argument("-c", "--connect", metavar = "conn_str", type = str, required = True, help = "Specify where to connect to. Can be something like \"tcpip:192.168.1.4\". Currently the only supported driver is \"tcpip\". Mandatory argument.")
parser.add_argument("-f", "--output-format", choices = [ "json", "files" ], default = "files", help = "Specify output filetype. Can be one of %(choices)s, defaults to %(default)s.")
parser.add_argument("--comment", metavar = "comment", type = str, help = "Add comment to output metadata.")
parser.add_argument("--include-hardcopy", action = "store_true", help = "Include a hardcopy (screenshot) of the oscilloscope screen in the result.")
parser.add_argument("--no-serial", action = "store_true", help = "Do not include device's serial number in the metadata.")
parser.add_argument("-o", "--output", metavar = "file", type = str, required = True, help = "Specify output filename. Mandatory argument.")
parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase level of debugging verbosity.")
args = parser.parse_args(sys.argv[1:])
conn = Connection.establish(args.connect)
outfile = OutputFile(include_serial = not args.no_serial)
outfile.connection = args.connect
try:
oscilloscope = RigolDriver(conn)
outfile.instrument = oscilloscope.identification
oscilloscope.stop()
outfile.channel_info = oscilloscope.get_enabled_channel_info()
outfile.acquisition_info = oscilloscope.get_acquisition_info()
outfile.comment = args.comment
if args.include_hardcopy:
hardcopy = oscilloscope.get_display_data(img_format = "png")
outfile.add_raw_data("hardcopy", hardcopy)
for channel_id in outfile.channel_info.keys():
waveform = oscilloscope.get_waveform(channel_id)
outfile.add_raw_data("waveform-ch%d" % (channel_id), waveform)
finally:
conn.close()
outfile.write(args.output_format, args.output)