forked from 4x1md/sds1004x_bode
-
Notifications
You must be signed in to change notification settings - Fork 4
/
testSCPI.py
38 lines (36 loc) · 1.55 KB
/
testSCPI.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
import argparse
import pyvisa
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Test simple SCPI communication via VISA.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("port", type=str, nargs='?', default=None, help="The port to use. Must be a Visa compatible connection string.")
parser.add_argument("-n", action="store_true", default=False, help="No scan for test SCPI devices. Will be ignored when port is not defined.")
args = parser.parse_args()
rm = pyvisa.ResourceManager()
skip_scan = args.n
if not args.port:
skip_scan = False
if not skip_scan:
print("Scanning for VISA resources...")
print("VISA Resources found: ", end='')
print(rm.list_resources())
else:
print("No scan for VISA resources.")
if args.port:
print(f"Connecting to '{args.port}'")
inst = rm.open_resource(args.port, timeout=10000) # You need a large timeout when using serial AWGs
print("Connected.")
msgs = ["*IDN?",
"IDN-SGLT-PRI?",
"C1:OUTP LOAD,50;BSWV WVTP,SINE,PHSE,0,FRQ,50000,AMP,2.1,OFST,0;OUTP ON",
"C1:BSWV?",
"C1:BSWV FRQ,10"
]
for m in msgs:
if m.endswith("?"):
print(f"Query \"{m}\" reply: ", end='')
r = inst.query(m).strip()
print(f"\"{r}\"")
else:
print(f"Write \"{m}\"")
inst.write(m)