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
Older Release Packages
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
Go to your device Quickstart Tutorial and follow the steps to install LabJack software and confirm basic operation.
Download and extract or clone the git repository and navigate into the directory.
Run
npm install
to install all of the project's dependencies. This will automatically compile the ffi library.Run
cd examples
to navigate into the examples directory.Execute
node hello_world.js
to run the hello world example.
Including ljm-ffi into your own node.js project
Open Windows command prompt/power shell, or Mac/Linux bash window.
Navigate into your node.js project.
Run
npm install ljm-ffi
.
Further Reading
Look at the ljm-ffi git repository for more information.
Code Snippet
// 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