From 065d48d8fe7e924fb02c42ab24250dc55c67b365 Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Fri, 24 Jun 2022 22:20:51 +0200 Subject: [PATCH] Forward SerialPort error event --- README.md | 2 +- src/index.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 31aece6..4ce3864 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,4 @@ import { EnttecOpenDMXUSBDevice as DMXDevice } from "enttec-open-dmx-usb"; ## Events `ready` - `startSending` can be called. -`error` - An error occurred. +`error` - An error occurred. The error can also originate from SerialPort. diff --git a/src/index.ts b/src/index.ts index 2b197fa..c967f92 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,13 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter { this.emit("ready") if (startSending) this.startSending(0) }) + // Forward SerialPort errors. + // If nothing is attaching to the SerialPort error event, the Node process will be terminated + // in case of an error (e.g. wrong device passed) which would not permit error handling in + // projects using this package. + this.port.on("error", (error: Error) => { + this.emit("error", error) + }) } /**