Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var b = require('bonescript');
- var options = {
- baudrate: 9600,
- parser: b.serialParsers.readline("\n")
- };
- b.serialOpen(port, options, onSerial);
- function onserail(x) {
- console.log(x.event);
- if (x.err) {
- console.log('---ERROR--- ' +
- JSON.stringify(x));
- }
- if (x.event == 'open') {
- console.log('---OPENED---');
- setInterval(sendCommand, 1000);
- }
- if (x.event == 'data') {
- console.log(String(x.data));
- }
- }
- var command = ['r', 'g'];
- var commIdx = 1;
- function sendCommand() {
- b.serialWrite(port, command[commIdx++]);
- if(commIdx >= command.length) {
- commIdx = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement