don't close bt connection
This commit is contained in:
parent
8280937d92
commit
e8468ab62c
@ -59,6 +59,7 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
private _writer: any;
|
private _writer: any;
|
||||||
|
|
||||||
constructor(private port: SerialPort, private options: SerialOptions) {
|
constructor(private port: SerialPort, private options: SerialOptions) {
|
||||||
|
console.log(`serial: new io`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async readSerialAsync() {
|
async readSerialAsync() {
|
||||||
@ -85,17 +86,24 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
return !!(<any>navigator).serial;
|
return !!(<any>navigator).serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static portIos: WebSerialPackageIO[] = [];
|
||||||
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
||||||
const serial = (<any>navigator).serial;
|
const serial = (<any>navigator).serial;
|
||||||
if (serial) {
|
if (serial) {
|
||||||
try {
|
try {
|
||||||
const requestOptions: SerialPortRequestOptions = {};
|
const requestOptions: SerialPortRequestOptions = {};
|
||||||
const port = await serial.requestPort(requestOptions);
|
const port = await serial.requestPort(requestOptions);
|
||||||
const options: SerialOptions = {
|
|
||||||
baudrate: 460800,
|
let io = WebSerialPackageIO.portIos.filter(i => i.port == port)[0];
|
||||||
buffersize: 4096
|
if (!io) {
|
||||||
};
|
const options: SerialOptions = {
|
||||||
return new WebSerialPackageIO(port, options);
|
baudrate: 460800,
|
||||||
|
buffersize: 4096
|
||||||
|
};
|
||||||
|
io = new WebSerialPackageIO(port, options);
|
||||||
|
WebSerialPackageIO.portIos.push(io);
|
||||||
|
}
|
||||||
|
return io;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`connection error`, e)
|
console.log(`connection error`, e)
|
||||||
}
|
}
|
||||||
@ -120,11 +128,8 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeAsync() {
|
private async closeAsync() {
|
||||||
console.log(`serial: closing port`);
|
// don't close port
|
||||||
this.port.close();
|
|
||||||
this._reader = undefined;
|
|
||||||
this._writer = undefined;
|
|
||||||
return Promise.delay(500);
|
return Promise.delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user