Node-serialport: a error when I use close() in electron v1.7.4 beta

Created on 4 Jul 2017  路  5Comments  路  Source: serialport/node-serialport

I select electron and serialport to create a serialport tool app.
serialport : 5.0.0-beta5
electron: v1.7.4 beta

Summary of Problem

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

bug resolution-verify

Most helpful comment

Please try 5.0.0-beta6 this should have better disconnect support.

  • disconnect events don't fire when you're closing the port
  • Close during writes causes an error, close during reads does not

All 5 comments

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.

  • disconnect events don't fire when you're closing the port
  • Close during writes causes an error, close during reads does not

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

callen5914 picture callen5914  路  7Comments

hugo-a-garcia picture hugo-a-garcia  路  8Comments

DariuszLuber picture DariuszLuber  路  9Comments

JBtje picture JBtje  路  8Comments

apiel picture apiel  路  5Comments