diff --git a/src/ebb.ts b/src/ebb.ts index 7f12aea..f054783 100644 --- a/src/ebb.ts +++ b/src/ebb.ts @@ -24,7 +24,7 @@ export class EBB { public constructor(port: SerialPort) { this.port = port; - this.writer = this.port.writable.getWriter() + this.writer = this.port.writable.getWriter(); this.commandQueue = []; this.readableClosed = port.readable .pipeThrough(new RegexParser({ regex: /[\r\n]+/ })) @@ -66,7 +66,7 @@ export class EBB { } public async close(): Promise { - throw new Error("TODO") + return await this.port.close() } private write(str: string): Promise { diff --git a/src/server.ts b/src/server.ts index a5f8247..4362b8f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -288,11 +288,13 @@ async function* ebbs(path?: string) { export async function connectEBB(path: string | undefined): Promise { if (path) { - return new EBB(new SerialPortSerialPort(path)); + const port = await tryOpen(path); + return new EBB(port); } else { const ebbs = await listEBBs(); if (ebbs.length) { - return new EBB(new SerialPortSerialPort(ebbs[0])); + const port = await tryOpen(ebbs[0]); + return new EBB(port); } else { return null; }