VISA Codec¶
The VISA codec is included in the zeloscloud
package, and requires extras visa
to be installed.
Read these!
Much of the configuration infrastructure for defining messages and signals is shared with serial
. Read more here:
- serial codec
- serial schema
Glossary¶
VISA stands for Virtual Instrument Software Architecture.
https://en.wikipedia.org/wiki/Virtual_instrument_software_architecture
Standard Commands for Programmable Instruments
https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments
Introduction¶
Many instruments accept SCPI commands over a VISA connection. Common device types include oscilloscopes, power analyzers, grid simulators, battery simulators, and much more.
By issuing commands/queries to VISA/SCPI-compliant third party hardware, users can automate testing, fault injection, data capture, and more.
Quick Start Guide¶
This section will walk through creating and using a VisaCodec
, a VisaLink
, and the corresponding Signals
/ Messages
Basic Pytest Setup¶
To set up a basic codec, you need to initialize it with a name, link, and configuration file. Here's a quick example to get you started:
conftest.py¶
import pytest
import yaml
from zeloscloud.links.visa_link import VisaLink
from zeloscloud.codecs.visa import VisaCodec
@pytest.fixture(scope="session")
def visa_link():
"""Initialize and open a visa link."""
with VisaLink(name="link", identifier="MY_INSTRUMENT") as link:
yield link
@pytest.fixture(scope="session")
def visa_config():
"""Load the visa config yaml which defines the cmd/queries."""
with open("instrument_signals.yml", "r") as f:
config = yaml.safe_load(f)
yield config
@pytest.fixture(scope="session")
def visa_codec(visa_link, visa_config):
"""Create a serial codec with and generate all the cmd/query objects."""
with VisaCodec(name="visa_codec", link=visa_link, config=visa_config) as codec:
yield codec
def test_visa_link(visa_link, check):
check.that("MANUFACTURER NAME", "in", visa_link.query("*IDN?"))
def test_visa_codec(visa_codec, check):
check.that("MANUFACTURER NAME", "in", visa_codec.identity)
Pytest Fixtures
We are utilizing pytest fixtures to inject dependencies into our tests and setups. This method ensures that our components are modular and can be tested independently. The visa_codec
and visa_link
fixtures can also be used as standalone components.
Default SCPI Commands¶
By default, the VISA codec includes a common set of signals and message you may use out of the box. The signals and messages are defined by IEEE 488.2 Common Commands. To view more information about these commands/queries, please visit the following page:
The config file used for generating the signals/messages:
signals:
# IEEE 488.2 Common Command: *TST (Self-Test)
self_test:
query:
cmd: "*TST?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *STB (Read Status Byte)
status_byte:
query:
cmd: "*STB?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *OPC (Operation Complete)
operation_complete:
query:
cmd: "*OPC?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *ESR (Standard Event Status Register)
event_status_register:
query:
cmd: "*ESR?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *SRE (Service Request Enable)
service_request_enable:
cmd: "*SRE {}"
query:
cmd: "*SRE?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *WAI (Wait to Continue)
wait_to_continue:
cmd: "*WAI"
# IEEE 488.2 Common Command: *RQS (Request Control)
request_control:
query:
cmd: "*RQS?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *TRG (Trigger)
trigger:
cmd: "*TRG"
# IEEE 488.2 Common Command: *SRE (Status Byte Enable)
status_byte_enable:
cmd: "*SRE {}"
query:
cmd: "*SRE?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *ESE (Standard Event Status Enable)
event_status_enable:
cmd: "*ESE {}"
query:
cmd: "*ESE?"
pattern: "(\\d+)"
data_type: int
timeout_s: 10
# IEEE 488.2 Common Command: *LLO (Local Lockout)
local_lockout:
cmd: "*LLO"
# IEEE 488.2 Common Command: *GTL (Go to Local)
go_to_local:
cmd: "*GTL"
# IEEE 488.2 Common Command: *PSC (Power-On Status Clear)
power_on_status_clear:
cmd: "*PSC {}"
query:
cmd: "*PSC?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *PPC (Parallel Poll Configure)
parallel_poll_configure:
cmd: "*PPC {}"
query:
cmd: "*PPC?"
pattern: "(\\d+)"
data_type: int
# IEEE 488.2 Common Command: *DCL (Device Clear)
clear:
cmd: "*DCL"
# IEEE 488.2 Common Command: *SPD (Serial Poll Disable)
serial_poll_disable:
cmd: "*SPD"
# IEEE 488.2 Common Command: *SPE (Serial Poll Enable)
serial_poll_enable:
cmd: "*SPE"
# IEEE 488.2 Common Command: *ERR (Last Error)
last_error:
query:
cmd: "*ERR?"
pattern: "(.+)"
data_type: string
messages:
# IEEE 488.2 Common Command: *IDN (Identification)
identification:
query: "*IDN?"
signals:
manufacturer_name:
pattern: "([^,]+),"
model_number:
pattern: "[^,]+,([^,]+),"
serial_number:
pattern: "[^,]+,[^,]+,([^,]+)"
API Reference¶
See zeloscloud.codecs.visa, zeloscloud.codecs.serial.messages, and zeloscloud.codecs.serial.signals in the API Reference.