Problem wtiting to ttyO1 - Update -

Hello All;

I apologize for starting a new thread, but I seem to have lost the last one L

Basically, after some “Google-ing” I realized that I have to wait for the serial port to be open before reading from or writing to it.

This is because it communicates asynchronously.

So here is my new code, and naturally a new error:

var data

var serialPort, sp;

var serialPort = require(“serialport”).SerialPort;

var sp = new serialPort("/dev/ttyO1", { baudrate: 9600 });

sp.on(“open”,function(){

console.log(“Hello World the Comm Port is Open”);

});

function sp_write(data){

sp.on(“open”, function () {

sp.write(“ls\n”, function(err, results) {

console.log('err ’ + err);

console.log('results ’ + results);

});

});

}

togglepin();

function togglepin(){

// High and low parts of the frame length (not counting checksum)

sp_write(“Hello Again”);

//sp_write(0x0);

//sp_write(0x10);

}

Hello World the Comm Port is Open

err undefined

results 3

I still need some help L

Bill

“No one could make a greater mistake than he who did nothing because he could do only a little.”

“All that is necessary for the triumph of evil is that good men do nothing” Edmond Burke (1729 - 1797)

http://www.packtpub.com/building-a-home-security-system-with-beaglebone/book

I have tried another solution which just uses bonescript.

I can receive data from the port but not write data to the port.

I have a USB/Serial adapter attached to ttyO1.

At least I know that ttyO1 is active and the hardware is working J

Here is the new code:

var b = require(‘bonescript’);

var port = ‘/dev/ttyO1’;

var options = {

baudrate: 9600

};

var data;

b.serialOpen(port, options,onWrite);

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:

onWrite(“Hello World”);

function onWrite(y){

if (y.error){

console.log('ERROR ’ + JSON.stringify(y));

}

if (y.event == ‘open’) {

console.log(y);

b.serialWrite(port, data);

console.log(data);

}

}

Console Output:

Your code is running at ‘http://0.0.0.0:28848’.

Important: in your scripts, use ‘process.env.PORT’ as port and ‘0.0.0.0’ as host.

{ event: ‘open’ }

If I replace “onWrite” with “onSerial” I can see characters that I type on the keyboard echoed in the terminal window.

Hoping for some help here L

Bill

“No one could make a greater mistake than he who did nothing because he could do only a little.”

“All that is necessary for the triumph of evil is that good men do nothing” Edmond Burke (1729 - 1797)

http://www.packtpub.com/building-a-home-security-system-with-beaglebone/book