webusb / arduino

WebUSB demos running on Arduino (and compatible) hardware.
576 stars 152 forks source link

fixed port object not destroy after disconnect #56

Closed jpliew closed 5 years ago

jpliew commented 5 years ago

On console example, when a user disconnect the port, the port object was not deleted like the rgb example https://github.com/webusb/arduino/blob/fab0eca52a6ea813e97607a75270bec1399dc77a/demos/rgb/rgb.js#L50

After disconnected, when user click the connect button again, there was an error The device must be opened first. This happens because the port object was already disconnected and will throw this error when a disconnect is called on a disconnected port.

image

No device selection dialog was offered when this happened.

Adding a line port=null after port.disconnect() just like the the rgb example fixed the error message and a device selection dialog will be offered each time

Hope this helps.

JP