Instrument#
- class Instrument(
- name: str,
- publishers: list[Publisher] | None = None,
- background_config: BackgroundDaemonConfig | None = None,
- legacy_naming: bool = False,
- **kwargs,
Bases:
objectBase class for Nominal instrument interfaces. Owns publishing and the background daemon.
Initialize an Instrument.
- Parameters:
name
Channel-name prefix for published data.
publishers
Publishers that receive emitted Measurement/Command data.
background_config
Background-daemon settings; default if omitted.
legacy_naming
When True, publish channels under their pre-v1.0 names (e.g.
main.ch1_vinstead ofmain.ch1.voltagefor PSU) for dashboards or recorded datasets keyed on those names. The setting is all-or-nothing per instrument. PSU, ELoad, I2C, InstroScope, and DAQ digital channels honor the flag; the categories with no v1.0 rename (DMM, Modbus, DAQ analog and relay channels) ignore it. Scheduled for removal in v2.0.**kwargs
Default tags applied to every emitted
MeasurementorCommand. Passdataset_rid="<rid>"to auto-create a NominalCorePublisher (uses the on-disk ‘default’ Nominal credential).
Attributes
Seconds between background daemon iterations (0 = no wait).
Return an insertion-ordered snapshot of all published channel names.
Methods
Append
methodto the daemon's call list.Register a publisher to receive this instrument's Measurement/Command data.
Stop the background daemon and close every publisher.
Replace all daemon functions with a single
method(called with the given args).Return the most recent
lengthsamples forchannel_namefrom the in-memory buffer.Return the most recent sample for
channel_namefrom the in-memory buffer.No-op base hook.
Fan
dataout to every configured publisher;kwargspass through.Start the background daemon thread.
Signal the background daemon to stop and join it.
Build a single-channel
Commandnamespaced under this instrument.Build a single-channel
Measurementnamespaced under this instrument.- add_publisher(
- publisher: Publisher,
Register a publisher to receive this instrument’s Measurement/Command data.
- publish(
- data: Measurement | Command,
- **kwargs,
Fan
dataout to every configured publisher;kwargspass through.
- _package_command( ) Command[source]#
Build a single-channel
Commandnamespaced under this instrument.The published channel key is
{self.name}.{channel}. The caller writes the full descriptor including any.cmdsuffix, so the literal published name appears at the call site (e.g.f"ch{channel}.voltage.cmd").
- _package_measurement( ) Measurement[source]#
Build a single-channel
Measurementnamespaced under this instrument.The published channel key is
{self.name}.{channel}. The caller writes the full descriptor, so the literal published name appears at the call site.
- close() None[source]#
Stop the background daemon and close every publisher.
Category subclasses override to also close their transport, calling
super().close()to keep daemon and publisher cleanup running.
- property background_interval#
Seconds between background daemon iterations (0 = no wait).
- add_background_daemon_function(
- method: Callable,
- *args,
- **kwargs,
Append
methodto the daemon’s call list. Usedefine_background_daemonto replace instead.
- get_channel( ) Measurement[source]#
Return the most recent
lengthsamples forchannel_namefrom the in-memory buffer.If the channel does not exist yet, or no sample is available, the code will always block until
timeoutexpires.- Parameters:
channel_name
Name of the channel to retrieve.
length
Number of trailing samples to return.
wait_for_new_samples
Block until at least
lengthnew values arrive.timeout
Seconds to wait when insufficient data exists or
wait_for_new_samples=True.
- Raises:
RuntimeError – No background buffer;
start()was not called.ChannelNotFoundError – channel had no values and no data appeared before
timeout.wait_for_new_samples=Trueand channel did not appear withintimeout.ChannelValueTimeoutError –
wait_for_new_samples=Trueand values did not arrive withintimeout.
- get_single_channel_value(
- channel_name: str,
Return the most recent sample for
channel_namefrom the in-memory buffer.This will not wait, if data is not available then
Noneis returned.- Parameters:
channel_name
Name of the channel to retrieve.
- Raises:
RuntimeError – No background buffer;
start()was not called.
- property channel_names: tuple[str, ...]#
Return an insertion-ordered snapshot of all published channel names.
Names are complete after one full daemon iteration: {name}.loop_time publishes every iteration, so call get_channel(“loop_time”, wait_for_new_samples=True) then read channel_names to ensure the complete set has arrived.
- Raises:
RuntimeError – No background buffer;
start()was not called.