I tried to use this example to write to a device I have connected to serial 
port /dev/ttyO1.  I know the device answers because I can use screen and 
get responses.  My code to send out "/sh/s" is:

var b = require('bonescript');

var cmd = '/sh/s';

var port = '/dev/ttyO1';

var options = {

    baudrate: 9600

};


b.serialOpen(port, options, onSerial);


b.serialWrite(port, cmd);


function onSerial(x) {

    if (x.err) {

        console.log('***ERROR*** ' + JSON.stringify(x));

    }

    if (x.event == 'open') {

       console.log('***OPENED***');

    }

    if (x.event == 'data') {

        console.log(String(x.data));

    }

}

I get the following response:

debian@beaglebone:~/nodews$ node shedrd.js 


/usr/local/lib/node_modules/bonescript/my.js:55

            var slotRegex = new RegExp('\\d+(?=\\s*:.*,bs.*' + pin.key + 
')', 

                                                                  ^

TypeError: Cannot read property 'key' of undefined

    at Object.exports.load_dt 
(/usr/local/lib/node_modules/bonescript/my.js:55:67)

    at Object.newFunction [as serialOpen] 
(/usr/local/lib/node_modules/bonescript/my.js:228:25)

    at Object.<anonymous> (/home/debian/nodews/shedrd.js:8:3)

    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 Function.Module.runMain (module.js:497:10)

    at startup (node.js:119:16)

    at node.js:902:3

debian@beaglebone:~/nodews$

Thanks for the help

Jonathan


On Monday, April 7, 2014 1:13:13 PM UTC-4, Jason Kridner wrote:
>
>
>
> On Thursday, March 27, 2014 4:59:00 PM UTC-4, Mark A. Yoder wrote:
>>
>> Nick:
>>   I have some bonescript code that works with the UART, but I'm not using 
>> the built-in bonescript calls. It works fine with a GPS, though I don't use 
>> it to transmit.
>>
>> I took would like to see an example that uses the bonescript calls. 
>>
>
> I haven't had a chance to try it out as I don't have a device easy to 
> wire-up until later today, but can you try out this live in-a-webpage 
> example at: http://jsfiddle.net/jkridner/AjnJs/
>
>  
>
>>  Before ruing the code you need to:
>>
>> beagle# *npm install -g serialport*
>>
>
> BoneScript simply uses this same library, so using BoneScript avoids 
> needing to install it.
>  
>
>>
>> beagle# *echo BB-UART4 > /sys/devices/bone_capemgr.*/slots*
>>
>
> BoneScript loads this same overlay for you.
>
> A basic listening example would be:
>
> var b = require('bonescript');
> var port = '/dev/ttyO4';
> var options = {
>     baudrate: 115200
> };
>
> b.serialOpen(port, options, onSerial);
>
> function onSerial(x) {
>     if (x.err) {
>         console.log('***ERROR*** ' + JSON.stringify(x));
>     }
>     if (x.event == 'open') {
>        console.log('***OPENED***');
>     }
>     if (x.event == 'data') {
>         console.log(String(x.data));
>     }
> }
>
> To write, you'd do:
>
> b.serialWrite(port, data);
>
>
> Hopefully you'll see some value in the simplicity.
>
>  
>
>>
>> --Mark
>> #!/usr/bin/env node
>> // From: https://github.com/voodootikigod/node-serialport
>> // From: https://github.com/jamesp/node-nmea
>>
>> var b = require('bonescript');
>> var nmea = require('nmea');
>>
>> //console.log(b.serialOpen);
>>
>> //var sp = b.serialOpen('/dev/ttyO4', {baudrate: 9600} );
>> // parser: b.serialParsers.readline("\n")});
>>
>>
>> var serialport = require("serialport");
>> var SerialPort = serialport.SerialPort; // localize object constructor
>>
>> var sp = new SerialPort("/dev/ttyO4", {
>>     parser: serialport.parsers.readline("\n")
>> });
>>
>> sp.on("data", function (data) {
>>     console.log("here: "+data);
>>     console.log(nmea.parse(data));
>>     });
>>
>>
>> On Thursday, December 19, 2013 1:49:30 AM UTC-5, Nick Farrell wrote:
>>>
>>> I am a newbie to BeagleBone Black(BBB) but have good knowledge about 
>>> Arduino. I would like to know how to open a serial port in BBB using the 4 
>>> UARTs available in BBB using BoneScript library and use cloud9 ide to see 
>>> the serial data on the console. Can anyone help me on this issue.
>>>
>>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to