KentK
unread,Apr 6, 2012, 3:56:05 PM4/6/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nodejs
Hi I am running this on Windows 7.
I am trying to set up a dual communication towards an external serial
device on COM1.
What happens is that I will only receive (fs.read) the first incoming
character.
Before I receive that character I am not able to send any character,
but after receiving, I can send over and over again. But not receive
any more.
Here is the code:
var fs = require('fs');
var fd;
var Buffer = require('buffer').Buffer;
var buffer = new Buffer(100);
fs.open("\\\\.\\COM1", "w+", function(status, _fd){
fd = _fd;
if(status){
console.log(status.message);
return;
}
fs.read(fd, buffer, 0, 100, null, function(e,l,b){
console.log("Read " + l + " bytes.");
return;
});
});
var buf = new Buffer('BBBB\n');
var stdin = process.openStdin();
stdin.on('data', function(chunk) {
// For now I just send the four Bs when [Enter] is pressed.
fs.write(fd, buf, 0, buf.length, null, function(err,written){
if(err)throw err;
console.log(written + " characters written.");
});
});