firmata / firmata.js

JavaScript implementation of the Firmata protocol
711 stars 147 forks source link

Firmata.JS unplug detection broken #234

Closed MattTavares closed 3 years ago

MattTavares commented 3 years ago

The upstream serialport library does not document or seemingly support event.disconnect as a valid error in the stream interface. The following line: https://github.com/firmata/firmata.js/blob/54dda2d2112e9fc3f997324df22d59f6e3d05298/packages/firmata-io/lib/firmata.js#L597 never triggers because only event and event.disconnected are returned true. This breaks detection of devices when they have been unplugged. In my case this is breaking my ability to reconnect in the node-red-node-arduino downstream dependency after an arduino (or in my case a Teensy 4) is disconnected and reconnected. Simply changing the line to read if (event && event.disconnected) { seems to fix everything

For reproducing my install I am running on raspberry pi OS Buster 10, Node-Red 1.2.9, Serial 9.0.7, and the latest firmata v2.2.0

rwaldron commented 3 years ago

@reconbot

reconbot commented 3 years ago

That seems right to me https://serialport.io/docs/api-stream#close

rwaldron commented 3 years ago

@MattTavares do you want to make a patch/pr?

rwaldron commented 3 years ago

Merged patch