Created
March 8, 2016 22:04
-
-
Save sofroniewn/81abc125d78a7dbe5d93 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
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() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overall seems like board can run reliably in the 500 Hz - 1 kHz regime