New Java LJUD Wrapper and Examples for the Windows UD Library

Now available for download is the new Java LJUD wrapper and examples for the Windows UD library (LabJack U3, U6 and UE9 driver). Using JNA it provides 32 and 64-bit Java support. This replaces the old Java LJUD wrapper which used a JNI dll and only supported 32-bit Java. For full details refer to the Java LJUD download's README.txt file.

Here is a simple code demonstration to read the voltage from AIN1 on the U6 ...

import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.labjack.LJUD;
import com.labjack.LJUDException;

public class U6Ain1 {
    public U6Ain1() {
    }

    public static void main(String[] args) {
        try {
            int intHandle = 0;
            IntByReference refHandle =
                    new IntByReference(0);

            DoubleByReference refVoltage = 
                    new DoubleByReference(0.0);
            //Positive channel = 1 (AIN1)
            int posChannel = 1;
            //Negative channel = 199 (single-ended)
            int negChannel = 199;
            //Range = +/- 10V
            int range = LJUD.Constants.rgBIP10V;
            //Resolution Index = 8 (Effective resolution with 
            //                      +/- 10V range = 16 bits)
            int resolutionIndex = 1;
            //Settling = 0 (Auto)
            int settling = 0;

            //Open the first found LabJack U6.
            LJUD.openLabJack(LJUD.Constants.dtU6,
                    LJUD.Constants.ctUSB, "1", 1, refHandle);
            intHandle = refHandle.getValue();

            //Take a measurement from AIN1 and display it.
            LJUD.eAIN(intHandle, posChannel, negChannel,
                    refVoltage, range, resolutionIndex,
                    settling, 0, 0, 0);
            System.out.println("AIN" + posChannel + " = " +
                    refVoltage.getValue() + " volts");
        }
        catch(LJUDException le) {
            le.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tags: