beagleboard / bonescript

Scripting tools for the BeagleBoard and BeagleBone
http://beagleboard.org
MIT License
32 stars 9 forks source link

serialParsers problem #25

Open jadonk opened 6 years ago

jadonk commented 6 years ago

From @docwelch on May 16, 2014 23:52

I am trying to run the test-serial.js example. When I start it, I get the following error: debugger listening on port 15454

/var/lib/cloud9/SerialTest.js:4 var options = { baudrate: 115200, parser: b.serialParsers.readline('\n') }; ^ TypeError: Cannot call method 'readline' of undefined at Object. (/var/lib/cloud9/SerialTest.js:4:59) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain as _onTimeout at Timer.listOnTimeout as ontimeout

[Process stopped]

If I change the var options line to: var options= {baudrate: 115200}; //leave out the parser everything works. I can actually send and get back data (though it is obviously not parsed correctly). Based on the fact it works without the "parser:b.serialParsers.readline('\n'), I think I have everything installed correctly (though I am a newbie to this so anything is possible).

I should mention I am running the Debian distribution (2014-04-23) and BoneScript 0.2.4

Thanks in advance.

Copied from original issue: jadonk/bonescript#85

jadonk commented 6 years ago

From @docwelch on May 19, 2014 14:6

I have found the problem but it raises another issue. When I look in the file serial.js on the beaglebone and compare it to the serial.js file on Github, the last line that enables the parsers is missing on my beaglebone. I went ahead and did another update with TERM=none npm install -g bonescript and the last line is still missing. If I add the line in manually, everything works. So, the parsers function is working, but the update is not working correctly for me.

jadonk commented 6 years ago

The github is ahead of the release in npm. I need to get a new release out. I'm hoping to get a review with the code in Simon Monk's book before I release 0.2.5.

jadonk commented 6 years ago

From @frank5192035 on February 9, 2015 6:8

Hi: I made UART1 and UART4 mutual communication with each other. But I found the received data always go throught first call back function "onUART4" as following code. I also try to change the "b.serialOpen(UART4, options, onUART4);" after the line "b.serialOpen(UART1, options, onUART1);". The result became it always called the onUART1 function. It behave like only one call back function can work. I am not sure what's the problem?

The code I wrote:

var b = require('bonescript');

var UART1 = '/dev/ttyO1'; var UART4 = '/dev/ttyO4'; var options = { // baudrate: 9600, // buffersize: 1000 // parser: b.serialport.parsers.readline("\n") // parser: b.parsers }

b.serialOpen(UART4, options, onUART4); setTimeout(Sending4, 1200); b.serialOpen(UART1, options, onUART1); setTimeout(Sending1, 1000);

function onUART1(x) { if (x.err) { console.log('_ERROR_ ' + JSON.stringify(x)); } if (x.event == 'open') { console.log('* UART1 OPENED *'); } if (x.event == 'data') { // console.log('UART1 Rx: ' + String(x.data)); console.log('UART1 Rx: ' + x.data); } }

function onUART4(x) { if (x.err) { console.log('_ERROR_ ' + JSON.stringify(x)); } if (x.event == 'open') { console.log('* UART4 OPENED *'); } if (x.event == 'data') { console.log('UART4 Rx: ' + String(x.data)); } }

function Sending1() { b.serialWrite(UART1, 'aaa'); } function Sending4() { b.serialWrite(UART4, 'bbb'); }

===>>> The execution result: [root@ /var/lib/cloud9/javascripts]# node UART.js * UART4 OPENED * * UART1 OPENED * UART4 Rx: aaa UART4 Rx: bbb