Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@labjack/labjack-nodejs
Advanced tools
'LabJack-nodejs' makes LabJack's LJM library available for node.js. The library uses ffi to link to the appropriate library file (LabJackM.dll, LabJackM.dylib, or LabJackM.so) which must be installed with one of LabJack's installers. Currently, installers are available for Windows, Mac OS X, Linux 32-bit & 64-bit, and a few builds for ARMv6 and ARMV7 architectures.
This library exposes the LJM driver slightly different than our standard LJM Library wrappers because it was created primarily for use in Kipling. If this library were to be re-written it would be split into two modules, one that directly exposes the LJM Library functions, and another that performs some of the abstractions. A brief summary of how this library exposes the LJM Library:
Currently this wrapper only supports the T4, T7, T7-Pro, Digit-TL, and Digit-TLH LabJack devices. (Which are low cost, high-quality, multifunction USB / Ethernet / 802.11b/g WiFi DAQ devices.) Devices using the UD library (Windows only) aka U3, U6, and UE9 are not supported. Additionally, the U12 is not supported.
If you are trying to perform device IO, consider looking at the ljswitchboard-ljm_device_curator project. It makes several more device abstractions and wraps this library in a promise interface. If you are trying to scan for devices consider using the ljswitchboard-device_scanner module.
$ npm install -g node-gyp
Make sure that node-ffi and ref can be installed, it may be wise to create a dummy project and invoke:
$ npm install ffi
before trying to install LabJack-nodejs. Once you can do that simply install via npm:
$ npm install labjack-nodejs
Make sure that node-gyp is properlly installed. Performing the standard npm install command will fail on Windows. It will hopefully complain about not having proper "TargetFrameworkVersion or PlatformToolset variables not being set. If this is true, set them: "npm install --msvs_version=2012" or 2013.
This hint came from someone building couchbase
For higher/newer versions of node, visual studio 14.0 is required aka msvs_version=2015.
Also, consider using the command "npm config set msvs_version 2015 --global" instead of the non global version node-gyp install issues.
This driver wrapper was created supporting both synchronous and asynchronous function calls to support both functional and object-oriented programing styles. The general format is shown below:
//Synchronous syntax:
var result = exampleFunctionSync(arg1);
//Asynchronous syntax (requiring function callbacks):
exampleFunction(
arg1,
function(err) {
console.log('error', err);
},
function(result) {
console.log('success', result);
}
);
//Require LabJack-nodejs
var ljn = require('@labjack/labjack-nodejs');
//Device object (to control a LabJack device)c
var createDeviceObject = ljn.getDevice();
//Device object (to control a LabJack device)
var device = new createDeviceObject();
// Open a device
device.openSync();
// Read an analog input
console.log('AIN0:', device.readSync('AIN0'));
// Close the device
device.closeSync();
After creating a labjack-nodejs library reference:
var ljn = require('@labjack/labjack-nodejs');
you get access to several attributes, the two most important ones are:
Look at the lib/labjack_nodejs.js file for what gets exported. There are a few subtle differences between the functions in terms of creating new objects.
In general, LJM functions that require the passing of a device handle are implemented in the device object. Functions that are device-agnostic are implemented in the driver object.
After creating a device object:
var device = new createDeviceObject();
several functions are made available:
Device Opening/Closing
Reading:
Writing:
Both Directions:
Special/Streaming
Uses LJM_Open and LJM_OpenS
device.openSync(); //opens the first found LabJack device, LJM_OpenS('LJM_dtANY', 'LJM_ctANY', 'LJM_idANY')
device.openSync('LJM_dtANY', 'LJM_ctANY', 'LJM_idANY'); //Connect to first-found device
device.openSync('LJM_dtT7', 'LJM_USB', '470010642'); //Connect to T7 w/ serial number 470010642 connected via USB
device.openSync('LJM_dtT7', 'LJM_ETHERNET', '470010642'); //Connect to T7 w/ serial number 470010642 connected via ETHERNET
device.openSync('LJM_dtT7', 'LJM_WIFI', '470010642'); //Connect to T7 w/ serial number 470010642 connected via WIFI
device.openSync(7, 1, 470010642); //Connect to T7 w/ serial number 470010642 connected via USB
//example with callback:
var onSuccess = function(result) {
//Code
}
var onError = function(error) {
//Code
}
//Connect to first-found device w/ callbacks
device.open(
'LJM_dtANY',
'LJM_ctANY',
'LJM_idANY',
onError,
onSuccess
);
Uses LJM_GetHandleInfo
devInfo = device.getHandleInfoSync(); //return the handle info in a dict:
//devInfo is a dictionary with attributes: deviceType, connectionType, serialNumber, ipAddress, port, maxBytesPerMB
devInfo.deviceType; //The device type (7 for T7s)
devInfo.connectionType; //The connection type, 1(USB), 3(ETHERNET), 4(WIFI)
devInfo.serialNumber; //The serial number of the open device
devInfo.ipAddress; //IP address string for the open device
devInfo.port;
devInfo.maxBytesPerMB;
Uses LJM_ReadRaw
Uses LJM_eReadAddress, LJM_eReadName, LJM_eReadNameString, and LJM_eReadAddressString.
value = device.readSync('AIN0'); //returns the AIN0 channel reading
value = device.readSync(0); //returns the AIN0 channel reading
value = device.readSync('DEVICE_NAME_DEFAULT'); //returns the name of the device
//example with callback:
value = device.read(
'AIN0',
function (res) {
console.log('err:', res);
},
function (res) {
console.log('ain0Reading:', res);
}
);
Uses LJM_eReadAddresses and LJM_eReadNames
value = device.readManySync(['AIN0', 'AIN1']); //returns an array with AIN0 and AIN1 readings
value = device.readManySync([0, 1]); //returns an array with AIN0 and AIN1 readings
Uses LJM_WriteRaw
Uses LJM_eWriteAddress, LJM_eWriteName, LJM_eWriteAddressString, and LJM_eWriteNameString
errRes = device.writeSync('DAC0', 1.0); //instructs the T7 to set DAC0 analog output to 1V, returns an error number
errRes = device.writeSync(1000, 1.0); //instructs the T7 to set DAC0 analog output to 1V, returns an error number
value = device.writeSync('DEVICE_NAME_DEFAULT', 'NewDeviceName'); //writes a new device name to the device
//example with callback:
errRes = device.write(
'DAC0',
1.0,
function (res) {
console.log('err:', res);
},
function (res) {
console.log('SUCCESS');
});
Uses LJM_eWriteAddresses LJM_eWriteNames
//Two Arrays
//using two separate arrays, one for addresses to write to and one of values
errRes = device.writeManySync(['DAC0', 'DAC1'], [1.0, 2.0]);
errRes = device.writeManySync([1000, 1002], [1.0, 2.0]);
Uses LJM_Close
errRes = device.closeSync();
//example with callback:
device.close(
function(res){
console.log('Err:', res);
},
function(res){
console.log('closed!');
});
JavaScript wrapper for the rest of the LJM_Driver functions.
//Require LabJack-nodejs
var ljn = require('@labjack/labjack-nodejs');
//Driver Object (to gain access to more general driver-related features)
var driver = ljn.driver();
Uses LJM_ListAll and LJM_ListAllS
foundDevices = ljmDriver.listAllSync(); //find all T7s
foundDevices = ljmDriver.listAllSync('LJM_dtANY', 'LJM_ctANY'); //find all T7s
foundDevices = ljmDriver.listAllSync('LJM_dtT7', 'LJM_ctUSB'); //find all T7s connected via USB
foundDevices = ljmDriver.listAllSync(7, 1); //find all T7s connected via USB
//using callback functions
ljmDriver.listAll(
function (err) {
console.log('Error', err);
},
function (foundDevices) {
console.log('Devices Found:');
console.log(foundDevices);
}
);
//Both methods return an array of dicts, ex:
//foundDevices.length is the number of devices found
//foundDevices[0].deviceType is a number
//foundDevices[0].connectionType is a number
//foundDevices[0].serialNumber is a number
//foundDevices[0].ipAddress is a string
Uses LJM_ErrorToString, converts an error number to a human-readable string-error. The errors can be found in the ljm_constants.json file.
console.log(ljmDriver.errToStrSync(0)); //returns the string 'Num 0, LJ_SUCCESS'
console.log(ljmDriver.errToStrSync(200)); //returns the string 'Num 200, LJME_WARNINGS_BEGIN'
console.log(ljmDriver.errToStrSync(1268)); //returns the string 'Num 1268, LJME_INVALID_INDEX'
Uses LJM_LoadConstants
Uses LJM_CloseAll
Uses LJM_ReadLibraryConfigS, helpful for using LJM's logging features
Uses LJM_ReadLibraryConfigStringS, helpful for using LJM's logging features
Uses LJM_WriteLibraryConfigS and LJM_WriteLibraryConfigStringS, helpful for using LJM's logging features
Uses LJM_Log
Uses LJM_ResetLog
FAQs
nodejs library for using the LabJackM library
The npm package @labjack/labjack-nodejs receives a total of 2 weekly downloads. As such, @labjack/labjack-nodejs popularity was classified as not popular.
We found that @labjack/labjack-nodejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.