Instrument architecture and drivers

The instrument subsystem is built around composition and discovery:

BaseInstrument composition model

Each instrument instance contains:

  • a transport object (byte-level I/O and connection lifecycle), and

  • a protocol object (command/query formatting, response parsing, and error checks).

This keeps instrument behaviour independent from physical connection details. A single driver can be reused with different transports (for example serial, Ethernet, GPIB, or null transport for tests) as long as the protocol matches the instrument command set.

Base instrument class providing the composition of transport and protocol.

BaseInstrument is the foundation of the instrument hierarchy. Every concrete instrument class is a (possibly indirect) subclass of BaseInstrument and gains the ability to communicate with a physical instrument by holding references to a BaseTransport and a BaseProtocol instance.

BaseInstrument

Base class for all instrument drivers.

Transport layer classes for instrument communications.

Provides an abstract BaseTransport interface and concrete implementations for serial (RS-232/RS-485), Ethernet (TCP/IP socket), UDP, and GPIB connections, plus a NullTransport suitable for simulation and unit tests.

base.BaseTransport

Abstract base for all instrument transport layers.

ethernet_transport.EthernetTransport

TCP/IP socket transport for network-connected instruments.

ftdi_d2xx_transport.FtdiD2xxError

An FTDI D2XX operation failed.

ftdi_d2xx_transport.FtdiD2xxTransport

Access an FTDI device directly through the native D2XX library.

gpib_transport.GpibTransport

GPIB transport using PyVISA.

gpib_transport.PassThroughGpibTransport

Passthrough Keithley 6221 GPIB transport.

null_transport.NullTransport

Loopback transport for simulation and unit testing.

serial_transport.EchoSerialTransport

Serial transport with character-at-a-time return-echo handshaking.

serial_transport.SerialTransport

Serial-port transport using pyserial.

udp_transport.UdpTransport

UDP socket transport for network-connected instruments.

Protocol layer classes for instrument communications.

Provides an abstract BaseProtocol interface and concrete implementations for SCPI (ScpiProtocol), Oxford Instruments carriage-return-terminated (OxfordProtocol), and Lakeshore simple-ASCII (LakeshoreProtocol) protocols.

base.BaseProtocol

Abstract base for all instrument communication protocols.

ieee488.parse_ieee_block

Return the payload from a complete IEEE 488.2 binary-block response.

lakeshore.LakeshoreProtocol

Lakeshore simple ASCII CRLF-terminated protocol.

leybold.LeyboldCenterProtocol

CR-terminated Leybold CENTER THREE RS232 protocol framing.

mks.MKSPR4000Protocol

PR4000B-S compact ASCII protocol with carriage-return framing.

mks.MKSPSRProtocol

PSR-family ASCII protocol using CR for commands and CRLF replies.

modbus.ModbusRtuProtocol

Minimal protocol descriptor for Modbus RTU binary frames.

oxford.OxfordProtocol

Oxford Instruments carriage-return-terminated ASCII protocol.

scpi.ScpiProtocol

SCPI protocol — newline-terminated ASCII messages.

signal_recovery.SignalRecoveryProtocol

Format 7265 commands and remove its optional RS-232 prompt.

Driver discovery process

InstrumentDriverManager uses two discovery paths:

  1. Built-in discovery scans modules in stoner_measurement.instruments (excluding the protocol and transport subpackages) and registers non-abstract BaseInstrument subclasses.

  2. Third-party discovery loads entry points in the stoner_measurement.instruments group and registers non-abstract BaseInstrument subclasses.

Use drivers_by_type() to filter the discovered registry by an instrument base type such as TemperatureController, MagnetController, or SourceMeter.

Instrument driver discovery and filtering utilities.

Provides InstrumentDriverManager for discovering concrete instrument driver classes from the local package and third-party entry-points.

InstrumentDriverManager

Discover and provide access to concrete instrument driver classes.

Instrument hierarchy and concrete classes

Hierarchy overview:

Concrete classes currently included in the package:

The legacy Oxford ITC503 and IPS120 drivers share acknowledgement and numeric response handling through OxfordProtocol. Setting commands wait for and validate their command-letter reply, even when auto_check_errors is disabled. Q communications-mode commands and commands prefixed with $ do not wait for a reply. A rejected or malformed acknowledgement raises InstrumentError; a missing reply propagates the transport timeout. Actions are not automatically retried, since the setting may already have been applied.

Instrument driver framework for stoner_measurement.

Provides a two-layer composition architecture for communicating with laboratory instruments:

Transport layer (physical byte-level I/O):

  • BaseTransport — abstract base

  • SerialTransport — RS-232/RS-485 via pyserial

  • EthernetTransport — TCP/IP socket

  • GpibTransport — GPIB/IEEE-488 via PyVISA

  • NullTransport — loopback for testing

Protocol layer (command formatting and response parsing):

  • BaseProtocol — abstract base

  • ScpiProtocol — SCPI / IEEE 488.2

  • OxfordProtocol — Oxford Instruments CR protocol

  • LakeshoreProtocol — Lakeshore CRLF ASCII

Instrument hierarchy:

  • BaseInstrument — holds transport + protocol

  • TemperatureController — abstract type

  • MagnetController — abstract type

  • SourceMeter — abstract type

  • CurrentSource — abstract type

  • LockInAmplifier — abstract type

  • MotorController — abstract type

  • DigitalMultimeter — abstract type

  • Electrometer — abstract type

  • Nanovoltmeter — abstract type

  • NetworkAnalyser — abstract type

  • Eurotherm2000Series — concrete temperature controller

  • Eurotherm3200Series — concrete temperature controller

  • Keithley2000 — concrete DMM driver

  • Keithley2700 — concrete DMM driver

  • Keithley2182A — concrete nanovoltmeter driver

  • Keithley182 — concrete nanovoltmeter driver

  • Keithley2400 — concrete SMU driver

  • Keithley2410 — concrete SMU driver

  • Keithley2450 — concrete SMU driver

  • Keithley6221 — concrete current-source driver

  • Keithley6485 — concrete picoammeter driver

  • Keithley6514 — concrete electrometer driver

  • Keithley6517 — concrete electrometer driver

  • LakeshoreM81CurrentSource — concrete current-source driver

  • OxfordIPS120 — concrete magnet supply driver

  • OxfordMercuryIPS — concrete magnet supply driver

  • SRS830 — concrete lock-in amplifier driver

  • LakeshoreM81LockIn — concrete lock-in amplifier driver

  • ThorlabsHDR50 — concrete motor driver

  • SimulatedTemperatureController — concrete simulated temperature controller

  • SimulatedMagnetController — concrete simulated magnet controller

  • SimulatedMotorController — concrete simulated motor controller

  • ThorlabsKDC101KPRMTE — concrete motor driver

  • AgilentE5062A — concrete ENA driver

  • AgilentN5222A — concrete PNA driver

agilent.e5062a.AgilentE5062A

Agilent E5062A ENA driver using numbered channels and traces.

agilent.n5222a.AgilentN5222A

Conservative N5222A PNA driver using named-measurement selection.

current_source.CurrentSource

Abstract base class for precision current-source instruments.

current_source.CurrentSourceCapabilities

Static capability descriptor for a current-source driver.

current_source.CurrentSweepConfiguration

Configuration for a current-source sweep.

current_source.CurrentSweepSpacing

Point-spacing mode for a built-in current sweep.

current_source.CurrentWaveform

Output waveform mode of a current-source instrument.

current_source.PulsedSweepConfiguration

Pulse parameters for a pulsed current sweep.

dmm.DigitalMultimeter

Abstract base class for digital multimeter instruments.

dmm.DmmCapabilities

Static capability descriptor for a DMM driver.

dmm.DmmFunction

Measurement functions for digital multimeters.

dmm.DmmTriggerSource

Trigger-source selection for digital multimeters.

electrometer.Electrometer

Abstract base class for electrometer and picoammeter instruments.

electrometer.ElectrometerCapabilities

Static capability descriptor for an electrometer driver.

electrometer.ElectrometerDataFormat

Data transfer format used for query responses.

electrometer.ElectrometerFunction

Measurement function selected on an electrometer.

electrometer.ElectrometerTriggerConfiguration

Configuration for trigger and arm model settings.

electrometer.ElectrometerTriggerSource

Trigger source for a simple trigger model.

errors.InstrumentError

Raised when an instrument reports a command or execution error.

eurotherm.temperature_controllers.Eurotherm2000Series

Eurotherm 2000-series Modbus RTU temperature controller.

eurotherm.temperature_controllers.Eurotherm3200Series

Eurotherm 3200-series/32h8 Modbus RTU temperature controller.

leybold.pressure_controllers.LeyboldCenterThree

Driver for the Leybold CENTER THREE RS232 gauge controller.

leybold.pressure_controllers.LeyboldDisplayThree

Analogue-I/O driver facade for the Leybold DISPLAY THREE.

lockin_amplifier.LockInAmplifier

Abstract base class for lock-in amplifier instruments.

lockin_amplifier.LockInAmplifierCapabilities

Static capability descriptor for a lock-in amplifier driver.

lockin_amplifier.LockInExpandFactor

Expand factor for output offset operations.

lockin_amplifier.LockInInputCoupling

Input-coupling selection for lock-in amplifiers.

lockin_amplifier.LockInInputShielding

Input shield grounding selection for lock-in amplifiers.

lockin_amplifier.LockInInputSource

Input source selection for lock-in amplifiers.

lockin_amplifier.LockInLineFilter

Line-frequency notch filter configuration for lock-in amplifiers.

lockin_amplifier.LockInOutputChannel

Output channel selection for offset and expand operations.

lockin_amplifier.LockInReferenceSource

Reference-source selection for lock-in amplifiers.

lockin_amplifier.LockInReserveMode

Dynamic-reserve operating modes.

magnet_controller.KepcoBOPGL

Magnet-supply driver for the Kepco BOP-GL 1 kW family.

magnet_controller.MagnetController

Abstract base class for superconducting magnet power supply drivers.

magnet_controller.MagnetLimits

Operating limits for a superconducting magnet power supply.

magnet_controller.MagnetState

Operational state of a superconducting magnet power supply.

magnet_controller.MagnetStatus

Consolidated status snapshot of a magnet power supply.

mass_flow_controller.MassFlowController

Abstract base class for mass-flow controllers and readout/controllers.

mass_flow_controller.MassFlowControllerCapabilities

Static capability descriptor for mass-flow-controller drivers.

mks.controllers.MKSPR4000BS

Driver for the MKS PR4000B-S single-channel controller.

mks.controllers.MKSPSR1A

Driver for the MKS PSR1A single-channel controller.

mks.controllers.MKSPSR4A

Driver for the MKS PSR4A four-channel controller.

motor_controller.Motor

Protocol describing the expected motor interface.

motor_controller.MotorController

Abstract base class for motor controller drivers.

motor_controller.MotorStatus

Consolidated status snapshot of a motor controller.

nanovoltmeter.Nanovoltmeter

Abstract base class for nanovoltmeter instruments.

nanovoltmeter.NanovoltmeterCapabilities

Static capability descriptor for a nanovoltmeter driver.

nanovoltmeter.NanovoltmeterFunction

Measurement functions for nanovoltmeters.

nanovoltmeter.NanovoltmeterTriggerSource

Trigger-source selection for nanovoltmeters.

network_analyser.ByteOrder

SCPI binary-transfer byte orders.

network_analyser.DataEncoding

Numeric transfer encodings supported by network analysers.

network_analyser.NetworkAnalyser

Abstract base class for vector network analysers.

network_analyser.NetworkAnalyserCapabilities

Runtime capability descriptor for a network analyser.

network_analyser.NetworkAnalyserTriggerSource

Portable network-analyser trigger sources.

network_analyser.NetworkSweep

A synchronized collection of network-analyser traces.

network_analyser.NetworkTraceData

One acquired network-analyser trace.

network_analyser.SweepConfiguration

Portable configuration for one network-analyser channel.

network_analyser.SweepType

Portable network-analyser sweep modes.

network_analyser.TraceFormat

Portable display formats for network-analyser traces.

pressure_controller.PressureControllerCapabilities

Static pressure-controller capability descriptor.

pressure_controller.PressureGaugeController

Abstract base class for pressure-gauge controller instruments.

pressure_controller.PressureReading

One pressure-channel reading.

pressure_controller.PressureRelayState

Relay state reported by a pressure-gauge controller.

pressure_controller.PressureSetpoint

Relay/setpoint threshold configuration.

pressure_controller.PressureStatus

Normalised pressure-channel status.

pressure_controller.PressureUnit

Pressure units reported by supported gauge controllers.

simulated.SimulatedMagnetController

Simple simulated superconducting magnet controller.

simulated.SimulatedMassFlowController

Simple simulated mass-flow controller.

simulated.SimulatedMotorController

Simple simulated motor controller.

simulated.SimulatedPressureGaugeController

Simple simulated pressure-gauge controller.

simulated.SimulatedTemperatureController

Simple simulated temperature controller.

source_meter.MeasureFunction

Measurement function selected on an SMU.

source_meter.SourceMeter

Abstract base class for source-measure unit (SMU) instruments.

source_meter.SourceMeterCapabilities

Static capability descriptor for a source-meter driver.

source_meter.SourceMode

Source output mode of an SMU.

source_meter.SourceSweepConfiguration

Configuration for a source sweep.

source_meter.SweepSpacing

Point-spacing mode for a built-in source sweep.

source_meter.TriggerModelConfiguration

Configuration for simple trigger and arm models.

source_meter.TriggerSource

Trigger or arm source for a trigger-model configuration.

temperature_controller.AlarmState

Alarm status for a sensor channel.

temperature_controller.ControlMode

Operating mode of a PID control loop.

temperature_controller.ControllerCapabilities

Static capability descriptor for a temperature controller driver.

temperature_controller.InputChannelSettings

Configuration settings for a single sensor input channel.

temperature_controller.LoopStatus

A snapshot of one PID control loop's complete state.

temperature_controller.PIDParameters

PID gain parameters for one control loop.

temperature_controller.RampState

Whether a control loop's setpoint is currently being ramped.

temperature_controller.SensorStatus

Validity and range status of a temperature sensor reading.

temperature_controller.TemperatureController

Abstract base class for temperature controller instruments.

temperature_controller.TemperatureReading

A snapshot of a single sensor channel reading.

temperature_controller.TemperatureStatus

A full controller status snapshot.

temperature_controller.ZoneEntry

One entry in a temperature controller's zone / table control table.

thorlabs.hdr50.ThorlabsHDR50

Control an HDR50/BSC201 through direct Thorlabs APT.dll calls.

thorlabs.kdc101_kprmte.ThorlabsKDC101KPRMTE

Driver for a Thorlabs KDC101 controller with a KPRMTE servo stage.

xray.legacy_diffractometer.LegacyXrayDiffractometer

Control the two host-stepped axes and scalar counter over a byte stream.

xray.protocol.XraySnapshot

One atomic counter and two-axis position snapshot.

xray.simulated.SimulatedXrayDiffractometer

Fast, reproducible simulation of motion, snapshots and scalar counts.

xray_diffractometer.DiffractometerMechanics

Confirmed mechanics profile for both axes.

xray_diffractometer.XrayDiffractometer

Contract implemented by physical and simulated X-ray controllers.

Keithley instrument drivers.

Contains concrete drivers for Keithley source-measure units (Keithley2400, Keithley2410, Keithley2450), precision current sources (Keithley6221), digital multimeters (Keithley2000, Keithley2700), nanovoltmeters (Keithley2182A, Keithley182), and electrometers/picoammeters (Keithley6485, Keithley6514, Keithley6517).

_scpi_data_format.KeithleyByteOrder

Byte order used for Keithley IEEE-754 response data.

k182.Keithley182

Concrete driver for the non-SCPI Keithley Model 182 nanovoltmeter.

k2000.Keithley2000

Driver for the Keithley 2000 digital multimeter.

k2000.Keithley2700

Driver for the Keithley 2700 multimeter/data-acquisition system.

k2182.Keithley2182A

Driver for the Keithley 2182A nanovoltmeter.

k2400.Keithley2400

Driver for the Keithley 2400 Series SourceMeter.

k2400.Keithley2410

Driver for the Keithley 2410 SourceMeter.

k2400.Keithley2450

Driver for the Keithley 2450 SourceMeter.

k6221.Keithley6221

Driver for the Keithley 6221 precision AC/DC current source.

k651x.Keithley6514

Driver for the Keithley 6514 electrometer.

k651x.Keithley6517

Driver for the Keithley 6517 electrometer.

k651x.Keithley6485

Driver for the Keithley 6485 picoammeter.

Lakeshore instrument drivers.

current_sources.LakeshoreM81CurrentSource

Driver for the Lakeshore M81 balanced current-source outputs.

lia.LakeshoreM81LockIn

Driver for the Lakeshore M81 SSM voltage-measurement module in LIA mode.

ls625.Lakeshore625

Driver for a Lakeshore 625 superconducting magnet power supply.

temperature_controllers.Lakeshore335

Concrete driver for the Lakeshore 335 temperature controller.

temperature_controllers.Lakeshore336

Concrete driver for the Lakeshore 336 temperature controller.

temperature_controllers.Lakeshore340

Model 340 native control commands for the standard A/B input hardware.

Oxford Instruments drivers.

ips120.OxfordIPS120

Driver for an Oxford Instruments IPS120 magnet power supply.

mercury_ips.OxfordMercuryIPS

Driver for an Oxford Instruments Mercury iPS magnet power supply.

temperature_controllers.OxfordITC503

Oxford ITC503 control using the Issue 4 handbook's command set.

temperature_controllers.OxfordMercuryTemperatureController

Mercury iTC native protocol, based on the Issue 05 operator's manual.

Abstract instrument contract for two-axis X-ray diffractometers.

AxisDirection

Direction of increasing or decreasing angular coordinate.

AxisMechanics

Installation-specific mechanics for one host-stepped axis.

CountResult

A completed count with its actual monotonic elapsed time.

XrayMotionDisabledError

Motion was requested before the mechanics profile was confirmed.

XrayMotionError

Base class for rejected or unsuccessful diffractometer motion.

XrayOperationCancelled

A cooperative move or count operation was cancelled.

XrayPositionError

The measured position did not agree with the requested motion.

XrayTravelLimitError

A requested target or backlash excursion exceeded a soft limit.

cancellation_requested

Return whether a callable or event cancellation token is set.

Legacy X-ray diffractometer driver and binary protocol.

protocol.ControllerStatus

Raw and provisional status flags from snapshot bytes one and two.

protocol.LegacyXrayProtocol

Framing metadata for the controller's fixed binary response.

protocol.XrayBcdError

A snapshot contained a non-decimal packed-BCD nibble.

protocol.XrayFrameLengthError

A snapshot did not contain exactly twelve bytes.

protocol.XrayOpcode

The complete set of opcodes recovered from the legacy application.

protocol.XrayProtocolError

Base class for malformed X-ray controller data.

protocol.decode_le_bcd

Decode packed decimal pairs whose least-significant digit comes first.

protocol.decode_snapshot

Validate and decode one fixed twelve-byte response.

protocol.decode_wrapped_six_digits

Decode the controller's modulo-one-million signed representation.