-
Notifications
You must be signed in to change notification settings - Fork 0
Adding a new instrument class
To add support for a new instrument, follow these steps:
Inside the user_defined/instruments/ directory, create a new Python file named after the instrument, e.g., TestInstrument.py.
Inside TestInstrument.py, define a class with the same name as the file, inheriting from Instrument or another appropriate base class:
from easy_scpi import Instrument
from instruments import SCPI_Info
from config import Config
class TestInstrument(Instrument):
def __init__(self, scpi_info: SCPI_Info):
super().__init__(
port=scpi_info.port,
timeout=5000,
baud_rate=scpi_info.baud_rate,
)
self.init_properties()
def init_properties(self) -> None:
self.properties_list: List[property_info] = [
property_info(
"Voltage",
float,
lambda: self.voltp,
lambda val: setattr(self, "voltp", val),
),
]
@property
def voltp(self):
"""
Returns the voltage reading.
"""
return self.voltage()
@voltp.setter
def voltp(self, volts):
"""
Sets the voltage of the instrument.
"""
self.voltage(volts)
# Register the instrument in Config
Config().add_instrument_extension(("TestInstrumentMatch", TestInstrument))When registering the class, make sure that the string "TestInstrumentMatch" matches a subset of the IDN string. For example, if you are working with a Keithley 2000, you may want to set the key to "Model 2000" as the IDN string contains it. Don't put serial numbers here as you may have multiple instruments of the same kind.
Modify user_defined/instruments/__init__.py to include:
from .TestInstrument import TestInstrumentThe system automatically detects and instantiates the correct instrument class based on the received IDN. This is handled by the custom_instr_handler() function, which matches the IDN to registered instrument extensions key specified before.