-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.py
102 lines (88 loc) · 3.61 KB
/
control.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
import pyvisa as visa
class Oscilloscope:
def __init__(self, ip: str) -> None:
""" " Connect to instrument, create new Oscilloscope object"""
self.rm = visa.ResourceManager('@sim')
# self.inst = self.rm.open_resource(self.rm.list_resources()[0], read_termination='\n') # for testing purposes
self.inst = self.rm.open_resource("TCPIP0::192.168.0." + str(ip) + "::INSTR")
self.idn = self.inst.query("*IDN?")
print("connection successful \n" + "IDN: \n" + self.idn + "\n\n")
def autoscale(self) -> None:
""" " Let the instrument set its parameters automatically"""
self.inst.write("AUToscale")
print("autosc")
def get_channel_state(self, ch: int) -> int:
""" " Check if channel is displayed"""
return int(self.inst.query(":CHANnel" + str(ch) + ":DISPlay?"))
def toggle_channel_state(self, ch: int) -> None:
""" " Change whether channel is displayed or not"""
self.inst.write(
":CHANnel" + str(ch) + ":DISPlay " + str(not self.get_channel_state(ch))
)
def get_vertical_amplification(self, ch: int) -> float:
""" " Get vertical amplification value for given channel"""
return float(self.inst.query(":CHANnel" + str(ch) + ":SCALe?"))
def set_vertical_amplification(self, op: str, ch: int) -> None:
""" " Set vertical amplification value for given channel
up - increase amplification
down - decrease amplification
"""
if op == "up":
self.inst.write(
":CHANnel"
+ str(ch)
+ ":SCALe "
+ str(self.get_vertical_amplification(ch) * 1.5)
)
elif op == "down":
self.inst.write(
":CHANnel"
+ str(ch)
+ ":SCALe "
+ str(self.get_vertical_amplification(ch) / 1.5)
)
def get_vertical_offset(self, ch: int) -> float:
return float(self.inst.query(":CHANnel" + str(ch) + ":OFFSet?"))
def set_vertical_offset(self, op: str, ch: int) -> None:
if op == "up":
self.inst.write(
":CHANnel"
+ str(ch)
+ ":OFFSet "
+ str(self.get_vertical_offset(ch) * 1.5)
)
elif op == "down":
self.inst.write(
":CHANnel"
+ str(ch)
+ ":OFFSet "
+ str(self.get_vertical_offset(ch) / 1.5)
)
def get_timebase(self) -> float:
""" " Get timebase value"""
return float(self.inst.query(":TIMebase:RANGe?"))
def set_timebase(self, op: str) -> None:
""" " Set timebase value
right - decrease
left - increase
"""
if op == "left":
self.inst.write(":TIMebase:RANGe " + str(self.get_timebase() * 2))
elif op == "right":
self.inst.write(":TIMebase:RANGe " + str(self.get_timebase() / 2))
def get_horizontal_offset(self) -> float:
""" " Get value of timebase offset"""
return float(self.inst.query(":TIMebase:POSition?"))
def set_horizontal_offset(self, op: str) -> None:
""" " Set value of timebase offset"""
if op == "left":
self.inst.write(
":TIMebase:POSition " + str(self.get_horizontal_offset() / 1.5)
)
elif op == "right":
self.inst.write(
":TIMebase:POSition " + str(self.get_horizontal_offset() * 1.5)
)
def close(self) -> None:
""" " Terminate connection with instrument"""
self.inst.close()