C/C++ examples for the LJM library. Also contains some header files:
LJM_Utilities.h
- contains useful functions
stream/LJM_StreamUtilities.h
- contains useful stream functions
LabJackMModbusMap.h
- contains declarations for register addresses, names, and types
Prerequisites
Subsections
Latest Release Example Package
Latest Release Example Package
Updated for LJM 1.2001.
c_c_ljm_2019-05-20.zip
New changes
LJM_StreamUtilities.h: Renamed CountAndOutputNumSkippedScans -> CountAndOutputNumSkippedSamples.
LJM_Utilities.h: Added Get().
Added cstring header to sd_util.hpp. Fixes CentOS 6 compilation.
Minor URL updates.
Latest Beta Example Package
Latest Beta Example Package
Updated for LJM 1.2100.
c_c_ljm_2021-08-20_0.zip ←Click to Download
New changes
Updated thermocouple_example.c
Added macro to define PrintAndLog function (to use PrintAndLog, set env variable LABJACK_DEBUG_LOG_OUTPUT to 1) requires C99 or newer standard
LJM_Utilities.h error checking functions pause for 100 ms before exiting so the debug logger can finish outputting.
Added more/lua folder
Moved lua_script_basic.c from more/utilities to more/lua
Added a Lua execution control example to more/lua
Added stream out examples to more/stream.
- periodic_stream_out.cpp
- stream_in_with_aperiodic_stream_out.cpp
- Renamed stream_in_with_stream_out.cpp to advanced_aperiodic_stream_out.cpp
GitHub
Our latest example changes are available in our GitHub repository.
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.
Navigate to the extracted LabJackM
folder.
Open and run .c
/.cpp
source files using your code editor of choice.
Windows
Newer versions of Visual Studio work with these .sln
and .vcproj
files, though you will need to run the automatic upgrade process when opening them.
For Visual Studio 2017, you may get the following error:
Error C1083 Cannot open include file: 'stdio.h': No such file or directory
In this case, you need to switch the project SDK version from 8.1 to 10:
Open the Properties
window for the project (e.g. in the Solution Explorer, right click on the project - not the solution)
Change Configuration Properties
→ General
→ Target Platform Version
to something like 10.0.14393.0
Mac/Linux
On Mac/Linux, the .zip format unfortunately removes the execution permissions from the build scripts. To use the examples on Mac/Linux, you may need to apply executable permissions. For example:
tar zxvf C_C++_LJM_2019-05-20.zip
cd C_C++_LJM_2019-05-20
chmod a+x make_all.sh basic/make.sh more/*/make.sh scons-local-2.5.1/scons.py
LJM Overview
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. The following examples in the Basic folder are a great place to start:
Where is an example to do XYZ?
You will find lots of examples in this archive, but there is not an example for everything the LabJack can do. The reason for this stems from the "Overview" section above. Most operations simply involve writing and reading different registers, so you really just need examples that show you how to write and read any register. If we had examples for every operation, they would just be copies of the example "Write Read Loop with Config" with different registers. The typical workflow to do almost anything beside stream is:
Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read.
Use the Register Matrix in Kipling to test writing and reading your desired registers and confirm you see what you expect to see. This step is optional and not always applicable.
Use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers. Or just use "Write Read Loop with Config", which provides the basic structure used by many user applications.
Stream mode and other operations that don't fit in "Write Read Loop with Config" will usually have specific examples, and if something seems to be missing let us know.
Compiling
To compile a C or C++ program that uses LJM see the compilation instructions, which include instructions for compiling programs including:
Code Snippet
#include <stdio.h>
#include <LabJackM.h>
#include "LJM_Utilities.h"
// Available in the C/C++ examples download. Provides the ErrorCheck function.
int main()
{
int err, handle;
double value = 0;
const char * NAME = {"SERIAL_NUMBER"};
// Open first found LabJack
err = LJM_Open(LJM_dtANY, LJM_ctANY, "LJM_idANY", &handle);
ErrorCheck(err, "LJM_Open");
// Call LJM_eReadName to read the serial number from the LabJack.
err = LJM_eReadName(handle, NAME, &value);
ErrorCheck(err, "LJM_eReadName");
printf("eReadName result:\n");
printf(" %s = %f\n", NAME, value);
// Close device handle
err = LJM_Close(handle);
ErrorCheck(err, "LJM_Close");
return LJME_NOERROR;
}
File list
c_c_ljm_2019-05-20.zip contains
README
scons-local-2.5.1/scons.py (as well as SConstruct files for each example folder)
CHANGES.txt
LabJackMModbusMap.h
LJM_StreamUtilities.h
LJM_Utilities.h
make_all.sh
basic\eAddresses.c
basic\eAddresses.exe
basic\eNames.c
basic\eNames.exe
basic\eReadAddress.c
basic\eReadAddress.exe
basic\eReadAddresses.c
basic\eReadAddresses.exe
basic\eReadName.c
basic\eReadName.exe
basic\eReadNames.c
basic\eReadNames.exe
basic\eWriteAddress.c
basic\eWriteAddress.exe
basic\eWriteAddresses.c
basic\eWriteAddresses.exe
basic\eWriteName.c
basic\eWriteName.exe
basic\eWriteNames.c
basic\eWriteNames.exe
basic\make.sh
basic\write_read_loop_with_config.c
basic\write_read_loop_with_config.exe
more\1-wire\1-wire.c
more\1-wire\1-wire.exe
more\1-wire\make.sh
more\ain\dual_ain_loop.c
more\ain\dual_ain_loop.exe
more\ain\make.sh
more\ain\single_ain.c
more\ain\single_ain.exe
more\ain\single_ain_with_config.c
more\ain\single_ain_with_config.exe
more\asynch\make.sh
more\asynch\uart_loopback_test.c
more\asynch\uart_loopback_test.exe
more\config\make.sh
more\config\read_config.c
more\config\read_config.exe
more\config\read_device_name_string.c
more\config\read_device_name_string.exe
more\config\write_device_name_string.c
more\config\write_device_name_string.exe
more\config\write_power_config.c
more\config\write_power_config.exe
more\dio\make.sh
more\dio\single_dio_read.c
more\dio\single_dio_read.exe
more\dio\single_dio_write.c
more\dio\single_dio_write.exe
more\dio_ef\dio_ef_config_1_pwm_and_1_counter.c
more\dio_ef\dio_ef_config_1_pwm_and_1_counter.exe
more\dio_ef\make.sh
more\ethernet\make.sh
more\ethernet\read_ethernet_config.c
more\ethernet\read_ethernet_config.exe
more\ethernet\read_ethernet_mac.c
more\ethernet\read_ethernet_mac.exe
more\ethernet\write_ethernet_config.c
more\ethernet\write_ethernet_config.exe
more\i2c\i2c_eeprom.c
more\i2c\i2c_eeprom.exe
more\i2c\make.sh
more\list_all\list_all.c
more\list_all\list_all.exe
more\list_all\list_all_extended.c
more\list_all\list_all_extended.exe
more\list_all\make.sh
more\sd\change_directory.cpp
more\sd\change_directory.exe
more\sd\delete_file.cpp
more\sd\delete_file.exe
more\sd\get_disk_info.cpp
more\sd\get_disk_info.exe
more\sd\list_directory.cpp
more\sd\list_directory.exe
more\sd\make.sh
more\sd\print_working_directory.cpp
more\sd\print_working_directory.exe
more\sd\read_file.cpp
more\sd\read_file.exe
more\sd\sd_util.hpp
more\spi\make.sh
more\spi\spi.c
more\spi\spi.exe
more\stream\make.sh
more\stream\stream_basic.c
more\stream\stream_basic.exe
more\stream\stream_basic_with_stream_out.c
more\stream\stream_basic_with_stream_out.exe
more\stream\stream_burst.c
more\stream\stream_burst.exe
more\stream\stream_callback.c
more\stream\stream_callback.exe
more\stream\stream_external_clock.c
more\stream\stream_external_clock.exe
more\stream\stream_out_only.c
more\stream\stream_out_only.exe
more\stream\stream_out_update.c
more\stream\stream_out_update.exe
more\stream\stream_sequential_ain.c
more\stream\stream_sequential_ain.exe
more\stream\stream_triggered.c
more\stream\stream_triggered.exe
more\testing\auto_reconnect_test.c
more\testing\auto_reconnect_test.exe
more\testing\c-r_speed_test.c
more\testing\c-r_speed_test.exe
more\testing\externally_clocked_stream_test.c
more\testing\externally_clocked_stream_test.exe
more\testing\make.sh
more\testing\stream_burst_test.c
more\testing\stream_burst_test.exe
more\testing\system_reboot_test.c
more\testing\system_reboot_test.exe
more\testing\write_read_loop_with_config_speed_test_eNames.c
more\testing\write_read_loop_with_config_speed_test_eNames.exe
more\utilities\device_info.c
more\utilities\device_info.exe
more\utilities\error.c
more\utilities\error.exe
more\utilities\lua_script_basic.c
more\utilities\lua_script_basic.exe
more\utilities\make.sh
more\utilities\names_to_addresses.c
more\utilities\names_to_addresses.exe
more\utilities\raw_bytes.c
more\utilities\raw_bytes.exe
more\utilities\read_cal.c
more\utilities\read_cal.exe
more\utilities\read_ljm_config.c
more\utilities\read_ljm_config.exe
more\utilities\set_timeout.cpp
more\utilities\set_timeout.exe
more\utilities\stepwise_feedback.c
more\utilities\stepwise_feedback.exe
more\utilities\t7_tcp_configure.c
more\utilities\t7_tcp_configure.exe
more\utilities\thermocouple_example.c
more\utilities\thermocouple_example.exe
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.c
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.exe
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.sln
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.vcproj
more\watchdog\make.sh
more\watchdog\read_watchdog_config.c
more\watchdog\read_watchdog_config.exe
more\watchdog\write_watchdog_config.c
more\watchdog\write_watchdog_config.exe
more\wifi\make.sh
more\wifi\read_wifi_config.c
more\wifi\read_wifi_config.exe
more\wifi\read_wifi_mac.c
more\wifi\read_wifi_mac.exe
more\wifi\read_wifi_rssi.c
more\wifi\read_wifi_rssi.exe
more\wifi\write_wifi_config.c
more\wifi\write_wifi_config.exe
visual_studio_2008\basic\eAddresses\eAddresses.sln
visual_studio_2008\basic\eAddresses\eAddresses.vcproj
visual_studio_2008\basic\eNames\eNames.sln
visual_studio_2008\basic\eNames\eNames.vcproj
visual_studio_2008\basic\eReadAddress\eReadAddress.sln
visual_studio_2008\basic\eReadAddress\eReadAddress.vcproj
visual_studio_2008\basic\eReadAddresses\eReadAddresses.sln
visual_studio_2008\basic\eReadAddresses\eReadAddresses.vcproj
visual_studio_2008\basic\eReadName\eReadName.sln
visual_studio_2008\basic\eReadName\eReadName.vcproj
visual_studio_2008\basic\eReadNames\eReadNames.sln
visual_studio_2008\basic\eReadNames\eReadNames.vcproj
visual_studio_2008\basic\eWriteAddress\eWriteAddress.sln
visual_studio_2008\basic\eWriteAddress\eWriteAddress.vcproj
visual_studio_2008\basic\eWriteAddresses\eWriteAddresses.sln
visual_studio_2008\basic\eWriteAddresses\eWriteAddresses.vcproj
visual_studio_2008\basic\eWriteName\eWriteName.sln
visual_studio_2008\basic\eWriteName\eWriteName.vcproj
visual_studio_2008\basic\eWriteNames\eWriteNames.sln
visual_studio_2008\basic\eWriteNames\eWriteNames.vcproj
visual_studio_2008\basic\write_read_loop_with_config\write_read_loop_with_config.sln
visual_studio_2008\basic\write_read_loop_with_config\write_read_loop_with_config.vcproj
visual_studio_2008\more\1-wire\1-wire\1-wire.sln
visual_studio_2008\more\1-wire\1-wire\1-wire.vcproj
visual_studio_2008\more\ain\dual_ain_loop\dual_ain_loop.sln
visual_studio_2008\more\ain\dual_ain_loop\dual_ain_loop.vcproj
visual_studio_2008\more\ain\single_ain\single_ain.sln
visual_studio_2008\more\ain\single_ain\single_ain.vcproj
visual_studio_2008\more\ain\single_ain_with_config\single_ain_with_config.sln
visual_studio_2008\more\ain\single_ain_with_config\single_ain_with_config.vcproj
visual_studio_2008\more\asynch\uart_loopback_test\uart_loopback_test.sln
visual_studio_2008\more\asynch\uart_loopback_test\uart_loopback_test.vcproj
visual_studio_2008\more\config\read_config\read_config.sln
visual_studio_2008\more\config\read_config\read_config.vcproj
visual_studio_2008\more\config\read_device_name_string\read_device_name_string.sln
visual_studio_2008\more\config\read_device_name_string\read_device_name_string.vcproj
visual_studio_2008\more\config\write_device_name_string\write_device_name_string.sln
visual_studio_2008\more\config\write_device_name_string\write_device_name_string.vcproj
visual_studio_2008\more\config\write_power_config\write_power_config.sln
visual_studio_2008\more\config\write_power_config\write_power_config.vcproj
visual_studio_2008\more\dio\single_dio_read\single_dio_read.sln
visual_studio_2008\more\dio\single_dio_read\single_dio_read.vcproj
visual_studio_2008\more\dio\single_dio_write\single_dio_write.sln
visual_studio_2008\more\dio\single_dio_write\single_dio_write.vcproj
visual_studio_2008\more\dio_ef\dio_ef_config_1_pwm_and_1_counter\dio_ef_config_1_pwm_and_1_counter.sln
visual_studio_2008\more\dio_ef\dio_ef_config_1_pwm_and_1_counter\dio_ef_config_1_pwm_and_1_counter.vcproj
visual_studio_2008\more\ethernet\read_ethernet_config\read_ethernet_config.sln
visual_studio_2008\more\ethernet\read_ethernet_config\read_ethernet_config.vcproj
visual_studio_2008\more\ethernet\read_ethernet_mac\read_ethernet_mac.sln
visual_studio_2008\more\ethernet\read_ethernet_mac\read_ethernet_mac.vcproj
visual_studio_2008\more\ethernet\write_ethernet_config\write_ethernet_config.sln
visual_studio_2008\more\ethernet\write_ethernet_config\write_ethernet_config.vcproj
visual_studio_2008\more\i2c\i2c_eeprom\i2c_eeprom.sln
visual_studio_2008\more\i2c\i2c_eeprom\i2c_eeprom.vcproj
visual_studio_2008\more\list_all\list_all\list_all.sln
visual_studio_2008\more\list_all\list_all\list_all.vcproj
visual_studio_2008\more\list_all\list_all_extended\list_all_extended.sln
visual_studio_2008\more\list_all\list_all_extended\list_all_extended.vcproj
visual_studio_2008\more\sd\change_directory\change_directory.sln
visual_studio_2008\more\sd\change_directory\change_directory.vcproj
visual_studio_2008\more\sd\delete_file\delete_file.sln
visual_studio_2008\more\sd\delete_file\delete_file.vcproj
visual_studio_2008\more\sd\get_disk_info\get_disk_info.sln
visual_studio_2008\more\sd\get_disk_info\get_disk_info.vcproj
visual_studio_2008\more\sd\list_directory\list_directory.sln
visual_studio_2008\more\sd\list_directory\list_directory.vcproj
visual_studio_2008\more\sd\print_working_directory\print_working_directory.sln
visual_studio_2008\more\sd\print_working_directory\print_working_directory.vcproj
visual_studio_2008\more\sd\read_file\read_file.sln
visual_studio_2008\more\sd\read_file\read_file.vcproj
visual_studio_2008\more\spi\spi\spi.sln
visual_studio_2008\more\spi\spi\spi.vcproj
visual_studio_2008\more\stream\stream_basic\stream_basic.sln
visual_studio_2008\more\stream\stream_basic\stream_basic.vcproj
visual_studio_2008\more\stream\stream_basic_with_stream_out\stream_basic_with_stream_out.sln
visual_studio_2008\more\stream\stream_basic_with_stream_out\stream_basic_with_stream_out.vcproj
visual_studio_2008\more\stream\stream_burst\stream_burst.sln
visual_studio_2008\more\stream\stream_burst\stream_burst.vcproj
visual_studio_2008\more\stream\stream_callback\stream_callback.sln
visual_studio_2008\more\stream\stream_callback\stream_callback.vcproj
visual_studio_2008\more\stream\stream_external_clock\stream_external_clock.sln
visual_studio_2008\more\stream\stream_external_clock\stream_external_clock.vcproj
visual_studio_2008\more\stream\stream_out_only\stream_out_only.sln
visual_studio_2008\more\stream\stream_out_only\stream_out_only.vcproj
visual_studio_2008\more\stream\stream_out_update\stream_out_update.sln
visual_studio_2008\more\stream\stream_out_update\stream_out_update.vcproj
visual_studio_2008\more\stream\stream_sequential_ain\stream_sequential_ain.sln
visual_studio_2008\more\stream\stream_sequential_ain\stream_sequential_ain.vcproj
visual_studio_2008\more\stream\stream_triggered\stream_triggered.sln
visual_studio_2008\more\stream\stream_triggered\stream_triggered.vcproj
visual_studio_2008\more\testing\auto_reconnect_test\auto_reconnect_test.sln
visual_studio_2008\more\testing\auto_reconnect_test\auto_reconnect_test.vcproj
visual_studio_2008\more\testing\c-r_speed_test\c-r_speed_test.sln
visual_studio_2008\more\testing\c-r_speed_test\c-r_speed_test.vcproj
visual_studio_2008\more\testing\externally_clocked_stream_test\externally_clocked_stream_test.sln
visual_studio_2008\more\testing\externally_clocked_stream_test\externally_clocked_stream_test.vcproj
visual_studio_2008\more\testing\stream_burst_test\stream_burst_test.sln
visual_studio_2008\more\testing\stream_burst_test\stream_burst_test.vcproj
visual_studio_2008\more\testing\system_reboot_test\system_reboot_test.sln
visual_studio_2008\more\testing\system_reboot_test\system_reboot_test.vcproj
visual_studio_2008\more\testing\write_read_loop_with_config_speed_test_eNames\write_read_loop_with_config_speed_test_eNames.sln
visual_studio_2008\more\testing\write_read_loop_with_config_speed_test_eNames\write_read_loop_with_config_speed_test_eNames.vcproj
visual_studio_2008\more\utilities\device_info\device_info.sln
visual_studio_2008\more\utilities\device_info\device_info.vcproj
visual_studio_2008\more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking\windows_dynamic_runtime_linking.sln
visual_studio_2008\more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking\windows_dynamic_runtime_linking.vcproj
visual_studio_2008\more\utilities\error\error.sln
visual_studio_2008\more\utilities\error\error.vcproj
visual_studio_2008\more\utilities\lua_script_basic\lua_script_basic.sln
visual_studio_2008\more\utilities\lua_script_basic\lua_script_basic.vcproj
visual_studio_2008\more\utilities\names_to_addresses\names_to_addresses.sln
visual_studio_2008\more\utilities\names_to_addresses\names_to_addresses.vcproj
visual_studio_2008\more\utilities\raw_bytes\raw_bytes.sln
visual_studio_2008\more\utilities\raw_bytes\raw_bytes.vcproj
visual_studio_2008\more\utilities\read_cal\read_cal.sln
visual_studio_2008\more\utilities\read_cal\read_cal.vcproj
visual_studio_2008\more\utilities\read_ljm_config\read_ljm_config.sln
visual_studio_2008\more\utilities\read_ljm_config\read_ljm_config.vcproj
visual_studio_2008\more\utilities\set_timeout\set_timeout.sln
visual_studio_2008\more\utilities\set_timeout\set_timeout.vcproj
visual_studio_2008\more\utilities\stepwise_feedback\stepwise_feedback.sln
visual_studio_2008\more\utilities\stepwise_feedback\stepwise_feedback.vcproj
visual_studio_2008\more\utilities\t7_tcp_configure\t7_tcp_configure.sln
visual_studio_2008\more\utilities\t7_tcp_configure\t7_tcp_configure.vcproj
visual_studio_2008\more\utilities\thermocouple_example\thermocouple_example.sln
visual_studio_2008\more\utilities\thermocouple_example\thermocouple_example.vcproj
visual_studio_2008\more\watchdog\read_watchdog_config\read_watchdog_config.sln
visual_studio_2008\more\watchdog\read_watchdog_config\read_watchdog_config.vcproj
visual_studio_2008\more\watchdog\write_watchdog_config\write_watchdog_config.sln
visual_studio_2008\more\watchdog\write_watchdog_config\write_watchdog_config.vcproj
visual_studio_2008\more\wifi\read_wifi_config\read_wifi_config.sln
visual_studio_2008\more\wifi\read_wifi_config\read_wifi_config.vcproj
visual_studio_2008\more\wifi\read_wifi_mac\read_wifi_mac.sln
visual_studio_2008\more\wifi\read_wifi_mac\read_wifi_mac.vcproj
visual_studio_2008\more\wifi\read_wifi_rssi\read_wifi_rssi.sln
visual_studio_2008\more\wifi\read_wifi_rssi\read_wifi_rssi.vcproj
visual_studio_2008\more\wifi\write_wifi_config\write_wifi_config.sln
visual_studio_2008\more\wifi\write_wifi_config\write_wifi_config.vcproj
xcode\basic\write_read_loop_with_config\write_read_loop_with_config.xcodeproj
xcode\basic\write_read_loop_with_config\write_read_loop_with_config.xcodeproj\project.pbxproj