qtics.instruments package#

Instruments submodule: base classes and drivers, grouped by vendor.

Subpackages#

Submodules#

qtics.instruments.base module#

Base instrument classes.

class qtics.instruments.base.Instrument(name: str)[source]#

Bases: ABC

Base instrument class.

clear_defaults()[source]#

Clear the defaults dictionary.

abstract connect()[source]#

Connect to the instrument.

property defaults: dict#

Default values for the instrument attributes.

abstract disconnect()[source]#

Disconnect from the instrument.

get(*args) → dict[source]#

Get multiple attributes and/or properties.

reset(defaults: bool = True)[source]#

Restore the default values.

Instruments supporting a hardware reset extend this method.

set(**kwargs)[source]#

Set multiple attributes and/or properties, in the given order.

set_defaults(**kwargs)[source]#

Set the specified default values.

update_defaults(**kwargs)[source]#

Validate and update the defaults dictionary.

static validate_opt(opt: str | int, allowed: tuple)[source]#

Check that opt is one of the allowed options and return it.

static validate_range(n, n_min, n_max)[source]#

Clip n to the allowed range, warning if it was outside.

class qtics.instruments.base.MessageInstrument(transport: Transport | str, name: str = '', **transport_kwargs)[source]#

Bases: Instrument

Instrument exchanging text messages through a transport.

The transport can be given directly, or as an address string: in that case default_transport is built with transport_defaults updated by the extra keyword arguments. Nothing is opened before connect().

property address: str#

Address of the instrument.

connect()[source]#

Open the transport and run the instrument setup.

default_transport#

alias of SocketTransport

disconnect()[source]#

Run the instrument teardown and close the transport.

property is_connected: bool#

Whether the transport is open.

query(cmd: str) → Any[source]#

Send a command and read the answer.

read() → Any[source]#

Read an answer.

read_raw(n_bytes: int) → bytes[source]#

Read exactly n_bytes bytes.

transport_defaults: ClassVar[Dict[str, Any]] = {}#
write(cmd: str, sleep: bool = False)[source]#

Send a command, optionally waiting the transport delay afterwards.

class qtics.instruments.base.SCPIInstrument(transport: Transport | str, name: str = '', **transport_kwargs)[source]#

Bases: MessageInstrument

Message instrument supporting the SCPI common commands.

clear()[source]#

Clear status registers and error queue.

get_id() → str[source]#

Identification string.

property is_completed: bool#

Whether all pending operations are completed.

query(cmd: str) → str[source]#

Send a query, which must contain “?”, and read the answer.

reset(defaults: bool = True)[source]#

Reset the instrument, then restore the default values.

wait()[source]#

Execute the following commands only after the pending ones complete.

qtics.instruments.utils module#

Helpers shared by the drivers.

qtics.instruments.utils.query_binblock(inst, cmd: str, datatype: str = 'REAL,64') → ndarray[source]#

Send a query and parse the answer in IEEE 488.2 binary block format.

inst must provide data_format, write, query and read_raw. With datatype="ASC,0" the answer is parsed as comma separated values.

qtics.instruments.utils.to_bool(answer: Any) → bool[source]#

Convert an instrument on/off answer (1/0, ON/OFF, TRUE/FALSE) to bool.