node-serialport: serialport doesn't recognize unpluged device

  • SerialPort Version: 6.0.0

  • NodeJS Version: v6.11.1

  • Operating System and Hardware Platform: Windows 10, 64 bit

  • Have you checked the right version of the api docs?:yes

  • Are you having trouble installing and you checked the Installation Special Cases docs? no

  • Are you using Electron and have you checked the Electron Docs?: yes

Summary of Problem

When I try to write to port of device that has been physically unplugged from computer error callback is not called and application just do nothing.

Steps and Code to Reproduce the Issue

var port = new SerialPort('COM2'); //success
//unplug the device
port.write('data');
port.drain((err) => { 
    if(err){
         console.log(err)
    }
}

the callback just isn’t called.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

@HipsterBrown sure, what I meant is something like this:

function callback(err) {
    if(error){
        console.log('write error: ' + error)
    }
    console.log('written')
}

var timeout = setTimeout(() => {
    callback('port write timed out')
}, 1500);

port.write(message, error => {
    clearTimeout(timeout)
    callback(error)
})

not nice at all though.