Skip to content

Commit 3bb7205

Browse files
authored
Merge pull request #9 from MideTechnology/master
Improved TDKLambdaZPlus support
2 parents ae22b46 + 3a839e4 commit 3bb7205

3 files changed

Lines changed: 310 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ nosetests.xml
3838
.mr.developer.cfg
3939
.project
4040
.pydevproject
41+
/venv*/

scpi/devices/TDKLambdaZPlus.py

Lines changed: 261 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,273 @@
33
44
@author: qmor
55
'''
6+
import decimal
7+
68
from ..scpi import SCPIDevice
79
from ..transports.tcp import TCPTransport
8-
from .generic import MultiMeter, PowerSupply
9-
class TDKLambdaZplus(PowerSupply, MultiMeter, SCPIDevice):
10-
pass
10+
from .generic import PowerSupply
11+
12+
13+
class TDKSCPI(SCPIDevice):
14+
15+
async def set_power_on_status_clear(self, setting):
16+
"""
17+
Set the Power-On Status Clear setting.
18+
* ON/1/True - This choice enables the power-on clearing of the listed registers
19+
* OFF/0/false - This choice disable the clearing of the listed registers and they retain
20+
their status when a power-on condition occurs
21+
"""
22+
setting = str(setting).upper()
23+
if setting in ("1", "ON", "TRUE"):
24+
setting = "1"
25+
elif setting in ("0", "OFF", "FALSE"):
26+
setting = "0"
27+
else:
28+
raise ValueError
29+
await super().set_power_on_status_clear(setting)
30+
31+
32+
async def restore_state(self, state):
33+
"""
34+
Restores the power supply to a state previously stored in memory by *SAV command.
35+
"""
36+
state = int(state)
37+
if state not in (1, 2, 3, 4):
38+
raise ValueError
39+
40+
await super().restore_state(state)
41+
42+
async def save_state(self, state):
43+
"""
44+
The SAV command saves all applied configuration settings.
45+
"""
46+
state = int(state)
47+
if state not in (1, 2, 3, 4):
48+
raise ValueError
49+
50+
await super().save_state(state)
51+
52+
async def power_on_state(self, setting):
53+
"""
54+
Set the power-on behavior of the system
55+
* 1 - AUTO - The power supply output will return to its previous value
56+
when the latching fault condition is removed or to the
57+
stored value after AC recycle.
58+
* 0 - SAFE - The power supply output will remain Off after the fault
59+
condition is removed or after AC recycle.
60+
"""
61+
setting = str(setting).upper()
62+
if setting in ("1", "ON", "TRUE"):
63+
setting = "1"
64+
elif setting in ("0", "OFF", "FALSE"):
65+
setting = "0"
66+
else:
67+
raise ValueError
68+
await super().power_on_state(setting)
69+
70+
71+
class TDKLambdaZplus(PowerSupply, TDKSCPI):
72+
73+
def __init__(self, protocol, use_safe_variants=True, voltage=20, current=10):
74+
"""
75+
Initialize the device with voltage [V] and current [A] limits.
76+
"""
77+
78+
self.voltage_limit = voltage
79+
self.current_limit = current
80+
81+
super().__init__(protocol, use_safe_variants=use_safe_variants)
82+
83+
async def measure_current(self, extra_params=""):
84+
"""
85+
Returns the actual output current in amps.
86+
87+
extra_params: String to append to the command. The only valid command
88+
for this device is ":DC"
89+
"""
90+
91+
resp = await self.ask("MEAS:CURR%s?" % extra_params)
92+
return decimal.Decimal(resp)
93+
94+
async def measure_voltage(self, extra_params=""):
95+
"""
96+
Returns the actual output voltage in volts.
97+
98+
extra_params: String to append to the command. The only valid command
99+
for this device is ":DC"
100+
"""
101+
102+
resp = await self.ask("MEAS:VOLT%s?" % extra_params)
103+
return decimal.Decimal(resp)
104+
105+
async def measure_power(self, extra_params=""):
106+
"""
107+
Returns the actual output power in watts.
108+
109+
extra_params: String to append to the command. The only valid command
110+
for this device is ":DC"
111+
"""
112+
113+
resp = await self.ask("MEAS:POW%s?" % extra_params)
114+
return decimal.Decimal(resp)
115+
116+
async def select_active_instrument(self, id):
117+
"""
118+
Select the power supply for communication.
119+
120+
id: the ID of the power supply to select. int from 1-31
121+
"""
122+
123+
_id = int(id)
124+
125+
if _id < 1 or id > 31:
126+
raise ValueError('id %d is outside of the valid id range' % _id)
127+
128+
await self.command("INSTrument:NSELect %d" % _id)
129+
130+
async def query_active_instrument(self):
131+
"""
132+
Returns the ID of the active instrument.
133+
"""
134+
135+
resp = await self.ask("INSTrument:NSELect?")
136+
return decimal.Decimal(resp)
137+
138+
async def couple_mode(self, couple="NONE"):
139+
"""
140+
Couple for all Z+ power supplies.
141+
"""
142+
143+
couple = couple.upper()
144+
145+
if couple in ("NONE", "ALL"):
146+
await self.command("INSTrument:COUPle %s" % couple)
147+
else:
148+
raise ValueError("Argument '%s' not valid for INST:COUP" % couple)
149+
150+
async def set_voltage_protection(self, volts):
151+
"""
152+
Set over-voltage protection level.
153+
"""
154+
155+
_volts = str(volts).upper()
156+
157+
await self.command("VOLTage:PROTection:LEVel")
158+
159+
async def query_voltage_protection(self, mode=None):
160+
"""
161+
Query the voltage protection level. Depending on mode, returns the current level, the
162+
minimum level, or the maximum level.
163+
164+
mode: Which value to return.
165+
- None (default): returns the current voltage protection level
166+
- "MAX": returns the maximum possible voltage protection level
167+
- "MIN": returns the minimum possible voltage protection level, approx. 105% the
168+
current voltage setting
169+
"""
170+
171+
if mode is None:
172+
resp = await self.ask("VOLTage:PROTection:LEVel?")
173+
else:
174+
resp = await self.ask("VOLTage:PROTection:LEVel? %s" % mode)
175+
return decimal.Decimal(resp)
176+
177+
async def flash_display(self, setting):
178+
"""
179+
Make the front panel voltage and Current displays flash.
180+
"""
181+
182+
setting = str(setting).upper()
183+
if setting in ("1", "ON", "TRUE"):
184+
setting = "1"
185+
elif setting in ("0", "OFF", "FALSE"):
186+
setting = "0"
187+
else:
188+
raise ValueError
189+
await self.command("DISPlay:FLASh %s" % setting)
190+
191+
async def global_enable(self, setting):
192+
"""
193+
Set enable status of all units.
194+
"""
195+
196+
setting = str(setting).upper()
197+
if setting in ("1", "ON", "TRUE"):
198+
setting = "1"
199+
elif setting in ("0", "OFF", "FALSE"):
200+
setting = "0"
201+
else:
202+
raise ValueError
203+
await self.command("GLOBal:OUTPut:STATe %s" % setting)
204+
205+
async def global_set_voltage(self, volts):
206+
"""
207+
Set enable status of all units.
208+
"""
209+
210+
_volts = str(volts)
211+
212+
await self.command("GLOBal:VOLTage:AMPLitude %s" % _volts)
213+
214+
async def global_reset(self):
215+
"""
216+
Reset all units.
217+
"""
218+
219+
await self.command("GLOBal:*RST")
220+
221+
async def set_voltage(self, millivolts, extra_params=""):
222+
"""
223+
Sets the desired output voltage (but does not auto-enable outputs) in
224+
millivolts, pass extra_params string to append to the command (like ":PROT")
225+
226+
Limited to five percent greater than the voltage limit of the unit.
227+
"""
228+
229+
if millivolts/1000. > 1.05*self.voltage_limit or millivolts < 0:
230+
raise ValueError
231+
232+
await super().set_voltage(millivolts, extra_params=extra_params)
233+
234+
async def set_current(self, milliamps, extra_params=""):
235+
"""
236+
Sets the desired output current (but does not auto-enable outputs) in
237+
milliamps, pass extra_params string to append to the command (like ":TRIG")
238+
239+
Limited to five percent greater than the current limit of the unit.
240+
"""
241+
242+
if milliamps/1000. > 1.05*self.current_limit or milliamps < 0:
243+
raise ValueError
244+
245+
await super().set_current(milliamps, extra_params=extra_params)
246+
11247

12248
def tcp(ip, port):
13249
"""Quick helper to connect via TCP"""
14250
from ..transports.tcp import get as get_tcp
15251
from ..scpi import SCPIProtocol
16-
transport = get_tcp(ip,port)
252+
transport = get_tcp(ip, port)
253+
protocol = SCPIProtocol(transport)
254+
dev = TDKLambdaZplus(protocol)
255+
return dev
256+
257+
258+
def serial(port, baudrate=9600):
259+
""" Quick helper to connect via serial """
260+
from ..transports.rs232 import RS232Transport
261+
from ..scpi import SCPIProtocol
262+
import serial
263+
port = serial.Serial(port,
264+
baudrate=baudrate,
265+
bytesize=8,
266+
parity=serial.PARITY_NONE,
267+
stopbits=1,
268+
xonxoff=False,
269+
rtscts=False,
270+
dsrdtr=False,
271+
timeout=10)
272+
transport = RS232Transport(port)
17273
protocol = SCPIProtocol(transport)
18274
dev = TDKLambdaZplus(protocol)
19-
return dev
275+
return dev

scpi/scpi.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,51 @@ async def trigger(self):
312312
NOTE: For GPIB devices the Group Execute Trigger is way better, use it when possible
313313
however we do not do it transparently here since it triggers all devices on the bus"""
314314
await self.command("*TRG")
315+
316+
async def clear_status(self):
317+
"""
318+
Sends a clear status command.
319+
"""
320+
await self.command("*CLS")
321+
322+
async def operation_complete(self):
323+
"""
324+
Sends an Operation Complete command.
325+
"""
326+
await self.command("*OPC")
327+
328+
async def query_options(self):
329+
"""
330+
Queries the model's options.
331+
"""
332+
await self.ask("*OPT?")
333+
334+
async def set_power_on_status_clear(self, setting):
335+
"""
336+
Set the Power-On Status Clear setting.
337+
"""
338+
await self.command("*PSC %s" % setting)
339+
340+
async def save_state(self, state):
341+
"""
342+
The SAV command saves all applied configuration settings.
343+
"""
344+
state = int(state)
345+
assert state in (1, 2, 3, 4)
346+
347+
await self.command("*SAV %d" % state)
348+
349+
async def restore_state(self, state):
350+
"""
351+
Restores the power supply to a state previously stored in memory by *SAV command.
352+
"""
353+
state = int(state)
354+
355+
await self.command("*RCL %d" % state)
356+
357+
async def power_on_state(self, setting):
358+
"""
359+
Set the power-on behavior of the system
360+
"""
361+
setting = str(setting).upper()
362+
await self.command("*OUTP:PON %s" % setting)

0 commit comments

Comments
 (0)