From 09ccd5f291caf6a965f2f827470b3597ae8a1c73 Mon Sep 17 00:00:00 2001 From: Alex <52292902+alexrudd2@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:32:56 -0500 Subject: [PATCH] fix: --firmware-version not opening port (#176) * Call port.open() before querying it * Close the port --- src/ebb.ts | 4 ++-- src/server.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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; }