nspyre.instrument.manager
Module Contents
Classes
For consolidating connections to multiple instrument gateways. |
|
Wrapper for a device residing in an |
- class nspyre.instrument.manager.InstrumentManager(*register_gateway_args, register_gateway=True, auto_device_discovery=True, **register_gateway_kwargs)
For consolidating connections to multiple instrument gateways. If only connecting to a single
InstrumentGateway
, you can simply pass the arguments and keyword arguments that you’d normally pass to the gateway here. TheInstrumentManager
returns anInstrumentManagerDevice
when a device attribute is accessed, e.g.:from nspyre import InstrumentManager with InstrumentManager() as mgr: # let's assume "dev1" was created on the instrument server as an # instance of "MyDriver" # d is an InstrumentManagerDevice object d = mgr.dev1 # run the get_something() method of dev1 and print its return value print(d.get_something()) print(isinstance(mgr.dev1, MyDriver)) # False print(isinstance(mgr.dev1, InstrumentManagerDevice)) # True
- Parameters:
register_gateway_args – See arguments for
register_gateway()
.register_gateway (bool) – if True, call
register_gateway()
.auto_device_discovery (bool) – if True, when an attribute of the manager is accessed, but the device hasn’t been registered yet with the manager using
register_device()
, the device will be automatically registered.register_gateway_kwargs – See keyword arguments for
register_gateway()
.
- register_gateway(*gateway_args, default_exclude=False, exclude=None, name_mapping=None, **gateway_kwargs)
Create and connect to an ~nspyre.instrument.gateway.InstrumentGateway, associate it with this
InstrumentManager
, and add all of its devices to thisInstrumentManager
.- Parameters:
gateway_args – See arguments for
InstrumentGateway
.gateway_kwargs – See keyword arguments for
InstrumentGateway
.default_exclude (bool) – If True, only add those devices specified in the
name_mapping
.exclude (Optional[list[str]]) – List of device names on the
InstrumentServer
that won’t be added to theInstrumentManager
.name_mapping (Optional[Dict[str, str]]) – Keys should be the device names on the
InstrumentServer
whose values are the corresponding desired name on theInstrumentManager
. Otherwise their name on theInstrumentManager
will be the same as that on theInstrumentServer
.
- register_device(dev, name=None)
Add a device to the
InstrumentManager
.- Parameters:
dev (nspyre.instrument.gateway.InstrumentGatewayDevice) – The device to add.
name (Optional[str]) – The name of the device on the
InstrumentManager
. IfNone
, theInstrumentGatewayDevice
name will be used.
- disconnect()
Disconnect from all
InstrumentGateway
.
- class nspyre.instrument.manager.InstrumentManagerDevice(name, manager)
Wrapper for a device residing in an
InstrumentManager
. Performs similar a function as anInstrumentGatewayDevice
. See those docs for details.- Parameters:
name (str) – Name of the device on the gateway.
gateway –
InstrumentGateway
object containing the device.manager (InstrumentManager) –