-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosc.py
executable file
·190 lines (169 loc) · 3.9 KB
/
osc.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
# wykys 2017
# program for control HMO1002 oscilloscope
import argparse
import time
import log
import SI
import SCPI
from device import Device
parser = argparse.ArgumentParser('osc')
parser.add_argument(
'-i',
'--interface',
dest='interface',
action='store',
default='uart',
choices=['uart', 'ethernet'],
help='communication interface with the device',
)
parser.add_argument(
'-p',
'--ip',
dest='ip',
action='store',
default='192.168.1.12',
help='ip address of the oscilloscope',
)
subparsers = parser.add_subparsers(help='commands')
# screenshot
parser_screenshot = subparsers.add_parser(
'screenshot',
help='save screenshot',
)
parser_screenshot.add_argument(
'screenshot',
action='store_true',
help='save screenshot',
)
parser_screenshot.add_argument(
'-f',
'--file',
dest='file',
action='store',
default='img',
help='image name, withtou siffix',
)
parser_screenshot.add_argument(
'-c',
'--color',
dest='color',
action='store',
default='color',
choices=['color', 'gray', 'invert'],
help='image colors',
)
parser_screenshot.add_argument(
'-d',
'--date',
dest='date',
action='store_true',
default=False, help='add the current date before the name'
)
# autoscale
parser_autoscale = subparsers.add_parser(
'autoscale',
help='autoscale oscilloscope'
)
parser_autoscale.add_argument(
'autoscale',
action='store_true',
help='run autoscale'
)
# time base
parser_time_base = subparsers.add_parser(
'time_base',
help='sets the horizontal scale for all channel and math waveforms'
)
parser_time_base.add_argument(
'time_base',
action='store_true',
help='sets the horizontal scale for all channel and math waveforms'
)
parser_time_base.add_argument(
'-t',
'--time',
dest='time_scale',
action='store',
default=1e-3,
help='time scale'
)
# function generator
parser_fgen = subparsers.add_parser(
'fgen',
help='function generator'
)
parser_fgen.add_argument(
'fgen',
action='store_true',
help='function generator'
)
parser_fgen.add_argument(
'-f',
'--frequency',
dest='freq',
action='store',
default='1000',
help='output frequency'
)
# auto measurement
parser_measurement = subparsers.add_parser(
'measurement',
help='starts the automatic measurement'
)
parser_measurement.add_argument(
'measurement',
action='store_true',
help='starts the automatic measurement'
)
parser_measurement.add_argument(
'-t',
'--type',
dest='type',
action='store',
default='module_and_phase_frequency_characteristics',
choices=[
'module_and_phase_frequency_characteristics',
'module_characteristic_of_both_channels',
],
help='type of measurement',
)
# export
parser_measurement = subparsers.add_parser(
'export',
help='export data'
)
parser_measurement.add_argument(
'export',
action='store_true',
help='export data'
)
args = parser.parse_args()
if args.interface == 'uart':
Device.slect_uart()
else:
Device.select_ethernet(args.ip)
if 'screenshot' in args:
if args.date:
name = time.strftime(
'%Y.%m.%d-%H:%M:%S-',
time.localtime()
) + args.file
else:
name = args.file
SCPI.screenshot(name=name, color=args.color)
elif 'autoscale' in args:
SCPI.autoscale()
elif 'time_base' in args:
SCPI.time_base(time_scale=SI.si_to_exp(args.time_scale))
elif 'fgen' in args:
SCPI.function_generator(freq=SI.si_to_exp(args.freq))
elif 'measurement' in args:
if args.type == 'module_and_phase_frequency_characteristics':
SCPI.module_and_phase_frequency_characteristics()
elif args.type == 'module_characteristic_of_both_channels':
SCPI.module_characteristic_of_both_channels()
elif 'export' in args:
SCPI.export()
else:
log.war('no any argument')