Refactor: rename SimDUT, restructure DUT simulation and test flow
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
Power Supply controller
|
||||
|
||||
This module provides a high-level interface to control a programmable power supply.
|
||||
It supports setting voltage, enabling/disabling output, and measuring values from the supply.
|
||||
Communication is delegated to a backend (e.g., SCPI, dummy simulator).
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PowerSupply:
|
||||
def __init__(self, comm):
|
||||
"""
|
||||
Initialize the power supply interface.
|
||||
|
||||
Args:
|
||||
comm: A communication backend object that implements `write()` and `query()` methods.
|
||||
"""
|
||||
self.comm = comm
|
||||
logger.info("PowerSupply interface initialized.")
|
||||
|
||||
def set_voltage(self, voltage: float):
|
||||
"""
|
||||
Set the output voltage of the power supply.
|
||||
|
||||
Args:
|
||||
voltage: The desired voltage in volts.
|
||||
"""
|
||||
logger.debug(f"Setting voltage to {voltage:.2f}V")
|
||||
self.comm.write(f"VOLT {voltage}")
|
||||
|
||||
def enable_output(self, enable: bool):
|
||||
"""
|
||||
Enable or disable the power supply output.
|
||||
|
||||
Args:
|
||||
enable: True to enable output, False to disable.
|
||||
"""
|
||||
command = "OUTP ON" if enable else "OUTP OFF"
|
||||
logger.debug(f"Setting output state: {command}")
|
||||
self.comm.write(command)
|
||||
|
||||
def measure_voltage(self) -> float:
|
||||
"""
|
||||
Measure and return the current output voltage.
|
||||
|
||||
Returns:
|
||||
The measured voltage in volts.
|
||||
"""
|
||||
response = self.comm.query("MEAS:VOLT?")
|
||||
logger.debug(f"Measured voltage response: {response}")
|
||||
try:
|
||||
return float(response.strip())
|
||||
except ValueError:
|
||||
logger.error(f"Invalid voltage response: {response}")
|
||||
return float('nan')
|
||||
|
||||
Reference in New Issue
Block a user