Labjack Installation Pre/Post 2015

Background

Since early 2011 I have used the Labjack digital I/O as a tool in test equipment for reliability testers. I started with Windows based GUI’s with custom app code written in Java. Since that time the same basic architecture was used in a half-dozen programs. The working tool chain has been Netbeans IDE and Java installed on a Windows based system. The Labjack U6 and UE9 devices were used which both have a USB interface. Prior to mid-2015 the UD library is the Windows library for the U3, U6, and UE9 and they have a Java wrapper.

The Problem

After a long pause in running these programs I found the need in 2018 to resurrect a program to perform start/stop testing on a BLDC motor (a polygon to be precise). I did not have my original tool chain but did have my Netbeans projects. I thought it would be a cinch to get this up and running in the matter of literally minutes. Boy was I wrong. What follows is what it took to get my old project working again.

A new Labjack UD library and Java wrapper were introduced starting in April 2015. On the Labjack website this is denoted as Java_LJUD_2015_04_27.zip for the new version and Old_Java_LJUD.zip for the old version. The old version uses a JNI dll and only supports 32-bit Java and UD driver. However, the new version requires JNA and supports 32 and 64-bit Java and UD driver.

Tool Chain Setup

My IDE of choice for Java is Netbeans but neither Java or the IDE were installed on my laptop. My laptop is a Windows 10 64-bit system. I headed over to Oracle and downloaded the free bundle of Netbeans 8.2 with Java SE (jdk-8u161-nb-8_2-windows-x64.exe). The installation was problem free using the default folder locations.

default install

Environment variables

In the Projects section of the Netbeans IDE right-click on Libraries and choose Add Jar/Folder and navigate to jna.jar and ljud.jar in your \NetBeansProjects\drivers\Java_LJUD_2015_04_27\Java_LJUD\jar, or whatever path you used to install the drivers.

Also in your system variables set JAVA_HOME to C:\Program Files\Java\jdk1.8.0_161 and add C:\Program Files\Java\jdk1.8.0_161\bin to your system path variable. This will allow the Netbeans project Libraries to point to JDK 1.8 as shown in the IDE.

Testing setup

Before making changes to your own code I would suggest running one of the Labjack examples. In my case I ran ‘simple.java’ in the UE9 Example folder.

  1. Create a New Project with the Name Simple
  2. Create a package folder named simple under Simple\src
  3. Copy the simple.java file to your new package folder Simple\src\simple\
  4. Edit simple.java and add the first line package simple;
  5. You should now be able to run your program from the Netbeans IDE.

The Project directory layout should look like this:

default install

Code changes

In addition to installing the updated tool-chain, changes are required to the Java code that interfaces to Labjack. There is a document here that describes the changes. The first major change worth mentioning is that rather than just returning an error code the high level IO functions now throw an exception. So most Labjack transactions need to be encapsulated in try-catch statements. See the Example files in the Labjack driver folder.

The second point worth mentioning is that Labjack constants are accessed differently. As example, using LJUD.Constants.ctUSB, instead of LJUD.LJ_ctUSB. Constants is a class containing the constants from the LJUD driver. The "LJ_" prefix have been removed from the original names.

The third point worth mentioning is with the new driver some data is passed by reference. Here is a snippet of code that looks for a UE9 before checking for a UE6.

default install

First of all the errors are caught by using a try-catch. Also note the way constants are referenced (lines 64, 68 and 72). and that that refHandle is declared as  IntByReference refHandle = new IntByReference(0); The familiar intHandle is recovered in line 66.

In Closure

After all is said and done the example files provided with the driver package are a great source to compare your old code. I just wish there was a document that explained the significance of the changes and guided one how to transition from the old to new drivers. I hope this blog helps in that arena.

The only uneasy feeling I am left with is that when I go to the Labjack forum or Google an issue related to Labjack I am never sure whether the information found is pre-2015 or 2015-forward.

The code for my project is here on Bibucket.

~Brian

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top