Getting Started - OE-FET/JISA GitHub Wiki
Set-Up Guide
This page is to show you how to set-up the necessary tools to be able to start making your own JISA
applications in Java.
1. Getting Java
The first thing to do is to download the Java Development Kit (JDK). This is the set of libraries and tools needed for compiling and running Java programs. You will need version 11 or newer.
How you do this exactly will depend on your operating system. For instance on a Linux system you might already have OpenJDK 11 installed, or just need to install it using your system's package manager, for instance on debian-based systems:
sudo apt install openjdk-11-jdk
For Windows and Mac (as well as Linux), you can download the latest release of JDK 11 from here:
https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot
2. Drivers
JISA
can use multiple different harware-level drivers to provide its instrument control features. The idea of VISA is to provide an umbrella API that covers all the commonly used communication protocol libraries (such as GPIB, COM ports, USB-TMC, etc) through one standard interface.
However, due to the most complete VISA implementation primarily being provided by National Instruments, this often fails to live up to its promise, particularly on any platform other than Windows. This is despite the various underlying libraries working just fine on their own in such situations. For this reason JISA
tries to use not just a VISA library but some of the individual communication libraries on their own if VISA fails.
Each of these is referred to as a "driver" by JISA
and the ones currently implemented are:
- National Instruments VISA Library (NI-VISA)
- Other VISA implementations should work
- Linux-GPIB (libgpib)
- National Instruments GPIB (ni4882)
- Native Serial Communications (provided by your OS)
More are planned including:
- USB-TMC (via libUSB)
- TCP-IP (via Java's own libraries)
The table below shows which drivers provide what sort of communications and on which platforms (W = Windows, M = MacOS, L = Linux). Anything from NI is probably going to be a right pain in the arse to get working (if you can at all) on anything other than Windows because it's made by NI (I hate them).
Driver | Platforms | Protocol(s) | Installation |
---|---|---|---|
NI-VISA | W, M, L | GPIB*, COM, TCP-IP, USB-TMC, PXI | W M L |
Linux-GPIB | L | GPIB | Use package manager (libgpib ) |
NI-488.2 | W, M, L | GPIB | W M L |
Serial | W, M, L | COM | No installation needed |
(* = Requires NI-488.2 to be installed)
It is therefore important that you make sure to install any of these libraries that you need to gain access to the communications protocol(s) that you want. For example, if you are only after Serial COM port communications, then you don't need to install any as JISA
can just directly access your COM ports only using the libraries provided in your operating system as standard.
If you are after, for instance, GPIB communications then you will need to install either NI-488.2 or Linux-GPIB depending on what works best for you.
3. Development Environment
The next thing to install is software designed for writing Java code. Technically, all you actually need is a text-editor like notepad, but using a full IDE like IntelliJ IDEA, Eclipse or NetBeans will make life a lot easier for you.
I would recommend IDEA. It's completely free and open-source and can be downloaded from here:
https://www.jetbrains.com/idea/download/
(Make sure to download the "Community Edition")
The set-up should be straight forward, just use the default options whenever it asks you for anything.
4. Download the JISA Library
You can download yourself a copy of the compiled JISA library from here:
https://github.com/OE-FET/JISA/raw/master/JISA.jar
Make sure you put this somewhere that you can find. If you have Java set-up properly, you should be able to run this JISA.jar
file to run an instrument control test (try it).
5. Create Project and Go!
Now everything is set-up so you can start IDEA. Upon doing so you'll be greeted with a welcome window. On it click "Create New Project":
Then when it asks what sort of project you want, just make sure "Java" is selected on the left and press "Next".
When it offers you the option to create your project from a template, tick the box and select "Command Line App".
Feel free to give your project whatever name you wish. The punnier the better, of course. When you have finished that, you will now have a very basic Java program structure open in-front of you that looks something like this:
On the right will be the automatically generated code. You will likely want to change the main
method so that it can throw exceptions by writing throws Exception
at the end of its declaration like so:
package PackageName;
public class Main {
public static void main(String[] args) throws Exception {
// write your code here
}
}
On the left you will see a file-browser showing you all the files and folders in your new project. You should be able to see that the currently open file, called Main.java
is found at src > PackageName > Main
. The files in .idea
and anything ending in .iml
are simply configuration files that IDEA uses, you can ignore these.
Now what you want to do is put your copy of JISA.jar
into your project. You can do this by dragging it into the file list on the left.
Now that the JISA.jar
file is within your project folder, you can add it as a library by right-clicking on it and selecting the "Add as Library..." option, then just press "OK".
That's it! You're now ready to write your code. To run it, just press the green "play" button on the toolbar at the top.
For example, let's connect to a Keithley 2450 SMU and read out voltage every 5 seconds:
package org.something.packagename;
import jisa.devices.K2450;
import jisa.addresses.GPIBAddress;
import jisa.Util;
public class Main {
public static void main(String[] args) throws Exception {
K2450 smu = new K2450(new GPIBAddress(0, 15));
while (true) {
double voltage = smu.getVoltage();
System.out.printf("Voltage = %e V\n", voltage);
Util.sleep(5000);
}
}
}
which results in the voltage being output to the terminal every 5 seconds like so:
Voltage = 4.312E-4 V
Voltage = 4.323E-4 V
Voltage = 4.401E-4 V
...