1

Beaglebone black - not receiving data on serial. I have connected Tx and Rx pins of the serial ports 1 and 2 directly (tx - rx). I'm kind of new to beaglebone. I used this code to send data on the serial to another device, it worked properly for transmission, but not for Rx. I haven't found the file ttyO1, just ttyO2.

var b = require('bonescript');
var rxport = '/dev/ttyO1';
var txport = '/dev/ttyO2';
var options = { baudrate: 115200, parity: 'even', parser:

b.serialParsers.readline('\n') };
var teststring = "This is the string I'm sending out as a test";

b.serialOpen(rxport, options, onRxSerial);

function onRxSerial(x) {

console.log('rx.eventrx= ' + x.event);
if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
if(x.event == 'open') {
    //readReapeatedly();
    b.serialOpen(txport, options, onTxSerial);
}
if(x.event == 'data') {
    console.log("I am receiving on rxport");
    console.log('rx (' + x.data.length +
                ') = ' + x.data.toString('ascii'));
 }
 }

function onTxSerial(x) {
console.log('tx.event = ' + x.event);
if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
if(x.event == 'open') {
    writeRepeatedly();
}
if(x.event == 'data') {

    console.log('tx (' + x.data.length +
                 ') = ' + x.data.toString('ascii'));
    console.log(x.data);
}
}

function printJSON(x) {
console.log(JSON.stringify(x));
}

function writeRepeatedly() {
console.log("write to serial");
b.serialWrite(txport, teststring, onSerialWrite);
console.log("I have sent data");
}


function onSerialWrite(x) {
console.log("Iam in the onSerialWrite function");
if(x.err) console.log('onSerialWrite err = ' + x.err);
if(x.event == 'callback') {setTimeout(writeRepeatedly, 5000);
console.log("HERE");
}
}
1
  • Thank u. It worked fine yesterday, but when trying to run the code today, I faced the following problem: (events.js:72 throw er; // Unhandled 'error' event ^ Error: Cannot open /dev/ttyO2). It seems that ttyO2 is not available in /dev. Mar 2, 2016 at 5:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.