Advertisement
silver2row

BoneScript but I am not sure just yet what it is...

Apr 5th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var b = require('bonescript');
  2. var options = {
  3.     baudrate: 9600,
  4.     parser: b.serialParsers.readline("\n")
  5. };
  6.  
  7. b.serialOpen(port, options, onSerial);
  8.  
  9. function onserail(x) {
  10.     console.log(x.event);
  11.     if (x.err) {
  12.         console.log('---ERROR--- ' +
  13. JSON.stringify(x));
  14.     }
  15.     if (x.event == 'open') {
  16.         console.log('---OPENED---');
  17.         setInterval(sendCommand, 1000);
  18.     }
  19.     if (x.event == 'data') {
  20.         console.log(String(x.data));
  21.     }
  22. }
  23.  
  24. var command = ['r', 'g'];
  25. var commIdx = 1;
  26.  
  27. function sendCommand() {
  28.     b.serialWrite(port, command[commIdx++]);
  29.     if(commIdx >= command.length) {
  30.         commIdx = 0;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement