from pymeasure.instruments import Instrument
from pymeasure.instruments.validators import strict_range
from time import sleep
from numpy import linspace
class SM7045D(Instrument):
""" This is the class for the SM 70-45 D power supply.
... (code omitted for brevity) ...
"""
# Define the voltage and current ranges
VOLTAGE_RANGE = [0, 70]
CURRENT_RANGE = [0, 45]
# Define the instrument properties
voltage = Instrument.control(
"SO:VO?", "SO:VO %g",
""" A floating point property that represents the output voltage
setting of the power supply in Volts. This property can be set. """,
validator=strict_range,
values=VOLTAGE_RANGE
)
current = Instrument.control(
"SO:CU?", "SO:CU %g",
""" A floating point property that represents the output current of
the power supply in Amps. This property can be set. """,
validator=strict_range,
values=CURRENT_RANGE
)
max_voltage = Instrument.control(
"SO:VO:MA?", "SO:VO:MA %g",
""" A floating point property that represents the maximum output
voltage of the power supply in Volts. This property can be set. """,
validator=strict_range,
values=VOLTAGE_RANGE
)
max_current = Instrument.control(
"SO:CU:MA?", "SO:CU:MA %g",
""" A floating point property that represents the maximum output
current of the power supply in Amps. This property can be set. """,
validator=strict_range,
values=CURRENT_RANGE
)
measure_voltage = Instrument.measurement(
"ME:VO?",
""" Measures the actual output voltage of the power supply in
Volts. """,
)
measure_current = Instrument.measurement(
"ME:CU?",
""" Measures the actual output current of the power supply in
Amps. """,
)
rsd = Instrument.measurement(
"SO:FU:RSD?",
""" Check whether remote shutdown is enabled/disabled and thus if the
output of the power supply is disabled/enabled. """,
)
def __init__(self, adapter, name="Delta Elektronika SM 70-45 D", **kwargs):
super().__init__(
adapter,
name,
**kwargs
)
def enable(self):
"""
Disable remote shutdown, hence output will be enabled.
"""
self.write("SO:FU:RSD 0")
def disable(self):
"""
Enables remote shutdown, hence input will be disabled.
"""
self.write("SO:FU:RSD 1")
def ramp_to_current(self, target_current, current_step=0.1):
"""
Gradually increase/decrease current to target current.
:param target_current: Float that sets the target current (in A)
:param current_step: Optional float that sets the current steps
/ ramp rate (in A/s)
"""
curr = self.current
n = round(abs(curr - target_current) / current_step) + 1
for i in linspace(curr, target_current, n):
self.current = i
sleep(0.1)
def ramp_to_zero(self, current_step=0.1):
"""
Gradually decrease the current to zero.
:param current_step: Optional float that sets the current steps
/ ramp rate (in A/s)
"""
self.ramp_to_current(0, current_step)
def shutdown(self):
"""
Set the current to 0 A and disable the output of the power source.
"""
self.ramp_to_zero()
self.disable()
super().shutdown()
# Connect to the power supply
source = SM7045D("GPIB::8")
# Example usage
source.ramp_to_zero(1) # Set output to 0 before enabling
source.enable() # Enables the output
source.current = 1 # Sets a current of 1 Amps