Add PSU and DMM drivers
This commit is contained in:
152
src/py_dvt_ate/instruments/drivers/power_supply.py
Normal file
152
src/py_dvt_ate/instruments/drivers/power_supply.py
Normal file
@@ -0,0 +1,152 @@
|
||||
"""Power supply SCPI driver.
|
||||
|
||||
This module implements a client-side driver for programmable power supplies
|
||||
that communicate via SCPI commands.
|
||||
"""
|
||||
|
||||
from py_dvt_ate.instruments.drivers.base import BaseDriver
|
||||
|
||||
|
||||
class PowerSupplyDriver(BaseDriver):
|
||||
"""SCPI driver for programmable power supplies.
|
||||
|
||||
Provides high-level Python API for controlling power supplies via
|
||||
SCPI commands. Implements the IPowerSupply interface.
|
||||
|
||||
Note: This driver assumes a single-channel instrument. The channel
|
||||
parameter is accepted for interface compatibility but currently ignored.
|
||||
|
||||
SCPI Commands Used:
|
||||
VOLT <value> - Set output voltage (V)
|
||||
VOLT? - Query voltage setpoint
|
||||
CURR <value> - Set current limit (A)
|
||||
CURR? - Query current limit
|
||||
OUTP <ON|OFF|1|0> - Enable/disable output
|
||||
OUTP? - Query output state (1=on, 0=off)
|
||||
MEAS:VOLT? - Measure actual output voltage
|
||||
MEAS:CURR? - Measure actual output current
|
||||
|
||||
Example:
|
||||
>>> transport = TCPTransport("localhost", 5002)
|
||||
>>> psu = PowerSupplyDriver(transport)
|
||||
>>> psu.connect()
|
||||
>>> psu.set_voltage(1, 3.3)
|
||||
>>> psu.set_current_limit(1, 0.5)
|
||||
>>> psu.enable_output(1, True)
|
||||
>>> voltage = psu.measure_voltage(1)
|
||||
"""
|
||||
|
||||
def set_voltage(self, channel: int, voltage: float) -> None:
|
||||
"""Set the output voltage setpoint.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
voltage: Target voltage in volts.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If command fails.
|
||||
"""
|
||||
self.write(f"VOLT {voltage:.3f}")
|
||||
|
||||
def get_voltage(self, channel: int) -> float:
|
||||
"""Get the voltage setpoint.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
|
||||
Returns:
|
||||
Current voltage setpoint in volts.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If query fails.
|
||||
"""
|
||||
return self.query_float("VOLT?")
|
||||
|
||||
def set_current_limit(self, channel: int, current: float) -> None:
|
||||
"""Set the current limit.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
current: Current limit in amps.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If command fails.
|
||||
"""
|
||||
self.write(f"CURR {current:.3f}")
|
||||
|
||||
def get_current_limit(self, channel: int) -> float:
|
||||
"""Get the current limit.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
|
||||
Returns:
|
||||
Current limit in amps.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If query fails.
|
||||
"""
|
||||
return self.query_float("CURR?")
|
||||
|
||||
def measure_voltage(self, channel: int) -> float:
|
||||
"""Measure the actual output voltage.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
|
||||
Returns:
|
||||
Measured voltage in volts.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If query fails.
|
||||
"""
|
||||
return self.query_float("MEAS:VOLT?")
|
||||
|
||||
def measure_current(self, channel: int) -> float:
|
||||
"""Measure the actual output current.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
|
||||
Returns:
|
||||
Measured current in amps.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If query fails.
|
||||
"""
|
||||
return self.query_float("MEAS:CURR?")
|
||||
|
||||
def enable_output(self, channel: int, enable: bool) -> None:
|
||||
"""Enable or disable the output.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
enable: True to enable output, False to disable.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If command fails.
|
||||
"""
|
||||
state = "ON" if enable else "OFF"
|
||||
self.write(f"OUTP {state}")
|
||||
|
||||
def is_output_enabled(self, channel: int) -> bool:
|
||||
"""Check if output is enabled.
|
||||
|
||||
Args:
|
||||
channel: Channel number (currently ignored, single channel assumed).
|
||||
|
||||
Returns:
|
||||
True if output is enabled, False if disabled.
|
||||
|
||||
Raises:
|
||||
ConnectionError: If not connected.
|
||||
IOError: If query fails.
|
||||
"""
|
||||
return self.query_bool("OUTP?")
|
||||
Reference in New Issue
Block a user