Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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