Skip to main content
Skip table of contents

Node.js for LJM - Windows, Mac, Linux

Node.js examples for the LJM library. The source code for the LJM Node.js library is also available on GitHub and npm.

Prerequisites

  • A T-series LabJack Device

  • LJM Library - Install the LJM Library

  • Node.js and npm.

  • Operating system - Windows, Mac OS X, or Linux.

  • The ability to compile node.js native modules. Look at the ffi and node-gyp for more details.

Latest Release Package

nodejs-ljm_2024-09-06.zip

Older Release Packages

nodejs_ljm_2016_1_11.zip

Known Issues

LJM stream functions do not work.

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.

Instructions

  1. Go to your device Quickstart Tutorial and follow the steps to install LabJack software and confirm basic operation.

  2. Download and extract or clone the git repository and navigate into the directory.

  3. Run npm install to install all of the project's dependencies. This will automatically compile the ffi library.

  4. Run cd examples to navigate into the examples directory.

  5. Execute node hello_world.js to run the hello world example.

Including ljm-ffi into your own node.js project

  1. Open Windows command prompt/power shell, or Mac/Linux bash window.

  2. Navigate into your node.js project.

  3. Run npm install ljm-ffi.

Further Reading

Look at the ljm-ffi git repository for more information.

Code Snippet

CODE
// Load the LJM Library.
var ljm_ffi = require('../lib/ljm-ffi');
var ljm = ljm_ffi.load();

// Load a utility function to get the connected device's info.
var utils = require('./utils/utils');
var getHandleInfoSync = utils.getHandleInfoSync;

// Define a variable that will store data from LJM function calls
var data;

// Define a variable that will store the device's handle.
var handle;

// Open the first found T7.
data = ljm.LJM_OpenS('LJM_dtT7', 'LJM_ctANY', 'LJM_idANY', 0);

// Exit the program if a device was not found.
if(data.ljmError !== 0) {
	console.log('Failed to open a device, please connect a T7 to your computer.');
	process.exit();
} else {
	handle = data.handle;
	console.log('Connected to device:', getHandleInfoSync(handle));
}

// Read the T7's AIN0.
data = ljm.LJM_eReadName(handle, 'AIN0', 0);
console.log('AIN0', data.Value);

// Close the device.
data = ljm.LJM_Close(handle);

File List

nodejs_ljm_2016_1_11.zip contains:

.gitignore
package.json
README.md
examples\hello_world.js
examples\read_analog_input.js
examples\write_analog_output.js
examples\misc\hello_world.js
examples\utils\utils.js
lib\ljm-ffi.js
lib\ljm_functions.js
lib\type_helpers.js
test\basic_ljm_calls.js
test\get_ljm_version.js
test\test.js
test\test_type_helpers.js
test\ljm_calls\device_scanning.js
test\ljm_calls\ljm_calls.js
test\ljm_calls\open_all_testing.js

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.