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
From: [email protected] [mailto:[email protected]] On
Behalf Of William Pretty Security
Sent: Wednesday, August 13, 2014 2:50 PM
To: [email protected]
Cc: 'Owen Roberts'
Subject: [beagleboard] 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:
From: https://www.npmjs.org/package/serialport
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
<sigh>
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
_____
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4716 / Virus Database: 3986/7978 - Release Date: 08/04/14
Internal Virus Database is out of date.
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4744 / Virus Database: 4007/8028 - Release Date: 08/13/14
--
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.
--
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.