From deea74b74af3fa6a7e7ad0799f6ee2c79d85cc88 Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Mon, 4 Dec 2023 09:42:25 -0800 Subject: [PATCH] docs: Add a code example of passing in config options in a dataclass via a keyword argument when initializing the `DeviceManager`. --- examples/miscellaneous/adding_devices.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/miscellaneous/adding_devices.py b/examples/miscellaneous/adding_devices.py index 0a718673..29f0108f 100644 --- a/examples/miscellaneous/adding_devices.py +++ b/examples/miscellaneous/adding_devices.py @@ -1,8 +1,25 @@ """An example of adding devices via Python code.""" from tm_devices import DeviceManager -from tm_devices.helpers import PYVISA_PY_BACKEND, SerialConfig, SYSTEM_DEFAULT_VISA_BACKEND +from tm_devices.helpers import ( + DMConfigOptions, + PYVISA_PY_BACKEND, + SerialConfig, + SYSTEM_DEFAULT_VISA_BACKEND, +) -with DeviceManager(verbose=True) as device_manager: +# Specific config options can optionally be passed in when creating +# the DeviceManager via a dataclass, they are used to update any existing +# configuration options from a config file. +CONFIG_OPTIONS = DMConfigOptions( + setup_cleanup=True, # update the value for this option, all other options will remain untouched +) + + +# Create the DeviceManager, turning on verbosity and passing in some specific configuration values. +with DeviceManager( + verbose=True, # optional argument + config_options=CONFIG_OPTIONS, # optional argument +) as device_manager: # Explicitly specify to use the system VISA backend, this is the default, # **this code is not required** to use the system default. device_manager.visa_library = SYSTEM_DEFAULT_VISA_BACKEND