« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Node.js for LJM - Windows, Mac, Linux

LJM Node.js Examples Windows, Mac, Linux (Software Platform)

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

Release

LJM Nodejs Examples (Referenceable)

Prerequisites

  • LabJack T7 or T4
  • 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.

Instructions

  1. Download and extract or clone the git repository and navigate into the directory.
  2. Execute "npm install" to install all of the project's dependencies. This will automatically compile the ffi library.
  3. Execute "cd examples" to navigate into the examples directory.
  4. 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. Execute "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);