VISA (Virtual Instrument Software Architecture) is an API for communicating with test & measurement instruments.
JVisa is a library for using VISA instruments in a Java program.
JVisa has been tested on Windows 7, Windows 10, Windows 11, and macOS 10.15. I think it should work on Linux too.
A small number of VISA functions been implemented, but it's definitely enough to do instrument automation.
This project is a fork of Günter Fuchs's project of the same name, which is hosted on SourceForge.
Günter set up JNAerator and Java Native Access to interact with VISA DLLs. That was a significant step forward.
However, there were some issues in the original JVisa:
- Confusing inheritance between the
JVisa
andJVisaInstrument
classes - Only one instrument can be opened at a time
- C-style error handling and output arguments
This fork of JVisa addresses those issues.
You must install a VISA implementation to use JVisa. National Instrument NI-VISA is recommended.
As far as I know, four companies have written their own VISA implementation: Keysight, National Instruments, Rohde & Schwarz, and Tektronix.
The Nation Instruments implementation appears to be the most common. For instance, PyVISA only supports NI-VISA, and Rigol software uses NI-VISA.
I tried out all four implementations and took notes and screenshots. See my comparison of VISA implementations.
You can use JitPack, visit https://jitpack.io/#xyz.froud/JVisa/2.0.0 for details.
Example for Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
...
<dependency>
<groupId>xyz.froud</groupId>
<artifactId>JVisa</artifactId>
<version>2.0.0</version>
</dependency>
Jitpack also builds and hosts Javadoc: https://javadoc.jitpack.io/xyz/froud/JVisa/2.0.0/javadoc
To manually download JVisa jar files, go to https://github.com/pfroud/JVisa/releases.
JVisa depends on the Java Native Access (JNA) library.
If you want a single jar file containing both JVisa and JNA, use JVisa-[version]-with-dependencies.jar
.
If you already have a JNA jar file, you can use JVisa-[version].jar
.
To download JNA jar files, I recommend https://mvnrepository.com/artifact/net.java.dev.jna/jna. First, click the version number of the newest version. Then, find the table row labeled "Files" and click on "jar".
Start by creating a Resource Manager:
JVisaResourceManager rm = new JVisaResourceManager();
You can search for available instruments, or you can directly open an instrument if you already know its resource name:
String[] resourcesNames = rm.findResources();
JVisaInstrument instrument = rm.openInstrument("USB0::0xFFFF::0x1234::123456789123456789::INSTR");
Examples of how to interact with the instrument:
String manufacturerName = instrument.getManufacturerName();
String modelName = instrument.getModelName();
instrument.write("source:voltage 12V");
instrument.write("output on");
String response = instrument.queryString("measure:current?");
When finished:
instrument.close();
rm.close();
The jvisa_example
folder contains a few example files:
- The file
FindResourcesExample.java
is a ready-to-run example of theResourceManager#findResources()
method. - The file
IdentificationQueryExample.java
shows how to open instruments and send a query.
There is also a small example of how to make a higher-level abstraction. The file AbstractionExample.java
shows how AbstractInstrument.java
and PowerSupplyExample.java
let you call a method like setVoltage(12)
instead of write("source:voltage 12V")
.
It is possible to run the examples directly from the jar file.
If you have a JVisa jar file which contains the JNA dependency:
java -classpath "C:\path\to\JVisa-[version]-with-dependencies.jar" xyz.froud.jvisa_example.FindResourcesExample
Otherwise, specify a path to a JNA jar file, separated with a semicolon:
java -classpath "C:\path\to\JVisa-[version].jar;C:\path\to\jna-[version].jar" xyz.froud.jvisa_example.FindResourcesExample
For documentation about the java
command, see https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html.
Here are some initialisms you might encounter when learning about test & measurement software.
-
USBTMC: USB Test & Measurement Class.
-
IVI: Interchangeable Virtual Instruments and the Foundation with the same name. Their Shared Components library
-
IEEE-488 aka GPIB: General Purpose Interface Bus. Specifies a physical connector and the signals used.
-
SCPI : Standard Commands for Programmable Instruments . Gives us command syntax like
measure:volrage:dc?
. -
LXI: LAN eXtensions for Instrumentation. Communicate with test & measurement instruments over Ethernet.
-
PXI: PCI eXtensions for Instrumentation. Communicate with test & measurement instruments over PCI. Based on CompactPCI, which is different from PCI on desktop motherboards.
-
VXI: VME eXtensions for Instrumentation. Communicate with test & measurement instruments over the VMEbus.
-
ASRL stands for asynchronous serial. When using NI-VISA on Windows, the VISA resource name to comunicate through a serial port starts with "ASRL" instead of "COM". But watch out because the ASRL number may be different from the COM number!