Skip to content
/ JVisa Public

Java library for VISA (Virtual Instrument Software Architecture) instruments

License

Notifications You must be signed in to change notification settings

pfroud/JVisa

Repository files navigation

JVisa

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.

Motivation

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 and JVisaInstrument classes
  • Only one instrument can be opened at a time
  • C-style error handling and output arguments

This fork of JVisa addresses those issues.

Getting started

Install a VISA implementation

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.

Add JVisa to your project

Using build automation tools

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

Using a Jar file

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".

Basic usage

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();

Complete example code files

The jvisa_example folder contains a few example files:

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").

Run examples from jar file

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.

Glossary

Here are some initialisms you might encounter when learning about test & measurement software.

About

Java library for VISA (Virtual Instrument Software Architecture) instruments

Topics

Resources

License

Stars

Watchers

Forks

Languages