Skip to content

Instantly share code, notes, and snippets.

@sofroniewn
Created March 8, 2016 22:04
Show Gist options
  • Save sofroniewn/81abc125d78a7dbe5d93 to your computer and use it in GitHub Desktop.
Save sofroniewn/81abc125d78a7dbe5d93 to your computer and use it in GitHub Desktop.
console.log('Hello LabJack')
var ljn = require('labjack-nodejs');
var NanoTimer = require('nanotimer')
var fs = require('fs')
var now = require('performance-now')
var path = require('path')
var mkdirp = require('mkdirp').mkdirp
var createDeviceObject = ljn.getDevice();
var device = new createDeviceObject();
device.openSync();
console.log('Board ready')
var timer = new NanoTimer()
var interval = process.argv[2]
var repeats = process.argv[3]
var samples = process.argv[4]
mkdirp('./logs')
var filename = path.basename(process.argv[1], '.js')
var ws = fs.createWriteStream('./logs/' + filename + '-' + interval + '-' + repeats +'.log' )
var iteration = 0
obj = {
'board': true,
'date': new Date(),
'time': now().toFixed(3)
}
console.log(JSON.stringify(obj))
var curTime = 0
var prevTime = 0
var value = 0
timer.setInterval(function() {
curTime = now()
for (i=0; i<repeats; i++) {
value = device.readSync('FIO0')
}
for (i=0; i<repeats; i++) {
device.writeSync('FIO1', value)
}
obj = {
'sw': value,
'it': iteration,
'ts': curTime.toFixed(3),
'df': (curTime - prevTime).toFixed(3)
}
prevTime = curTime
iteration++
if (iteration > samples) {
device.closeSync();
timer.clearInterval()
}
//console.log(JSON.stringify(obj))
ws.write(JSON.stringify(obj) + '\n')
}, '', interval)
process.on('SIGINT', function() {
device.closeSync();
timer.clearInterval()
});
@sofroniewn
Copy link
Author

Also see 1 ms to 2 ms latencies for analog switch

 value = device.rwManySync(['AIN0', 'DAC0'], [0, 1], [1, 1], [null, value])[0]

@sofroniewn
Copy link
Author

Overall seems like board can run reliably in the 500 Hz - 1 kHz regime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment