Communicating with Machines

Access and addressing

LLM-written

Connections to a machine are handled through qslib.machine.Machine. APIs that accept a machine reference also accept a hostname string when no password or other connection settings are needed.

Machine(host[, password, automatic, ...])

A QuantStudio connection.

Direct and managed transports

LLM-written (GPT-6, Fable 5, Claude Opus 5.5, and an unknown model)

Choose the backend when constructing a machine.

  • backend="scpi" (default) uses direct SCPI.

  • backend="qslib" uses qslib-server.

  • backend="auto" probes the qslib-server capabilities endpoint once during construction. A compatible API selects qslib-server. An unreachable endpoint or an HTTP 404 without a qslib-server error code selects SCPI. Authentication failures and incompatible API versions surface as errors.

Direct SCPI uses TLS on port 7443, which firmware 1.3.4 and later offers. For earlier firmware or a plaintext tunnel, pass port=7000, ssl=False. The qslib and auto modes use port 7500 by default. Set server_port to override it and server_token to supply a bearer token. The resolved backend holds for the life of the machine object. Reconnects reuse it and commands surface errors from that backend. Use a machine with the SCPI backend for raw SCPI commands.

If a mutation has an unknown outcome, QSLib raises qslib.server.ServerOutcomeUnknown with the state resource to inspect and, for idempotent operations, the key required to retry safely.

Machine.ensure_server() returns an existing ready service or deploys a supplied ARMv7 binary over a Controller SCPI connection. Call it on a SCPI machine object, then construct a qslib-backed machine for HTTP operations. See qslib-server for the service itself, and in particular for the warning that it uses unencrypted HTTP.

Connections, Access Levels, and Passwords

By default, as of 0.5.0, Machine automatically handles connections, disconnections, and, when possible (eg, for commands within qslib, rather than an arbitrary Machine.run_command()), access levels.

The QuantStudio SCPI interface controls access through passwords, which have no username associated; these passwords are each associated with a maximum access level. Each connection type (usually ethernet) also has an associated default and maximum access level with no password.

The recommended settings for QSLib, which can be set through the QSLib CLI, has a connection granted Observer access by default, and Controller access without a password.

When automatic=True, which is the default, whenever code needing a connection is run, a connection will be made, then disconnected as soon as the code is finished, if the machine wasn’t already connected. When automatic=False, connections can be handled manually through either context managers (safer) or individual commands. For clean access, the class provides a context manager for the connection, and the Machine.at_level() method provides a context manager for access level:

>>> with Machine('machine', 'password', max_access_level="Controller") as m:
>>>     # Now connected
>>>     print(m.run_status())  # runs at Observer level
>>>     with m.at_level("Controller", exclusive=True):
>>>         # Runs as Controller, and fails if another Controller is connected (exclusive)
>>>         m.abort_run()
>>>         m.drawer_open()
>>>     # Now back to Observer
>>>     print(m.status())
>>> # Now disconnected.

There is also the qslib.machine.Machine.ensured_connection() context manager, which will ensure that a connection exists at a particular access level, or arrange one if it does not. The connection context manager can also be used with with m: form for a Machine instance m that already exists, in which case it will connect and disconnect.

If you don’t want to use these, you can also use manual methods:

Machine.connect()

Connect using the selected backend.

Machine.set_access_level(access_level[, ...])

Machine.disconnect()

Close the current connection, first returning its session to Observer access.

Note that there is no supported method on the machine’s server for removing hanging connections other than a reboot, and AB’s software will not start runs when other connections hold Controller level. To correct this, you can restart the instrument’s computer with qslib.machine.Machine.restart_machine() over direct SCPI. Use machine.restart_machine(wait=True) to wait for a fresh SCPI connection to answer. By default the method refuses to reboot during a run. A reboot also stops any qslib-server process running on the instrument.

LLM-written (GPT-6)

qslib.machine.Machine.restart_system() restarts InstrumentServer and the Android framework and front-panel application while the operating system stays up. The restart briefly interrupts SCPI connections. Like restart_machine, it refuses to restart during a run unless given force=True; its documentation describes what the instrument then does with the run.

Utility commands

Machine.drawer_open()

Open the machine drawer using the OPEN command.

Machine.drawer_close([lower_cover, check])

Close the machine drawer using the OPEN command.

Machine.drawer_position

Return the drawer position from the DRAW? command.

Machine.cover_lower([check, ensure_drawer])

Lower/engage the plate cover, closing the drawer if needed.

Machine.cover_position

Return the cover position.

Machine.status

Return the current status of the run.

Machine.run_status()

Return information on the status of any run.

Machine.access_level

Machine.current_run_name

Name of current run, or None if no run is active.

Machine.abort_current_run()

Abort the current run and wait for the instrument to confirm it.

Machine.stop_current_run()

Stop the current run at the end of its current cycle.

Machine.pause_current_run()

Pause the current run now.

Machine.pause_current_run_at_temperature()

Machine.resume_current_run()

Resume the current run.

Machine.restart_system(*[, force])

Restart InstrumentServer and the Android framework and front-panel app.

Machine.restart_machine(*[, force, wait, ...])

Reboot the instrument's computer over direct SCPI with Controller access.

Machine.power

Get and set the machine's operational power (lamp, etc) as a bool.

Machine.get_timing_profile(protocol)

Query live ramp and optics timing for protocol.

Machine.get_plate_setup([run])

Read the plate setup of a run from its folder in the machine's experiments storage.

Machine.set_plate_setup(plate_setup[, run, ...])

Write the plate setup of a run to its folder in the machine's experiments storage.

Machine.get_timing_profile(protocol) reads the active block identity, directional ramp rates, and optics settings without changing the instrument. The returned TimingProfile can be passed to Protocol.estimate_timeline(). For offline block-18 vendor estimates, use TimingProfile.for_block.

Lower-level commands

Machine.run_command(command, *[, timeout])

Run a SCPI command, and return the response as a string.

Machine.run_command_to_ack(command)

Run an SCPI command and wait for its acknowledgement.