Skip to content

Instantly share code, notes, and snippets.

@sofroniewn
Created March 8, 2016 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

$ node switch.js 1m 1 50000

Run switch test with labjack connected to my laptop (make sure power on!!) and test with oscilloscope
image

@sofroniewn
Copy link
Author

Reliably see < 1.5 ms delays
image

@sofroniewn
Copy link
Author

Also try just a single read/write call, but still have 1 ms to 2 ms latencies

 value = device.rwManySync(['FIO0', 'FIO1'], [0, 1], [1, 1], [null, value[0]])

@sofroniewn
Copy link
Author

image

image

@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