InstroScope#
- class InstroScope(
- name: str | None = None,
- driver: ScopeDriverBase | None = None,
- num_channels: int | None = None,
- publishers: list[Publisher] | None = None,
- config: ScopeConfig | dict | Path | str | None = None,
- autostart: bool = False,
- **kwargs,
Bases:
InstrumentOscilloscope instrument. Tracks scope state locally; call
sync_configuration()afteropen()to refresh.Initialize an InstroScope.
Provide either
configordriver/num_channelstogether, not both.- Parameters:
name
Channel-name prefix for published data. Falls back to
config.device.namewhenconfigis given.driver
Concrete scope driver; owns its own transport:
scope = InstroScope( "scope", driver=Keysight1200X("<visa_resource>"), num_channels=4, )
num_channels
Analog-input channel count.
publishers
Publishers that receive emitted Measurement/Command data. Combined with any publishers declared in
config.config
A
ScopeConfig, a dict, or a path to a JSON config file. Itschannels,acquisition, andtriggerblocks are applied through the public setters onopen(); each channel’smeasurementsare registered as background daemon functions.autostart
When True, open the connection and start background polling. Requires
configwith at least onemeasurementsentry, since the daemon has nothing to poll otherwise.**kwargs
Default tags applied to every emitted Measurement/Command. Pass
dataset_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 daemon and publishers, then close the underlying driver.
Replace all daemon functions with a single
method(called with the given args).Fetch the acquired waveform from
channel.Force a trigger event immediately.
Query the current acquisition mode (published as a string).
Query RUNNING/STOPPED.
Query the average count.
Return the most recent
lengthsamples forchannel_namefrom the in-memory buffer.Query the input coupling mode on
channel(published as a string).Query the timebase (seconds/div).
Query the probe attenuation ratio on
channel.Query the current sample rate (Sa/s).
Return the most recent sample for
channel_namefrom the in-memory buffer.Query the trigger status (published as a string).
Query the vertical offset (volts) on
channel.Query the vertical scale (V/div) on
channel.Recall a scope setup.
Take a built-in measurement on
channel.Open the underlying driver and apply any configured initial state.
Fan
dataout to every configured publisher;kwargspass through.Start continuous acquisition.
Capture a screenshot and save it.
Save scope setup.
Set the acquisition mode (NORMAL/AVERAGE/HIRES/PEAK_DETECT/ENVELOPE).
Set the average count (waveforms averaged) used in AVERAGE acquisition mode.
Set AC/DC input coupling on
channel.Set the timebase (seconds/div).
Set the probe attenuation ratio (e.g. 1, 10, 100) on
channel.Set the trigger level (volts).
Set the trigger mode (AUTO/NORMAL).
Set the trigger edge slope (RISING/FALLING/EITHER).
Set the trigger source to
channel.Set the trigger type (EDGE, PULSE, …).
Set the vertical offset (volts) on
channel.Set the vertical scale (V/div) on
channel.Arm a single-shot acquisition.
Start the background daemon; warns when nothing is registered to poll.
Signal the background daemon to stop and join it.
Stop acquisition; records the acquisition timestamp if one was armed.
Bulk-query the instrument and overwrite the tracked
ScopeStatewith live state.- property background_interval#
Seconds between background daemon iterations (0 = no wait).
- sync_configuration() ScopeState[source]#
Bulk-query the instrument and overwrite the tracked
ScopeStatewith live state.Note that trigger source/type/level/slope/mode aren’t bulk-queried — not all scopes expose every trigger field, so call the per-field getters where supported.
- get_vertical_scale(
- channel: int,
- **kwargs,
Query the vertical scale (V/div) on
channel.
- get_vertical_offset(
- channel: int,
- **kwargs,
Query the vertical offset (volts) on
channel.
- get_coupling(
- channel: int,
- **kwargs,
Query the input coupling mode on
channel(published as a string).
- set_probe_attenuation( ) Command[source]#
Set the probe attenuation ratio (e.g. 1, 10, 100) on
channel.
- get_probe_attenuation(
- channel: int,
- **kwargs,
Query the probe attenuation ratio on
channel.
- set_horizontal_scale(
- seconds_per_div: float,
- **kwargs,
Set the timebase (seconds/div).
- get_horizontal_scale(
- **kwargs,
Query the timebase (seconds/div).
- get_sample_rate(
- **kwargs,
Query the current sample rate (Sa/s).
- set_acquisition_mode(
- mode: AcquisitionMode,
- **kwargs,
Set the acquisition mode (NORMAL/AVERAGE/HIRES/PEAK_DETECT/ENVELOPE).
- get_acquisition_mode(
- **kwargs,
Query the current acquisition mode (published as a string).
- set_average_count(
- count: int,
- **kwargs,
Set the average count (waveforms averaged) used in AVERAGE acquisition mode.
- get_average_count(
- **kwargs,
Query the average count.
- stop_acquisition(**kwargs) Command[source]#
Stop acquisition; records the acquisition timestamp if one was armed.
- get_acquisition_state(
- **kwargs,
Query RUNNING/STOPPED. If STOPPED while armed, records the acquisition timestamp.
- fetch_waveform( ) Measurement[source]#
Fetch the acquired waveform from
channel.Timestamps are ns relative to the trigger point (negative = pre-trigger). If an acquisition is armed, blocks up to
timeoutseconds for it to complete; raisesTimeoutErrorif it doesn’t.
- measure(
- measurement_type: ScopeMeasurementType,
- channel: int = 1,
- timeout: float = 5.0,
- **kwargs,
Take a built-in measurement on
channel.Timestamps default to the last recorded acquisition time (falls back to
time.time_ns()if none). If an acquisition is armed, blocks up totimeoutseconds for it to complete; raisesTimeoutErrorif it doesn’t.
- set_trigger_type(
- trigger_type: TriggerType,
- **kwargs,
Set the trigger type (EDGE, PULSE, …).
- set_trigger_slope(
- slope: TriggerSlope,
- **kwargs,
Set the trigger edge slope (RISING/FALLING/EITHER).
- set_trigger_mode(
- mode: TriggerMode,
- **kwargs,
Set the trigger mode (AUTO/NORMAL).
- get_trigger_status(
- **kwargs,
Query the trigger status (published as a string).
- save_screenshot( ) Command[source]#
Capture a screenshot and save it.
to_instrument=Truewrites to the scope’s filesystem; otherwise to the host.
- save_settings( ) Command[source]#
Save scope setup.
to_instrument=Truewrites to the scope’s filesystem; otherwise to the host.
- load_settings( ) Command[source]#
Recall a scope setup.
from_instrument=Truereads from the scope’s filesystem; otherwise from the host.Invalidates the tracked
ScopeStatesince instrument state changed externally; callsync_configuration()to refresh.
- add_background_daemon_function(
- method: Callable,
- *args,
- **kwargs,
Append
methodto the daemon’s call list. Usedefine_background_daemonto replace instead.
- add_publisher(
- publisher: Publisher,
Register a publisher to receive this instrument’s Measurement/Command data.
- 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.
- define_background_daemon(
- method: Callable,
- *args,
- **kwargs,
Replace all daemon functions with a single
method(called with the given args).
- get_channel( ) Measurement#
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.
- publish(
- data: Measurement | Command,
- **kwargs,
Fan
dataout to every configured publisher;kwargspass through.
- stop()#
Signal the background daemon to stop and join it. No-op if not running.