Last active
March 8, 2016 22:02
-
-
Save sofroniewn/0d257ca144e706ebd392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var now = require('performance-now') | |
//Require LabJack-nodejs | |
var ljn = require('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 digital input | |
var time = now() | |
var val = device.readSync('DIO0') | |
var diff = now()-time | |
console.log('read DIO0:', val); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Read an analog input | |
var time = now() | |
var val = device.readSync('AIN0') | |
var diff = now()-time | |
console.log('read AIN0:', val); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Read two digital inputs and two analog inputs | |
var time = now() | |
var val = device.readManySync(['DIO0', 'DIO1', 'AIN0', 'AIN1']) | |
var diff = now()-time | |
console.log('read DIO0:', val[0], 'DIO1:', val[0], 'AIN0:', val[2], 'AIN1:', val[3]); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Write a digital input | |
var time = now() | |
var errRes = device.writeSync('DAC0', 1.0); | |
var diff = now()-time | |
console.log('write DAC0:', 1.0); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Write a digital output | |
var time = now() | |
var errRes = device.writeSync('DIO0', 1); | |
var diff = now()-time | |
console.log('write DIO0:', 1.0); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Write two digital outputs and two analog outputs | |
var time = now() | |
var errRes = device.writeManySync(['DIO0', 'DIO1', 'DAC0', 'DAC1'], [1, 1, 1.0, 1.0]) | |
var diff = now()-time | |
console.log('write DIO0:', 1, 'DIO1:', 1, 'DAC0:', 1.0, 'DAC1:', 1.0); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
///////////////////////////////////////////////////// | |
// Read and write one digital and analog input and output each | |
var time = now() | |
var val = device.rwManySync(['DIO0', 'DIO1', 'AIN0', 'DAC1'], [0, 1, 0, 1],[1, 1, 1, 1], [null, 1, null, 1.0]) | |
var diff = now()-time | |
console.log('read & write DIO0:', val[0], 'DIO1:', 1, 'AIN0:', val[1], 'DAC1:', 1.0); | |
console.log(' ' + diff.toFixed(3) + ' ms') | |
// Close the device | |
device.closeSync(); |
Author
sofroniewn
commented
Mar 8, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment