diff options
| author | raldone01 <[email protected]> | 2025-07-08 11:31:57 +0200 |
|---|---|---|
| committer | raldone01 <[email protected]> | 2025-07-08 11:31:57 +0200 |
| commit | 1dcab4346889eb0c1906550ced954cdccfa8bedd (patch) | |
| tree | 4a1a6e7595f422aa9d3ab8a7a4c24f70c5bb4bb7 /examples/device/webusb_serial/website/serial.js | |
| parent | ce40b4c11e69520c9fe0274f9950d0557a0180a4 (diff) | |
Fix ui desync issue. Fix disconnection issue.
Diffstat (limited to 'examples/device/webusb_serial/website/serial.js')
| -rw-r--r-- | examples/device/webusb_serial/website/serial.js | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/examples/device/webusb_serial/website/serial.js b/examples/device/webusb_serial/website/serial.js index 18bb8a717..7068a7069 100644 --- a/examples/device/webusb_serial/website/serial.js +++ b/examples/device/webusb_serial/website/serial.js @@ -42,19 +42,9 @@ class SerialPort { } } - async _waitForReadLoopToFinish() { - if (this.readLoop) { - try { - await this.readLoop; - } catch (error) {} - this.readLoop = null; - } - } - /// Stop reading and release port async disconnect() { this.isConnected = false; - await this._waitForReadLoopToFinish(); if (this.reader) { try { @@ -66,7 +56,8 @@ class SerialPort { if (this.writer) { try { await this.writer.close(); - } catch (error) {} + } catch (error) { } + this.writer.releaseLock(); } if (this.readableStreamClosed) { @@ -160,15 +151,6 @@ class WebUsbSerialPort { this.readLoop = this._readLoop(); } - async _waitForReadLoopToFinish() { - if (this.readLoop) { - try { - await this.readLoop; - } catch (error) {} - this.readLoop = null; - } - } - /// Internal continuous read loop async _readLoop() { while (this.isConnected) { @@ -189,7 +171,6 @@ class WebUsbSerialPort { /// Stop reading and release device async disconnect() { this.isConnected = false; - await this._waitForReadLoopToFinish(); if (!this.device.opened) return; try { await this.device.controlTransferOut({ @@ -199,9 +180,7 @@ class WebUsbSerialPort { value: 0x00, index: this.interfaceNumber, }); - } catch (error) { - console.log(error); - } + } catch (error) {} await this.device.close(); } |
