VISA

VISA Interface module for Labtronyx

codeauthor:Kevin Kennedy
class labtronyx.interfaces.i_VISA.i_VISA(manager, **kwargs)[source]

VISA Controller

Wraps PyVISA. Requires a VISA driver to be installed on the system.

enumerate()[source]

Identify all devices known to the VISA driver and create resource objects for valid resources

open()[source]

Initialize the VISA Interface. Instantiates a VISA Resource Manager.

Returns:True if successful, False if an error occurred
openResource(resID)[source]

Attempt to open a VISA instrument. If successful, a VISA resource is added to the list of known resources and the object is returned.

Returns:object
Raises:labtronyx.ResourceUnavailable
Raises:labtronyx.InterfaceError
prune()[source]

Close any resources that are no longer known to the VISA interface

class labtronyx.interfaces.i_VISA.r_VISA(manager, resID, **kwargs)[source]

VISA Resource Base class.

Wraps PyVISA Resource Class

All VISA compliant devices will adhere to the IEEE 488.2 standard for responses to the *IDN? query. The expected format is: <Manufacturer>,<Model>,<Serial>,<Firmware>

BK Precision has a non-standard format for some of their instruments: <Model>,<Firmware>,<Serial>

Drivers derived from a VISA resource do not need to provide values for the following property attributes as they are derived from the identification string:

  • deviceVendor
  • deviceModel
  • deviceSerial
  • deviceFirmware
close()[source]

Close the resource. If a driver is loaded, that driver is also closed

Returns:True if successful, False otherwise
configure(**kwargs)[source]

Configure resource parameters to alter transmission characteristics or data interpretation

All VISA Resources

Parameters:
  • timeout (float) – Command timeout
  • write_termination (str) – Write termination
  • read_termination (str) – Read termination
  • query_delay (int) – Delay between write and read commands in a query

Serial Resources

Parameters:
  • baud_rate (int) – Serial Baudrate. Default 9600
  • data_bits (int) – Number of bits per frame. Default 8.
  • parity (str) – Data frame parity (None, Even, Odd, Mark or Space)
  • stop_bits (int) – Number of stop bits. Default 1
  • break_length (int) – Duration of the break signal in milliseconds
  • discard_null (bool) – Discard NUL characters
  • send_end (bool) – Assert END during the transfer of the last byte of data in the buffer

Resource type dependent

Parameters:
  • allow_dma (bool) – Allow DMA transfer
  • chunk_size (int) – Data chunk size
  • encoding (str) – Data encoding
getConfiguration()[source]

Get the resource configuration

Returns:dict
getIdentity(section=None)[source]

Get the comma-delimited identity string returned from *IDN? command on resource enumeration

Parameters:section (int) – Section of comma-split identity
Return type:str
getProperties()[source]

Get the property dictionary for the VISA resource.

Return type:dict[str:object]
getStatusByte()[source]

Read the Status Byte Register (STB). Interpretation of the status byte varies by instrument

Returns:
identify()[source]

Query the resource to find out what instrument it is. Uses the standard SCPI query string *IDN?. Will attempt to load a driver using the information returned.

inWaiting()[source]

Return the number of bytes in the receive buffer for a Serial VISA Instrument. All other VISA instrument types will return 0.

Returns:int
isOpen()[source]

Query the VISA resource to find if it is open

Returns:bool
lineBreak(length)[source]

Suspends character transmission and places the transmission line in a break state

Parameters:length (int) – Length of time to break
loadDriver(driverName=None, force=False)[source]

Load a Driver.

VISA supports enumeration and will thus search for a compatible driver. A driverName can be specified to load a specific driver, even if it may not be compatible with this resource. If more than one compatible driver is found, no driver will be loaded.

On startup, the resource will attempt to load a valid driver automatically. This function only needs to be called to override the default driver. unloadDriver() must be called before loading a new driver for a resource.

Parameters:driverName (str) – Driver name to load
Returns:True if successful, False otherwise
open()[source]

Open the resource and prepare to receive commands. If a driver is loaded, the driver will also be opened

Returns:True if successful, False otherwise
Raises:labtronyx.ResourceUnavailable
query(data, delay=None)[source]

Retrieve ASCII-encoded data from the device given a prompt.

A combination of write(data) and read()

Parameters:
  • data (str) – Data to send
  • delay (float) – delay (in seconds) between write and read operations.
Returns:

str

Raises:

labtronyx.ResourceNotOpen

Raises:

labtronyx.InterfaceTimeout

Raises:

labtronyx.InterfaceError

read(termination=None, encoding=None)[source]

Read ASCII-formatted data from the instrument.

Reading stops when the device stops sending, or the termination characters sequence was detected. All line-ending characters are stripped from the end of the string.

Parameters:
  • termination (str) – Line termination
  • encoding (str) – Encoding
Returns:

str

Raises:

labtronyx.ResourceNotOpen

Raises:

labtronyx.InterfaceTimeout

Raises:

labtronyx.InterfaceError

read_raw(size=None)[source]

Read Binary-encoded data directly from the instrument.

Parameters:size (int) – Number of bytes to read
Raises:labtronyx.ResourceNotOpen
Raises:labtronyx.InterfaceTimeout
Raises:labtronyx.InterfaceError
reset()[source]

Reset the instrument. Behavior varies by instrument, typically this will reset the instrument to factory default settings.

trigger()[source]

Trigger the instrument using the common trigger command *TRG. Behavior varies by instrument

write(data)[source]

Send ASCII-encoded data to the instrument. Termination character is appended automatically, according to write_termination property.

Parameters:data (str) – Data to send
Raises:labtronyx.ResourceNotOpen
Raises:labtronyx.InterfaceError
write_raw(data)[source]

Send Binary-encoded data to the instrument without modification

Parameters:data (str) – Data to send
Raises:labtronyx.ResourceNotOpen
Raises:labtronyx.InterfaceError