Java for LJM - Windows, Mac, Linux
Cross-platform Java wrapper and examples for the LJM library.
Prerequisites
A T-series LabJack Device
LJM Library - Install the LJM Library
Java 8.0 or newer. - Download from https://www.oracle.com/
JNA library - Version 5.14 included. Download from https://github.com/twall/jna
Operating system - Windows, Mac OS X, Linux
Latest Release Example Package
Up to date with LJM 1.23.2
New Changes
Added new PeriodStreamOut example.
Added T8 support to wrapper.
Instructions
Go to your device Quickstart Tutorial and follow the steps to install LabJack software and confirm basic operation.
Download/extract the .zip file attached at the top of this page.
To compile and run the Java examples use the javac compiler and java interpreter. You will need to use the "-classpath" option to add the ljm.jar and jna.jar to the build/class path.
To demonstrate, open a terminal, navigate to the Java_LJM\examples directory and run the following command for the EReadName example:
Windows:javac -classpath .;..;..\..\jar\jna.jar;..\..\jar\ljm.jar EReadName.
java -classpath .;..;..\..\jar\jna.jar;..\..\jar\ljm.jar EReadName
Mac OS X/Linux:javac -classpath .:..:../../jar/jna.jar:../../jar/ljm.jar EReadName.javajava -classpath .:..:../../jar/jna.jar:../../jar/ljm.jar EReadName
Refer to the download's README.TXT
file for requirements, compile/run instructions, documentation and license information.
Communication Basics
With the LJM library, pretty much everything you might want to do with a device is accomplished by writing and/or reading some registers. Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read, then use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers.
Code Snippet
import java.text.DecimalFormat;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.DoubleByReference;
import com.labjack.LJM;
import com.labjack.LJMException;
public class ReadSerialNumber {
public static void main(final String[] args) {
try {
IntByReference handleRef = new IntByReference(0);
int handle = 0;
//Open first found LabJack
LJM.openS("ANY", "ANY", "ANY", handleRef);
handle = handleRef.getValue();
//Call eReadName to read the serial number from the LabJack.
String name = "SERIAL_NUMBER";
DoubleByReference valueRef = new DoubleByReference(0);
LJM.eReadName(handle, name, valueRef);
System.out.println("\neReadName result: ");
System.out.println(" " + name + " = "
+ new DecimalFormat("#.#").format( valueRef.getValue() ));
}
catch (LJMException le) {
le.printStackTrace();
}
}
}
Old Versions
Download Java_LJM_2017_12_04.zip
12/04/2017
Release
Up to date with LJM version 1.16.
Added new examples.
Added T4 support to examples.
Download Java_LJM_2015_05_21.zip
05/21/2015
Release
Updated for LJM 1.0800
File List
Java_LJM_2024_05_23.zip contains:
LICENSE.txt
README.txt
doc\allclasses-frame.html
doc\allclasses-noframe.html
doc\constant-values.html
doc\deprecated-list.html
doc\help-doc.html
doc\index-all.html
doc\index.html
doc\overview-tree.html
doc\script.js
doc\serialized-form.html
doc\stylesheet.css
doc\com\labjack\LJM.Constants.html
doc\com\labjack\LJM.Errors.html
doc\com\labjack\LJM.html
doc\com\labjack\LJM.LabJackM.html
doc\com\labjack\LJMException.html
doc\com\labjack\package-frame.html
doc\com\labjack\package-summary.html
doc\com\labjack\package-tree.html
examples\LJMUtilities.java
examples\Basic\EAddresses.java
examples\Basic\ENames.java
examples\Basic\EReadAddress.java
examples\Basic\EReadAddresses.java
examples\Basic\EReadName.java
examples\Basic\EReadNames.java
examples\Basic\EWriteAddress.java
examples\Basic\EWriteAddresses.java
examples\Basic\EWriteName.java
examples\Basic\EWriteNames.java
examples\More\AIN\DualAINLoop.java
examples\More\AIN\SingleAIN.java
examples\More\AIN\SingleAINWithConfig.java
examples\More\Config\ReadConfig.java
examples\More\Config\ReadDeviceNameString.java
examples\More\Config\WriteDeviceNameString.java
examples\More\Config\WritePowerConfig.java
examples\More\DIO\SingleDIORead.java
examples\More\DIO\SingleDIOWrite.java
examples\More\DIO_EF\DioEfConfig1PwmAnd1Counter.java
examples\More\Ethernet\ReadEthernetConfig.java
examples\More\Ethernet\ReadEthernetMac.java
examples\More\Ethernet\WriteEthernetConfig.java
examples\More\I2C\I2CEeprom.java
examples\More\ListAll\ListAll.java
examples\More\SPI\SPI.java
examples\More\Stream\PeriodicStreamOut.java
examples\More\Stream\StreamBasic.java
examples\More\Stream\StreamBasicWithStreamOut.java
examples\More\Stream\StreamBurst.java
examples\More\Stream\StreamSequentialAIN.java
examples\More\Testing\CRSpeedTest.java
examples\More\Watchdog\ReadWatchdogConfig.java
examples\More\Watchdog\WriteWatchdogConfig.java
examples\More\WiFi\ReadWiFiConfig.java
examples\More\WiFi\ReadWiFiMac.java
examples\More\WiFi\ReadWiFiRssi.java
examples\More\WiFi\WriteWiFiConfig.java
jar\jna.jar
jar\ljm.jar
src\build_ljm.bat
src\Manifest.txt
src\com\labjack\LJM.java
src\com\labjack\LJMException.java