aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
authorMichael Vorobiov <mvorobiov@wm.edu>2024-11-05 16:17:01 -0500
committerMichael Vorobiov <mvorobiov@wm.edu>2024-11-05 16:17:01 -0500
commit97ebffd0fd0d62b25200f26aa911313d6cb754d7 (patch)
tree3b2a3ad652a222ed4bf736d7029b73005cb46f56 /qolab
parent5e9ee1520e1117ec09b7092c2227ea556e10c034 (diff)
downloadqolab-97ebffd0fd0d62b25200f26aa911313d6cb754d7.tar.gz
qolab-97ebffd0fd0d62b25200f26aa911313d6cb754d7.zip
added minimally working driver for GWInstek PSW250-4.5 power supply
Diffstat (limited to 'qolab')
-rw-r--r--qolab/hardware/power_supply/psw25045.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/qolab/hardware/power_supply/psw25045.py b/qolab/hardware/power_supply/psw25045.py
new file mode 100644
index 0000000..f6080bb
--- /dev/null
+++ b/qolab/hardware/power_supply/psw25045.py
@@ -0,0 +1,139 @@
+"""
+Module: GW INSTEK GPP-250-4.5 power supply unit control
+Description: This module provides a class to interface with the GW INSTEK GPP250-4.5 power
+ supply unit (PSU) using pyvisa for setting current and voltage on the PSU
+
+Author: Mykhailo Vorobiov
+Email: mvorobiov@wm.edu
+Date: 2024-10-02
+Update: 2024-11-05
+"""
+
+from qolab.hardware.power_supply._basic import PowerSupplySCPI
+import pyvisa
+
+class PSW25045(PowerSupplySCPI):
+ """
+ A class for interfacing with GW INSTEK GPP250-4.5
+ signle channel power supply unit.
+ """
+ def __init__(self, resource, *args, **kwds):
+ """
+ Initialize the PSU class.
+ """
+ super().__init__(resource, *args, **kwds)
+ self.resource = resource
+
+ self.config["Device model"] = "GWInstek PSW 250-4.5"
+ self.numberOfChannels = 2
+ self.deviceProperties.update({"OpMode"})
+ self.resource.read_termination = "\n"
+
+ self.MAX_CURRENT = 4.5 # Amp
+ self.MAX_VOLTAGE = 250.0 # Volt
+ self.enable_output(False)
+
+ def get_idn(self):
+ """
+ Query the identification of the instrument.
+
+ :return: Identifier string if query is successful or None otherwise.
+ """
+ try:
+ return self.query('*IDN?').strip()
+ except pyvisa.VisaIOError as e:
+ print(f'[ERROR!] Error retrieving identification: {e}')
+ return None
+
+
+ def get_current_meas(self):
+ """
+ Query the current reading of the instrument.
+
+ :return: Current reading in amps as float number and None if error occurs.
+ """
+
+ try:
+ return float(self.query('MEAS:CURR?'))
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error querying the current reading: {e}")
+ return None
+
+ def get_voltage_meas(self):
+ """
+ Query the voltage reading of the instrument.
+
+ :return: Voltage reading in volts as float number and None if error occurs.
+ """
+
+ try:
+ return float(self.query('MEAS:VOLT?'))
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error querying the voltage reading: {e}")
+ return None
+
+ def get_power_meas(self):
+ """
+ Query the power reading of the instrument.
+
+ :return: Power reading in watts as float number and None if error occurs.
+ """
+
+ try:
+ return float(self.query('MEAS:POWE?'))
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error querying the power reading: {e}")
+ return None
+
+
+
+ def set_current(self, current):
+ """
+ Set the target current output of the instrument.
+ """
+
+ if current <= self.MAX_CURRENT and current >= 0.0:
+ try:
+ self.write(f'SOUR:CURR {current}')
+ print(f"Current is set to {current} V")
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error setting the current target output: {e}")
+ else:
+ print(f"[WARNING] Target current must be between 0 and {self.MAX_CURRENT} Amps."
+ f"\n\tThe traget current left unchanged.")
+
+
+ def set_voltage(self, voltage):
+ """
+ Set the target voltage output of the instrument.
+ """
+ if voltage <= self.MAX_VOLTAGE and voltage >= 0.0:
+ try:
+ self.write(f'SOUR:VOLT {voltage}')
+ print(f"[INFO] Voltage is set to {voltage} V")
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error setting the voltage target output: {e}")
+ else:
+ print(f"[WARNING] Target voltage must be between 0 and {self.MAX_VOLTAGE} Volts."
+ f"\n\tThe traget voltage left unchanged.")
+
+ def enable_output(self, output_state=False):
+ """
+ Set the output state of the instrument ON or OFF.
+
+ :param output_state: Boolean flag. Sets the output ON if 'True' or OFF if 'False'.
+ """
+ try:
+ if self.output_state:
+ self.write(f'OUTP:STAT 1')
+ self.output_state = output_state
+ print(f"[INFO] Output is ON")
+ else:
+ self.write(f'OUTP:STAT 0')
+ self.output_state = not(output_state)
+ print(f"[INFO] Output is OFF")
+ except pyvisa.VisaIOError as e:
+ print(f"[ERROR!] Error toggle the output: {e}")
+
+
+