mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
pushing 0.2.6 with possible fix for arduino reading.
This commit is contained in:
parent
1d9dad5092
commit
72eff29d84
5 changed files with 26 additions and 29 deletions
|
|
@ -12,7 +12,7 @@
|
|||
8ee88 88ee 88 8 88 88 8 88eee 88 8eee8 88 8 88
|
||||
</pre>
|
||||
|
||||
Version: 0.2.5 - Released June 27, 2011
|
||||
Version: 0.3.0 - Released June 28, 2011
|
||||
|
||||
*****
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
Version 0.2.5 - Version 0.2.6
|
||||
-----------------------------
|
||||
- Debugging issue with IOWatcher not holding in the event loop in node.js.
|
||||
- Converted to ReadStream instead of IOWatcher.
|
||||
|
||||
Version 0.2.4
|
||||
-------------
|
||||
- Integrated arduino tests (rwaldron)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{ "name" : "serialport",
|
||||
"version" : "0.2.5",
|
||||
"version" : "0.2.6",
|
||||
"description" : "Welcome your robotic javascript overlords. Better yet, program them!",
|
||||
"author": "Chris Williams <voodootikigod@gmail.com>",
|
||||
"main": "./serialport",
|
||||
|
|
|
|||
|
|
@ -73,37 +73,29 @@ function SerialPort(path, options) {
|
|||
|
||||
this.port = path;
|
||||
this.fd = serialport_native.open(this.port, options.baudrate, options.databits, options.stopbits, options.parity, options.flowcontrol);
|
||||
|
||||
this.readWatcher = new IOWatcher();
|
||||
this.empty_reads = 0;
|
||||
this.readWatcher.callback = (function (file_id, me) {
|
||||
return function () {
|
||||
var buffer = new Buffer(options.buffersize);
|
||||
var bytes_read = 0, err = null;
|
||||
try {
|
||||
bytes_read = serialport_native.read(file_id, buffer);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
if (bytes_read <= 0) {
|
||||
// assume issue with reading.
|
||||
me.emit("error", (err ? err :"Read triggered, but no bytes available. Assuming error with serial port shutting down."));
|
||||
me.close();
|
||||
} else {
|
||||
options.parser(me, buffer.slice(0, bytes_read));
|
||||
}
|
||||
}
|
||||
})(this.fd, this);
|
||||
this.readWatcher.set(this.fd, true, false);
|
||||
this.readWatcher.start();
|
||||
|
||||
if (this.fd == -1) {
|
||||
this.emit("error", new Error('could not open serial port'))
|
||||
} else {
|
||||
this.readStream = fs.createReadStream(this.port);
|
||||
var dataCallback = (function (me) {
|
||||
return (function (buffer) {
|
||||
options.parser(me, buffer)
|
||||
});
|
||||
})(this);
|
||||
var errorCallback = (function (me) {
|
||||
return (function (err) {
|
||||
me.emit("error", err);
|
||||
});
|
||||
});
|
||||
this.readStream.on("data", dataCallback);
|
||||
this.readStream.on("error", errorCallback);
|
||||
}
|
||||
}
|
||||
|
||||
sys.inherits(SerialPort, stream.Stream);
|
||||
|
||||
SerialPort.prototype.close = function () {
|
||||
this.readWatcher.stop();
|
||||
|
||||
this.readStream.close();
|
||||
if (this.fd) {
|
||||
serialport_native.close(this.fd);
|
||||
this.fd = null;
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ namespace node {
|
|||
int fd = open(*path, flags);
|
||||
|
||||
if (fd == -1) {
|
||||
perror("open_port: Unable to open specified serial port connection.");
|
||||
// perror("open_port: Unable to open specified serial port connection.");
|
||||
return scope.Close(Integer::New(fd));
|
||||
} else {
|
||||
struct sigaction saio;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue