« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Java for LJM - Windows, Mac, Linux

LJM Java Wrapper/Examples Windows/Mac/Linux (Software Platform)

Cross-platform Java wrapper and examples for the LJM library.

Release
05/21/2015

LJM Java Wrapper/Examples (Referencable)

Prerequisites

Instructions

  1. Download/extract the .zip file attached at the top of this page.
  2. 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.
  3. 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
        java -classpath .;..\jar\jna.jar;..\jar\ljm.jar EReadName
    Mac OS X/Linux
        javac -classpath .:../jar/jna.jar:../jar/ljm.jar EReadName.java
        java -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.

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