From ded2e9d82c8e9c386b1d556e5b02e56b3d9dfd4e Mon Sep 17 00:00:00 2001 From: Peli Date: Sun, 19 Jan 2020 21:37:52 -0800 Subject: [PATCH] don't close bt connection --- editor/deploy.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/editor/deploy.ts b/editor/deploy.ts index 09a85db4..b102dfe0 100644 --- a/editor/deploy.ts +++ b/editor/deploy.ts @@ -64,6 +64,7 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO { private _writer: any; constructor(private port: SerialPort, private options: SerialOptions) { + console.log(`serial: new io`) } async readSerialAsync() { @@ -90,17 +91,24 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO { return !!(navigator).serial; } + static portIos: WebSerialPackageIO[] = []; static async mkPacketIOAsync(): Promise { const serial = (navigator).serial; if (serial) { try { const requestOptions: SerialPortRequestOptions = {}; const port = await serial.requestPort(requestOptions); - const options: SerialOptions = { - baudrate: 460800, - buffersize: 4096 - }; - return new WebSerialPackageIO(port, options); + + let io = WebSerialPackageIO.portIos.filter(i => i.port == port)[0]; + if (!io) { + const options: SerialOptions = { + baudrate: 460800, + buffersize: 4096 + }; + io = new WebSerialPackageIO(port, options); + WebSerialPackageIO.portIos.push(io); + } + return io; } catch (e) { console.log(`connection error`, e) } @@ -125,11 +133,8 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO { }); } - private closeAsync() { - console.log(`serial: closing port`); - this.port.close(); - this._reader = undefined; - this._writer = undefined; + private async closeAsync() { + // don't close port return Promise.delay(500); }