njs-modbus 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ interface ApplicationDataUnit {
12
12
  data: Buffer;
13
13
  }
14
14
  interface ServerId {
15
- /** Server ID; may be 1 byte (number) or multi-byte (number[]) per device spec. */
15
+ /** Server ID as a byte array (e.g. single-byte IDs use `[id]`). */
16
16
  serverId?: number[];
17
17
  runIndicatorStatus?: boolean;
18
18
  additionalData?: number[];
@@ -52,6 +52,8 @@ interface CustomFunctionCode {
52
52
  * @param start — Byte offset in `buffer` where the current candidate frame begins
53
53
  * (the unit ID byte). Read the function code at `buffer[start + 1]` and derive
54
54
  * the total frame length from the trailing bytes.
55
+ * @param end — Byte offset one past the last valid byte. Bounds checks must use
56
+ * `end - start` as available bytes, NOT `buffer.length` (pool capacity).
55
57
  * @returns Total frame length (>= 4, <= 256), or `null` if more bytes are needed.
56
58
  */
57
59
  predictRequestLength: (buffer: Buffer, start: number, end: number) => number | null;
@@ -670,7 +672,7 @@ declare class ModbusMaster<T extends ModbusMasterOptions = ModbusMasterOptions>
670
672
  sendCustomFC(unit: 0, fc: number, data: Buffer | number[], timeout?: number): Promise<void>;
671
673
  sendCustomFC(unit: number, fc: number, data: Buffer | number[], timeout?: number): Promise<Buffer>;
672
674
  /**
673
- * Open the underlying physical layer and begin accepting connections.
675
+ * Open the underlying physical layer and establish a connection.
674
676
  *
675
677
  * A `ModbusMaster` instance can only be opened once. Once {@link close}
676
678
  * is called — explicitly or because the physical layer disconnected —
@@ -715,15 +717,19 @@ interface ModbusSlaveModel {
715
717
  * Otherwise keep the default read and write behavior.
716
718
  */
717
719
  interceptor?: MaybeAsyncFunction<(fc: number, data: Buffer) => Buffer | undefined>;
718
- readDiscreteInputs?: MaybeAsyncFunction<(address: number, length: number) => boolean[]>;
719
- readCoils?: MaybeAsyncFunction<(address: number, length: number) => boolean[]>;
720
+ /** Return `Uint8Array` to avoid the `Array.from` allocation overhead. */
721
+ readDiscreteInputs?: MaybeAsyncFunction<(address: number, length: number) => boolean[] | Uint8Array>;
722
+ /** Return `Uint8Array` to avoid the `Array.from` allocation overhead. */
723
+ readCoils?: MaybeAsyncFunction<(address: number, length: number) => boolean[] | Uint8Array>;
720
724
  writeSingleCoil?: MaybeAsyncFunction<(address: number, value: boolean) => void>;
721
725
  /**
722
726
  * If omitted, defaults to loop and call `writeSingleCoil`.
723
727
  */
724
728
  writeMultipleCoils?: MaybeAsyncFunction<(address: number, value: boolean[]) => void>;
725
- readInputRegisters?: MaybeAsyncFunction<(address: number, length: number) => number[]>;
726
- readHoldingRegisters?: MaybeAsyncFunction<(address: number, length: number) => number[]>;
729
+ /** Return `Uint16Array` to avoid the `Array.from` allocation overhead. */
730
+ readInputRegisters?: MaybeAsyncFunction<(address: number, length: number) => number[] | Uint16Array>;
731
+ /** Return `Uint16Array` to avoid the `Array.from` allocation overhead. */
732
+ readHoldingRegisters?: MaybeAsyncFunction<(address: number, length: number) => number[] | Uint16Array>;
727
733
  writeSingleRegister?: MaybeAsyncFunction<(address: number, value: number) => void>;
728
734
  /**
729
735
  * If omitted, defaults to loop and call `writeSingleRegister`.