I select electron and serialport to create a serialport tool app.
serialport : 5.0.0-beta5
electron: v1.7.4 beta
I can use serialport to write and receive data now.But It throw a error when I used close()
In addition, it also throw a error when I unplug. the disconnect callback does not work
close error: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Reading from COM port (ReadFile): Invalid handle
unplug error: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: Reading from COM port (ReadFile): Access denied
when I add this code
process.on('unhandledRejection', (reason, p) => {
if (reason.message.indexOf('Invalid handle') !== -1) {
} else if (reason.message.indexOf('Access denied') !== -1) {
port.emit('disconnect', reason.message)
} else {
console.log(p, ' ', reason)
}
})
the close & disconnect callback does work!!!:joy:
Please try 5.0.0-beta6 this should have better disconnect support.
@reconbot great, close and disconnect callback does work in electron & node when I unplug CH340 without close
It will trigger disconnect callback before and then close callback without do anything
That's great!
May I ask, would it be easier to use if you only got one event (disconnect) instead of both (disconnect and close) on disconnect?
Yes
Most helpful comment
Please try
5.0.0-beta6this should have better disconnect support.