Adding a new device driver¶
This guide will walk through the steps needed to add a new device driver.
drivers\<device_type>[\<device_series>]\<device_driver>.py
Steps to follow¶
-
If the new device is a brand-new device type, add a new device type subpackage
-
Create the new device driver python file and class that inherits the appropriate device type/series base class
-
If the new device is part of a series (also referred to as a family), add a new series subpackage for them (e.g.
power_supplies/psu2200/) -
Create the device driver python file, create a class that inherits from the abstracted device type (or series) base class, see example. After creating the first driver that inherits from the abstracted type base class, the rest should look like the example below.
Note
For documentation to render for the new driver properly, an
__init__()method must be defined.
-
-
Update the
SupportedModelsenum exposed intm_devices/helpers/__init__.py -
Update the
___SUPPORTED_MODEL_REGEX_STRINGregex constant insidetm_devices/helpers/functions.pyto include a mapping of the new driver name (model series) to a regex string matching the appropriate model strings -
Update the
_DEVICE_DRIVER_MODEL_STR_MAPPINGlookup insidetm_devices/drivers/_device_driver_mapping.py -
Update the
__all__variable insidetm_devices/drivers/__init__.pyto include the new device driver -
If the device supports VISA USBTMC communication, update the
USB_MODEL_ID_LOOKUPlookup exposed intm_devices/helpers/__init__.py -
Update the Supported Devices section in
README.rstto include the new model -
Update unit tests (and simulated device files)
- Add a new simulated device driver in the correct folder within
tests/sim_devices - Update
tests/sim_devices/devices.yamlwith a new resource for the new driver (Make sure the device name is correct in thedevices.yamland in the corresponding simulated device file) - Update
tests/test_all_device_drivers.pywith the new simulated resource
- Add a new simulated device driver in the correct folder within
-
Run the
tests/verify_physical_device_support.pyscript targeting a physical device that will use the newly created driver to verify it is working properly.
Example of adding a new device series parent driver class¶
A device series driver parent should inherit the abstracted type base class and defines abstract functions that all device drivers must implement.
Note
The filename should be a snake-case version of the new class name. In this example
the filepath would be tm_devices/drivers/power_supplies/psu2200/new_psu.py
### drivers/power_supplies/new_series_psu/fancy_power_supply.py
"""Fancy PSU Base device driver for the new series/family of fancy power supplies."""
from abc import ABC
from tm_devices.drivers.power_supplies.power_supply import PowerSupplyUnit
from tm_devices.drivers.device import family_base_class
@family_base_class # Mark the base class for the new family of devices
class BaseFancyPSU(PowerSupplyUnit, ABC):
"""Base Fancy PSU device driver."""
# Abstracted functions for specific driver implementation goes here.
### drivers/ower_supplies/new_series_psu/fancy_psu_123.py
"""BaseFancyPSU device driver."""
from tm_devices.drivers.power_supplies.new_series_psu.fancy_power_supply import (
BaseFancyPSU,
)
class FancyPSU123(BaseFancyPSU):
"""Fancy PSU 123 device driver."""
# Specific driver implementation goes here.
A final note here, if there was no need for a “fancy” psu family series
subpackage, then the driver class can inherit directly from the device type
parent, in this example the PowerSupplyUnit class.
Example of adding a new device driver within an existing device type¶
To add a new device driver within the PowerSupply device type and PSU2200
series:
Note
The filename should be a snake-case version of the new class name. In this example
the filepath would be tm_devices/drivers/power_supplies/psu2200/new_psu.py
"""NewPSU device driver."""
from tm_devices.drivers.power_supplies.psu22xx.psu2200 import PSU2200
class NewPSU(PSU2200):
"""NewPSU device driver."""
# Specific driver implementation goes here.