-
-
Save CJ-Davies/5a810072245a26bf99fb0a7893933a15 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
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
if (process.argv.length != 4) { | |
console.log('\nUsage: node stopTest.js <port> <baudrate>\n'); | |
process.exit(1); | |
} | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
var OBD = require('obd-parser'); | |
var getConnector = require('obd-parser-serial-connection'); | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
var count = 0; | |
var maxCount = 5; | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
var connect = getConnector({ | |
serialPath: process.argv[2], | |
serialOpts: { | |
baudrate: process.argv[3] | |
} | |
}); | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
OBD.init(connect).then(function() { | |
var rpmPoller = new OBD.ECUPoller({ | |
pid: new OBD.PIDS.Rpm(), | |
interval: 500 | |
}); | |
console.log('[stopTest.js] calling startPolling()') | |
rpmPoller.startPolling(); | |
rpmPoller.on('data', function(output) { | |
PrintOBDMessage('12/0x0C RPM', output); | |
count++; | |
console.log(count); | |
if (count >= maxCount) { | |
console.log('[stopTest.js] calling stopPolling()'); | |
rpmPoller.stopPolling(); | |
} | |
}); | |
}); | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- | |
function PrintOBDMessage(pid, msg) { | |
console.log('\n------- ' + pid + ' -------') | |
console.log('time: ', msg.ts); | |
console.log('bytes: ', msg.bytes); | |
console.log('value: ', msg.value); | |
console.log('pretty: ', msg.pretty); | |
} | |
// ------- ------- ------- ------- ------- ------- ------- ------- ------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment