njs-modbus 3.1.1 → 3.2.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/README.md +20 -0
- package/README.zh-CN.md +20 -0
- package/dist/index.cjs +878 -384
- package/dist/index.d.ts +87 -25
- package/dist/index.mjs +878 -385
- package/dist/utils.cjs +439 -0
- package/dist/utils.d.ts +161 -0
- package/dist/utils.mjs +425 -0
- package/package.json +15 -2
- package/dist/src/error-code.d.ts +0 -17
- package/dist/src/index.d.ts +0 -7
- package/dist/src/layers/application/abstract-application-layer.d.ts +0 -26
- package/dist/src/layers/application/ascii-application-layer.d.ts +0 -23
- package/dist/src/layers/application/index.d.ts +0 -6
- package/dist/src/layers/application/rtu-application-layer.d.ts +0 -34
- package/dist/src/layers/application/tcp-application-layer.d.ts +0 -16
- package/dist/src/layers/physical/abstract-physical-layer.d.ts +0 -50
- package/dist/src/layers/physical/index.d.ts +0 -12
- package/dist/src/layers/physical/serial-physical-layer.d.ts +0 -70
- package/dist/src/layers/physical/tcp-client-physical-layer.d.ts +0 -20
- package/dist/src/layers/physical/tcp-physical-connection.d.ts +0 -16
- package/dist/src/layers/physical/tcp-server-physical-layer.d.ts +0 -29
- package/dist/src/layers/physical/udp-client-physical-layer.d.ts +0 -34
- package/dist/src/layers/physical/udp-server-physical-layer.d.ts +0 -51
- package/dist/src/layers/physical/utils.d.ts +0 -39
- package/dist/src/layers/physical/vars.d.ts +0 -11
- package/dist/src/master/index.d.ts +0 -3
- package/dist/src/master/master-session.d.ts +0 -18
- package/dist/src/master/master.d.ts +0 -140
- package/dist/src/slave/index.d.ts +0 -2
- package/dist/src/slave/slave.d.ts +0 -119
- package/dist/src/types.d.ts +0 -54
- package/dist/src/utils/bitsToMs.d.ts +0 -13
- package/dist/src/utils/callback.d.ts +0 -8
- package/dist/src/utils/checkRange.d.ts +0 -1
- package/dist/src/utils/crc.d.ts +0 -1
- package/dist/src/utils/index.d.ts +0 -11
- package/dist/src/utils/isUint8.d.ts +0 -8
- package/dist/src/utils/lrc.d.ts +0 -1
- package/dist/src/utils/predictRtuFrameLength.d.ts +0 -17
- package/dist/src/utils/promisify-cb.d.ts +0 -4
- package/dist/src/utils/rtu-timing.d.ts +0 -63
- package/dist/src/utils/whitelist.d.ts +0 -11
- package/dist/src/vars.d.ts +0 -49
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true when `n` is an integer in the unsigned-byte range [0, 255].
|
|
3
|
-
*
|
|
4
|
-
* Used for byte-level Modbus payload validation (function-code values, raw
|
|
5
|
-
* byte arrays in FC17/FC43 responses) — rejects negative, fractional, NaN,
|
|
6
|
-
* Infinity, and out-of-range values uniformly.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isUint8(n: number): boolean;
|
package/dist/src/utils/lrc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function lrc(data: Uint8Array): number;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Sentinel: caller needs to feed more bytes before length can be determined. */
|
|
2
|
-
export declare const PREDICT_NEED_MORE = 0;
|
|
3
|
-
/** Sentinel: function code is not in the standard tables. */
|
|
4
|
-
export declare const PREDICT_UNKNOWN = -1;
|
|
5
|
-
/**
|
|
6
|
-
* Predict the total RTU frame length (PDU + 2-byte CRC) given the leading bytes.
|
|
7
|
-
*
|
|
8
|
-
* Returns a sentinel-encoded number to avoid per-call object allocation on the
|
|
9
|
-
* RTU decode hot path:
|
|
10
|
-
* - Positive integer (>= 4): total frame length, function code is known.
|
|
11
|
-
* - {@link PREDICT_NEED_MORE} (0): function code is known but more bytes are
|
|
12
|
-
* required (typically waiting on the byteCount byte).
|
|
13
|
-
* - {@link PREDICT_UNKNOWN} (-1): function code is not in the standard tables —
|
|
14
|
-
* the framing layer must defer to a registered `CustomFunctionCode` or treat
|
|
15
|
-
* this as a framing error.
|
|
16
|
-
*/
|
|
17
|
-
export declare function predictRtuFrameLength(buffer: Buffer, isResponse: boolean): number;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RTU timing parameter — accepts either:
|
|
3
|
-
* - a bare `number` in milliseconds (`0` to disable the timer entirely)
|
|
4
|
-
* - `{ unit: 'ms', value: N }` — explicit milliseconds (equivalent to bare `N`)
|
|
5
|
-
* - `{ unit: 'bit', value: N }` — bit-time approximation, derived from `baudRate`
|
|
6
|
-
*
|
|
7
|
-
* The bare-number form is the recommended default; the object form exists for
|
|
8
|
-
* specs that quote bit-time. Pass `0` (or `{ unit: 'ms', value: 0 }`) to disable
|
|
9
|
-
* the timer; either form short-circuits the baudRate-derived fallback.
|
|
10
|
-
*/
|
|
11
|
-
export type RtuTimingValue = number | {
|
|
12
|
-
unit: 'bit' | 'ms';
|
|
13
|
-
value: number;
|
|
14
|
-
};
|
|
15
|
-
/** User-facing RTU protocol options (supports both bit and ms units). */
|
|
16
|
-
export interface RtuProtocolOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Inter-frame silence (Modbus RTU t3.5).
|
|
19
|
-
*
|
|
20
|
-
* - `20` or `{ unit: 'ms', value: 20 }` — 20 ms
|
|
21
|
-
* - `{ unit: 'bit', value: 38.5 }` — spec bit-time approximation (default when `baudRate` is provided)
|
|
22
|
-
* - `0` — disable t3.5 timing (immediate parse on every chunk; useful for
|
|
23
|
-
* lossless transports such as RTU-over-TCP or PTY-based tests where the
|
|
24
|
-
* wire's silence semantics do not apply)
|
|
25
|
-
*
|
|
26
|
-
* Per Modbus V1.02 §2.5.1.1, at baud rates > 19200 a fixed 1.75 ms is used
|
|
27
|
-
* regardless of the bit value.
|
|
28
|
-
*/
|
|
29
|
-
intervalBetweenFrames?: RtuTimingValue;
|
|
30
|
-
/**
|
|
31
|
-
* Inter-character timeout (Modbus RTU t1.5). Opt-in; **disabled** by default.
|
|
32
|
-
*
|
|
33
|
-
* - `1` or `{ unit: 'ms', value: 1 }` — 1 ms
|
|
34
|
-
* - `{ unit: 'bit', value: 21 }` — bit-time approximation (~1.5 char times)
|
|
35
|
-
* - `0` — disable explicitly
|
|
36
|
-
*
|
|
37
|
-
* Per Modbus V1.02 §2.5.1.1, at baud rates > 19200 a fixed 0.75 ms is used
|
|
38
|
-
* regardless of the bit value.
|
|
39
|
-
*/
|
|
40
|
-
interCharTimeout?: RtuTimingValue;
|
|
41
|
-
/**
|
|
42
|
-
* Buffer pool size per connection (bytes). Defaults to `MAX_FRAME_LENGTH * 2`
|
|
43
|
-
* (512 bytes). Increase this if you expect frames larger than 256 bytes or
|
|
44
|
-
* heavy pipelining on a single connection.
|
|
45
|
-
*/
|
|
46
|
-
poolSize?: number;
|
|
47
|
-
}
|
|
48
|
-
/** Resolved RTU timing values in milliseconds. */
|
|
49
|
-
export interface ResolvedRtuTiming {
|
|
50
|
-
intervalBetweenFrames: number;
|
|
51
|
-
interCharTimeout: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Resolve Modbus RTU timing parameters from user options into milliseconds.
|
|
55
|
-
*
|
|
56
|
-
* - `intervalBetweenFrames` (t3.5): if omitted and `baudRate` is present,
|
|
57
|
-
* defaults to 38.5 bits per Modbus V1.02 §2.5.1.1. Pass `0` to disable.
|
|
58
|
-
* - `interCharTimeout` (t1.5): opt-in; only resolved when explicitly provided.
|
|
59
|
-
*
|
|
60
|
-
* Per the spec, at baud rates > 19200 fixed values are used
|
|
61
|
-
* (1.75 ms for t3.5, 0.75 ms for t1.5) regardless of the bit value.
|
|
62
|
-
*/
|
|
63
|
-
export declare function resolveRtuTiming(opts?: RtuProtocolOptions, baudRate?: number): ResolvedRtuTiming;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize an IP address by stripping the IPv4-mapped IPv6 prefix.
|
|
3
|
-
* This ensures consistent comparison of addresses like `::ffff:192.168.1.1`.
|
|
4
|
-
*/
|
|
5
|
-
export declare function normalizeAddress(address?: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Check whether a remote address is allowed by the given whitelist.
|
|
8
|
-
* IPv4-mapped IPv6 addresses are normalized before comparison.
|
|
9
|
-
* Returns `true` when whitelist is absent or empty.
|
|
10
|
-
*/
|
|
11
|
-
export declare function isWhitelisted(address: string | undefined, whitelist: string[] | undefined): boolean;
|
package/dist/src/vars.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard Modbus function codes (V1.1b3 §6).
|
|
3
|
-
*/
|
|
4
|
-
export declare enum FunctionCode {
|
|
5
|
-
READ_COILS = 1,
|
|
6
|
-
READ_DISCRETE_INPUTS = 2,
|
|
7
|
-
READ_HOLDING_REGISTERS = 3,
|
|
8
|
-
READ_INPUT_REGISTERS = 4,
|
|
9
|
-
WRITE_SINGLE_COIL = 5,
|
|
10
|
-
WRITE_SINGLE_REGISTER = 6,
|
|
11
|
-
WRITE_MULTIPLE_COILS = 15,
|
|
12
|
-
WRITE_MULTIPLE_REGISTERS = 16,
|
|
13
|
-
REPORT_SERVER_ID = 17,
|
|
14
|
-
MASK_WRITE_REGISTER = 22,
|
|
15
|
-
READ_WRITE_MULTIPLE_REGISTERS = 23,
|
|
16
|
-
READ_DEVICE_IDENTIFICATION = 43
|
|
17
|
-
}
|
|
18
|
-
/** Exception response FC = request FC | EXCEPTION_OFFSET (V1.1b3 §7). */
|
|
19
|
-
export declare const EXCEPTION_OFFSET = 128;
|
|
20
|
-
/** Coil value encoding for FC 5 / FC 15 (V1.1b3 §6.5/§6.11). */
|
|
21
|
-
export declare const COIL_ON = 65280;
|
|
22
|
-
export declare const COIL_OFF = 0;
|
|
23
|
-
/** FC 0x2B MEI sub-function selecting Read Device Identification (V1.1b3 §6.21). */
|
|
24
|
-
export declare const MEI_READ_DEVICE_ID = 14;
|
|
25
|
-
/** Read Device ID code values inside an FC 0x2B / MEI 0x0E request. */
|
|
26
|
-
export declare enum ReadDeviceIDCode {
|
|
27
|
-
BASIC_STREAM = 1,
|
|
28
|
-
REGULAR_STREAM = 2,
|
|
29
|
-
EXTENDED_STREAM = 3,
|
|
30
|
-
SPECIFIC_ACCESS = 4
|
|
31
|
-
}
|
|
32
|
-
/** Conformity level reported in an FC 0x2B / MEI 0x0E response. */
|
|
33
|
-
export declare enum ConformityLevel {
|
|
34
|
-
BASIC = 129,
|
|
35
|
-
REGULAR = 130,
|
|
36
|
-
EXTENDED = 131
|
|
37
|
-
}
|
|
38
|
-
/** Shared empty Buffer to avoid repeated allocations. */
|
|
39
|
-
export declare const EMPTY_BUFFER: Buffer<ArrayBuffer>;
|
|
40
|
-
/** Modbus V1.1b3 PDU quantity limits. */
|
|
41
|
-
export declare const LIMITS: {
|
|
42
|
-
readonly READ_COILS_MIN: 1;
|
|
43
|
-
readonly READ_COILS_MAX: 2000;
|
|
44
|
-
readonly READ_REGISTERS_MIN: 1;
|
|
45
|
-
readonly READ_REGISTERS_MAX: 125;
|
|
46
|
-
readonly WRITE_COILS_MAX: 1968;
|
|
47
|
-
readonly WRITE_REGISTERS_MAX: 123;
|
|
48
|
-
readonly RW_REGISTERS_WRITE_MAX: 121;
|
|
49
|
-
};
|