From ee33b492c544a8b3b9bbc912d850622ad7ee365c Mon Sep 17 00:00:00 2001 From: Yan <2031974+yangit@users.noreply.github.com> Date: Sun, 21 Apr 2024 02:54:28 +0800 Subject: [PATCH] Fix write-single-coil.ts incorrect processing of true value #338 The WriteSingleCoilResponseBody constructor declares that it can handle `boolen` but it can not do that. So I have addled boolean handling into the function. --- src/response/write-single-coil.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/response/write-single-coil.ts b/src/response/write-single-coil.ts index 396f375..2ce6363 100644 --- a/src/response/write-single-coil.ts +++ b/src/response/write-single-coil.ts @@ -53,8 +53,12 @@ export default class WriteSingleCoilResponseBody extends ModbusWriteResponseBody constructor (address: number, value: 0 | 0xff00 | boolean) { super(FC.WRITE_SINGLE_COIL) this._address = address - - this._value = value === 0xFF00 ? 0xFF00 : 0x0000 + + if (value === true || value === 0xFF00) { + this._value = 0xFF00 + } else { + this._value = 0x0000 + } } public createPayload () {