- Notifications
You must be signed in to change notification settings - Fork15
Java library for VISA (Virtual Instrument Software Architecture) instruments
License
pfroud/JVisa
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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'sproject of the same name, which is hosted on SourceForge.
Günter set upJNAerator andJava 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 mycomparison of VISA implementations.
You can use JitPack, visithttps://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 tohttps://github.com/pfroud/JVisa/releases.
JVisa depends on theJava Native Access (JNA) library.
If you want a single jar file containing both JVisa and JNA, useJVisa-[version]-with-dependencies.jar
.
If you already have a JNA jar file, you can useJVisa-[version].jar
.
To download JNA jar files, I recommendhttps://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:
JVisaResourceManagerrm =newJVisaResourceManager();
You can search for available instruments, or you can directly open an instrument if you already know its resource name:
String[]resourcesNames =rm.findResources();JVisaInstrumentinstrument =rm.openInstrument("USB0::0xFFFF::0x1234::123456789123456789::INSTR");
Examples of how to interact with the instrument:
StringmanufacturerName =instrument.getManufacturerName();StringmodelName =instrument.getModelName();instrument.write("source:voltage 12V");instrument.write("output on");Stringresponse =instrument.queryString("measure:current?");
When finished:
instrument.close();rm.close();
Thejvisa_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 fileAbstractionExample.java
shows howAbstractInstrument.java
andPowerSupplyExample.java
let you call a method likesetVoltage(12)
instead ofwrite("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 thejava
command, seehttps://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. TheirShared 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 onCompactPCI, which is different from PCI on desktop motherboards.
VXI:VME eXtensions for Instrumentation. Communicate with test & measurement instruments over theVMEbus.
ASRLstands 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!
About
Java library for VISA (Virtual Instrument Software Architecture) instruments