# VisaDriver

## class VisaDriver(visa_resource: str | VisaConfig)[source]

Bases: [`TransportBase`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.transport_base.TransportBase.md#instro.lib.transports.transport_base.TransportBase "instro.lib.transports.transport_base.TransportBase")

Transport for VISA-attached instruments. Composed by concrete drivers, not extended.

Supports shared ownership: a device serving several categories holds one connection for
all of them, passing each category view as the holder to [`open()`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.open "instro.lib.transports.visa.VisaDriver.open")/[`close()`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.close "instro.lib.transports.visa.VisaDriver.close"), and
it closes only when the last owner closes it. Thread-safe at the I/O level via an internal
lock; use [`lock()`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.lock "instro.lib.transports.visa.VisaDriver.lock") to keep a multi-step VISA sequence atomic.

Construct from a VISA resource string (uses defaults) or a full `VisaConfig`.

Attributes

| [`is_open`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.is_open "instro.lib.transports.visa.VisaDriver.is_open") | Whether the underlying VISA resource is currently open. |
| --- | --- |

Methods

| [`clear`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.clear "instro.lib.transports.visa.VisaDriver.clear") | VISA device clear — aborts any pending operation. |
| --- | --- |
| [`close`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.close "instro.lib.transports.visa.VisaDriver.close") | Close and teardown; with a holder, remove it and tear down only when the last owner leaves. |
| [`lock`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.lock "instro.lib.transports.visa.VisaDriver.lock") | Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it. |
| [`open`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.open "instro.lib.transports.visa.VisaDriver.open") | Open the connection (idempotent); with a holder, admit it and return True only for the first owner. |
| [`query`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.query "instro.lib.transports.visa.VisaDriver.query") | Write `command` and read the response. |
| [`query_binary_values`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.query_binary_values "instro.lib.transports.visa.VisaDriver.query_binary_values") | Send `command` and decode the IEEE-488.2 definite-length binary block reply. |
| [`query_raw`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.query_raw "instro.lib.transports.visa.VisaDriver.query_raw") | Write `command` (with terminator) and read raw bytes — reply is not decoded or stripped. |
| [`read`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.read "instro.lib.transports.visa.VisaDriver.read") | Read a response, stripping the configured read terminator. |
| [`read_raw`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.read_raw "instro.lib.transports.visa.VisaDriver.read_raw") | Read raw bytes from the instrument. |
| [`temporary_timeout`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.temporary_timeout "instro.lib.transports.visa.VisaDriver.temporary_timeout") | Hold the lock and override the operation timeout to `timeout_ms` ms; restored on exit (even if raises). |
| [`write`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.write "instro.lib.transports.visa.VisaDriver.write") | Write `command` to the instrument; the configured write terminator is appended. |
| [`write_raw`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.visa.VisaDriver.md#instro.lib.transports.visa.VisaDriver.write_raw "instro.lib.transports.visa.VisaDriver.write_raw") | Write raw bytes verbatim. |

### property is_open: bool

Whether the underlying VISA resource is currently open.

### write(command: str) → None[source]

Write `command` to the instrument; the configured write terminator is appended.

### read() → str[source]

Read a response, stripping the configured read terminator.

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

Write `command` and read the response.

### write_raw(data: bytes) → None[source]

Write raw bytes verbatim. Caller owns framing for binary payloads.

### read_raw() → bytes[source]

Read raw bytes from the instrument.

### query_raw(command: str) → bytes[source]

Write `command` (with terminator) and read raw bytes — reply is not decoded or stripped.

### query_binary_values( command: str, datatype: str = 'B', is_big_endian: bool = False, container: type = list, ) → Any[source]

Send `command` and decode the IEEE-488.2 definite-length binary block reply.

Use for waveforms, screenshots, settings dumps.

Parameters:
:   - **command**

      SCPI query that returns a binary block (e.g. `"CURV?"`).
    - **datatype**

      `struct`-style format char (`"B"` u8, `"h"` i16, `"H"` u16, `"f"` f32).
    - **is_big_endian**

      Byte order of multi-byte elements.
    - **container**

      Container for decoded values (default `list`).

### clear() → None[source]

VISA device clear — aborts any pending operation. Use after a timed-out blocking read.

### temporary_timeout(timeout_ms: int) → Iterator[None][source]

Hold the lock and override the operation timeout to `timeout_ms` ms; restored on exit (even if raises).

### close(holder: object | None = None) → None

Close and teardown; with a holder, remove it and tear down only when the last owner leaves.

A holder that needs to talk to the instrument before the connection goes (releasing a remote
lock, say) does that in its own `close` before calling this, while the session is still up.

Raises `UnknownHolderError` when an unrecognized holder closes while others still own the
connection, because that is the case where ignoring it silently strands the real owners and
leaves the connection open forever. Once the last owner has left there is nothing to strand,
so a repeat close is a no-op and close stays idempotent.

### lock() → RLock

Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it.

### open(holder: object | None = None) → bool

Open the connection (idempotent); with a holder, admit it and return True only for the first owner.
