Skip to content

Commit 2121bc3

Browse files
Try to force disconnections
1 parent ababfb4 commit 2121bc3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

kernel/src/services/DeviceService.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ export class DeviceService {
5454
async disconnect(): Promise<void> {
5555
if (this.port) {
5656
try {
57-
if ((this.port.readable && this.port.readable.locked) ||
58-
(this.port.writable && this.port.writable.locked)) {
59-
console.warn('Serial port has locked streams. Cannot close directly.');
60-
this.isDeviceConnected = false;
61-
return;
62-
}
57+
if (this.port.readable)
58+
await this.port.readable.cancel();
59+
else if (this.port.writable)
60+
await this.port.writable.abort();
61+
else
62+
await this.port.close();
6363

64-
await this.port.close();
6564
console.log('Device disconnected successfully');
6665
} catch (err) {
6766
console.error('Failed to disconnect:', err);

0 commit comments

Comments
 (0)