Skip to content

Commit 3247987

Browse files
authored
Allow opening after an open error. (#910)
fixes #908
1 parent aaa0613 commit 3247987

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/serialport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ SerialPort.prototype.open = function(callback) {
222222
this.opening = true;
223223

224224
SerialPortBinding.open(this.path, this.options, function(err, fd) {
225+
this.opening = false;
225226
if (err) {
226227
debug('SerialPortBinding.open had an error', err);
227228
return this._error(err, callback);
228229
}
229230
this.fd = fd;
230231
this.paused = false;
231-
this.opening = false;
232232

233233
if (process.platform !== 'win32') {
234234
this.serialPoller = new SerialPortBinding.SerialportPoller(this.fd, function(err) {

test/serialport.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ describe('SerialPort', function() {
327327
port.open(spy);
328328
port.open(spy);
329329
});
330+
331+
it('allows opening after an open error', function(done) {
332+
var stub = sandbox.stub(bindings, 'open', function(path, opt, cb) {
333+
cb(new Error('haha no'));
334+
});
335+
var port = new SerialPort('/dev/exists', { autoOpen: false });
336+
port.open(function(err) {
337+
assert.instanceOf(err, Error);
338+
stub.restore();
339+
port.open(done);
340+
});
341+
});
330342
});
331343

332344
describe('#close', function() {

0 commit comments

Comments
 (0)