Skip to content

Commit

Permalink
Allow opening after an open error. (#910)
Browse files Browse the repository at this point in the history
fixes #908
  • Loading branch information
reconbot authored Aug 17, 2016
1 parent aaa0613 commit 3247987
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ SerialPort.prototype.open = function(callback) {
this.opening = true;

SerialPortBinding.open(this.path, this.options, function(err, fd) {
this.opening = false;
if (err) {
debug('SerialPortBinding.open had an error', err);
return this._error(err, callback);
}
this.fd = fd;
this.paused = false;
this.opening = false;

if (process.platform !== 'win32') {
this.serialPoller = new SerialPortBinding.SerialportPoller(this.fd, function(err) {
Expand Down
12 changes: 12 additions & 0 deletions test/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ describe('SerialPort', function() {
port.open(spy);
port.open(spy);
});

it('allows opening after an open error', function(done) {
var stub = sandbox.stub(bindings, 'open', function(path, opt, cb) {
cb(new Error('haha no'));
});
var port = new SerialPort('/dev/exists', { autoOpen: false });
port.open(function(err) {
assert.instanceOf(err, Error);
stub.restore();
port.open(done);
});
});
});

describe('#close', function() {
Expand Down

0 comments on commit 3247987

Please sign in to comment.