Skip to content

Commit

Permalink
fix issue #59. Incorrect handling of rile descriptor on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeferner committed Jul 24, 2012
1 parent 00f8013 commit 526b2a2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _options = {
buffersize: 255,
parser: parsers.raw
};
function SerialPort(path, options) {
function SerialPort (path, options) {
options = options || {};
options.__proto__ = _options;

Expand Down Expand Up @@ -92,6 +92,9 @@ function SerialPort(path, options) {
self.emit('error', err);
};
options.disconnectedCallback = function () {
if (self.closing) {
return;
}
self.emit('error', new Error("Disconnected"));
self.close();
};
Expand All @@ -102,18 +105,20 @@ function SerialPort(path, options) {

SerialPortBinding.open(path, options, function (err, fd) {
self.fd = fd;
self.readStream = fs.createReadStream(path, { bufferSize: options.bufferSize, fd: fd });
self.readStream.on("data", options.dataCallback);
self.readStream.on("error", options.errorCallback);
self.readStream.on("close", function () {
self.close();
});
self.readStream.on("end", function () {
self.emit('end');
});
if (err) {
return self.emit('error', err);
}
if (process.platform !== 'win32') {
self.readStream = fs.createReadStream(path, { bufferSize: options.bufferSize, fd: fd });
self.readStream.on("data", options.dataCallback);
self.readStream.on("error", options.errorCallback);
self.readStream.on("close", function () {
self.close();
});
self.readStream.on("end", function () {
self.emit('end');
});
}

self.emit('open');
});
Expand Down

0 comments on commit 526b2a2

Please sign in to comment.