VisaDriver#
- class VisaDriver(visa_resource: str | VisaConfig)[source]#
Bases:
TransportBaseTransport 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()/close(), and it closes only when the last owner closes it. Thread-safe at the I/O level via an internal lock; uselock()to keep a multi-step VISA sequence atomic.Construct from a VISA resource string (uses defaults) or a full
VisaConfig.Attributes
Whether the underlying VISA resource is currently open.
Methods
VISA device clear — aborts any pending operation.
Close and teardown; with a holder, remove it and tear down only when the last owner leaves.
Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it.
Open the connection (idempotent); with a holder, admit it and return True only for the first owner.
Write
commandand read the response.Send
commandand decode the IEEE-488.2 definite-length binary block reply.Write
command(with terminator) and read raw bytes — reply is not decoded or stripped.Read a response, stripping the configured read terminator.
Read raw bytes from the instrument.
Hold the lock and override the operation timeout to
timeout_msms; restored on exit (even if raises).Write
commandto the instrument; the configured write terminator is appended.Write raw bytes verbatim.
- write(command: str) None[source]#
Write
commandto the instrument; the configured write terminator is appended.
- write_raw(data: bytes) None[source]#
Write raw bytes verbatim. Caller owns framing for binary payloads.
- query_raw(command: str) bytes[source]#
Write
command(with terminator) and read raw bytes — reply is not decoded or stripped.
- query_binary_values( ) Any[source]#
Send
commandand 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_msms; 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
closebefore calling this, while the session is still up.Raises
UnknownHolderErrorwhen 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.