Example Code/Wrappers | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


Example Code/Wrappers


Example code is a great way to get started writing a custom code.

LJM Example Code Table

LJM Example Code Table HTML (Referencable)

Example Code/Wrappers: LJM Library

T7 T4 Digit

T7, T4, Digit


Examples In... Windows Mac Linux
.NET (C#, VB)    
Visual Basic (VB6, VBA)    
Agilent VEE    


Embedded Lua Scripts

While the above examples are run on the host computer, there are also example Lua scripts which run on-board T-series devices.

Modbus TCP

There are also direct Modbus TCP examples that do not use LJM. Note that some features, such as streaming, are greatly simplified by the LJM library. A list of the available Modbus registers is available on the Modbus Map page.

Digit (End of life)

Example code specifically tailored to the Digit-TL/Digit-TLH can be found in the appendix-b section of the Digit's datasheet.

UD Example Code Table

Example Code/Wrappers: UD Library

U3 U6 UE9

U3, U6, UE9

Examples In... Windows Mac Linux

Modbus TCP Example Code Table

Modbus TCP Example Code Table (Referencable)

Direct Modbus TCP Example Code

T7 T4

T7, T4

Libraries... Windows Mac Linux
C/C++ (Streaming)

To use a 3rd party Modbus program, such as a Rockwell/Allen Bradley application, follow the instructions on the Modbus Client Applications page.

More information about Modbus as well as some getting started information can be found on the Modbus API Documentation page. A list of the available Modbus registers is available on the Modbus Map page.

UE9 Native TCP Example Code Table (Referencable)

UE9 Native TCP Example Code



Libraries... Windows Mac Linux

The UE9 is also compatible with the direct Modbus TCP examples. A list of the available modbus registers that the UE9 supports is available in the UD Modbus section.

Note that some features, such as streaming, are simplified by the UD library.

Lua Scripting on T7/T4 Devices

Example Code: Lua Scripting On T7/T4

Lua Scripts run on the device rather than on a computer. This allows for unique control of T-series devices. It's especially useful for time-sensitive applications, digital communication, and standalone operation. The included examples are a great place to start writing a custom program. Lua scripts can use USER_RAM registers to pass data into other programs.

Lua scripts are uploaded to the T-series device through Kipling, which makes Lua scripting possible across all platforms (Windows, macOS, and Linux).


Emanuele Reggiani's picture


I am currently using the U6 with a raspberry pi2, firmware updated, libusb installed, built C modules and installed wrappers for python. All works.

Still, I have some simple USB routines based on the usb.core python libraries and I would like to send simple sequence of bytes. The have been tested with other devices and they work.

For example, the AIN24 command  like:

[0x86,0xF8, 0x03, 0x00, 0x8a, 0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x00]

is supposed to read a differential input (channel 0 and 1) with gain index 0 (x1) and precision index 8.

Checksum are verified and received packet is as shown:

[0xCA, 0xF8, 0x03, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x04,0x8a]

How should the last bytes be treated to get to a voltage reading?


labjack support's picture

First, take a look at the AIN24 low-level documentation. The last 3-bytes in your response is the 24-bit reading as described in the 3-byte response part of that page. Convert those bytes to the 24-bit binary value, and then apply the appropriate calibration constants to get the voltage. So something like this with your response bytes to get the 24-bit value:

binValue = (bytes[11] << 16 ) + (bytes[10] << 8 ) + bytes[9]

For code on getting and applying the calibration contants that converts the binary value reading to a voltage, look at the getCalibrationData and binaryToCalibratedAnalogVoltage methods in the u6.py source code. Also, the Exodriver provides low-level example code which may be helpful.

shih cheng pang's picture


I have a UE9 device. Can I use two programs to read the same UE9 on the same computer? 

labjack support's picture

We do not recommend talking to the device in multiple processes at once unless you have a particularly good reason to. That said, you could connect to the device in two separate processes if you use Ethernet connections. You can only obtain the USB connection in one process at a time, but you should be able to use USB in one program and Ethernet in another.

Mark-225's picture

I have a T7, in the past i have experienced some ethernet drop outs. Is there a way to reconnect, programatically if the connection is restored?  Right now the device will not until every thing is restarted, including power cycling the T7.

labjack support's picture

Our LJM library supports connection healing, so you should typically be able to start communicating with the device when the connection is restored. The following page has some recommendations for avioding LJME_RECONNECT_FAILED errors:


Another option could be to configure the software watchdog so that the device automatically restarts after a disconnect lasts a certain duration: