njs-modbus 1.5.0 → 2.0.1
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 +16 -0
- package/dist/index.cjs +2033 -1136
- package/dist/index.d.ts +315 -89
- package/dist/index.mjs +2026 -1137
- package/dist/src/error-code.d.ts +27 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/layers/application/abstract-application-layer.d.ts +11 -8
- package/dist/src/layers/application/ascii-application-layer.d.ts +15 -10
- package/dist/src/layers/application/index.d.ts +2 -0
- package/dist/src/layers/application/rtu-application-layer.d.ts +53 -18
- package/dist/src/layers/application/tcp-application-layer.d.ts +5 -8
- package/dist/src/layers/physical/abstract-physical-layer.d.ts +5 -1
- package/dist/src/layers/physical/index.d.ts +1 -0
- package/dist/src/layers/physical/serial-physical-layer.d.ts +2 -0
- package/dist/src/layers/physical/tcp-client-physical-layer.d.ts +3 -0
- package/dist/src/layers/physical/tcp-server-physical-layer.d.ts +3 -1
- package/dist/src/layers/physical/udp-physical-layer.d.ts +25 -10
- package/dist/src/master/index.d.ts +2 -0
- package/dist/src/master/master-session.d.ts +18 -0
- package/dist/src/master/master.d.ts +29 -5
- package/dist/src/slave/index.d.ts +1 -1
- package/dist/src/slave/slave.d.ts +20 -5
- package/dist/src/types.d.ts +33 -2
- package/dist/src/utils/bitsToMs.d.ts +13 -0
- package/dist/src/utils/crc.d.ts +1 -1
- package/dist/src/utils/genConnectionId.d.ts +2 -0
- package/dist/src/utils/index.d.ts +5 -1
- package/dist/src/utils/isUint8.d.ts +8 -0
- package/dist/src/utils/predictRtuFrameLength.d.ts +20 -0
- package/dist/src/vars.d.ts +47 -0
- package/dist/test/adu-buffer.test.d.ts +1 -0
- package/dist/test/ascii-hex-sentry.test.d.ts +1 -0
- package/dist/test/ascii-hex-validation.test.d.ts +1 -0
- package/dist/test/ascii-tcp-fragmentation.test.d.ts +1 -0
- package/dist/test/check-range.test.d.ts +1 -0
- package/dist/test/fallback-atomic.test.d.ts +1 -0
- package/dist/test/fallback-serial.test.d.ts +1 -0
- package/dist/test/fc17-serverid-validation.test.d.ts +1 -0
- package/dist/test/fc43-conformity.test.d.ts +1 -0
- package/dist/test/fc43-utf8-objects.test.d.ts +1 -0
- package/dist/test/gen-connection-id.test.d.ts +1 -0
- package/dist/test/helpers/raw-tcp.d.ts +38 -0
- package/dist/test/master-concurrent.test.d.ts +1 -0
- package/dist/test/modbus-error.test.d.ts +1 -0
- package/dist/test/physical-lifecycle.test.d.ts +1 -0
- package/dist/test/predict-rtu.test.d.ts +1 -0
- package/dist/test/rtu-custom-fc.test.d.ts +1 -0
- package/dist/test/rtu-pool-overflow.test.d.ts +1 -0
- package/dist/test/rtu-t15-timing.test.d.ts +1 -0
- package/dist/test/rtu-t35-default.test.d.ts +1 -0
- package/dist/test/rtu-t35-strict.test.d.ts +1 -0
- package/dist/test/rtu-tcp-fragmentation.test.d.ts +1 -0
- package/dist/test/serial-e2e.test.d.ts +1 -0
- package/dist/test/slave-multi-connection.test.d.ts +1 -0
- package/dist/test/tcp-fragmentation.test.d.ts +1 -0
- package/dist/test/udp-multi-client.test.d.ts +1 -0
- package/package.json +4 -2
- package/dist/src/utils/getThreePointFiveT.d.ts +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Server } from 'node:net';
|
|
2
|
+
import { Socket } from 'node:net';
|
|
3
|
+
export interface RawClient {
|
|
4
|
+
socket: Socket;
|
|
5
|
+
write: (data: Buffer) => Promise<void>;
|
|
6
|
+
end: () => Promise<void>;
|
|
7
|
+
onData: (callback: (chunk: Buffer) => void) => void;
|
|
8
|
+
collected: () => Buffer;
|
|
9
|
+
}
|
|
10
|
+
export declare function connectRawClient(port: number, host?: string): Promise<RawClient>;
|
|
11
|
+
export interface RawServer {
|
|
12
|
+
server: Server;
|
|
13
|
+
port: number;
|
|
14
|
+
/** Resolves with the first accepted socket. */
|
|
15
|
+
firstSocket: Promise<Socket>;
|
|
16
|
+
close: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare function startRawServer(port?: number, host?: string): Promise<RawServer>;
|
|
19
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
20
|
+
/** Build a Modbus TCP MBAP request frame. */
|
|
21
|
+
export declare function buildMbapRequest(opts: {
|
|
22
|
+
transaction: number;
|
|
23
|
+
unit: number;
|
|
24
|
+
fc: number;
|
|
25
|
+
data: Buffer | number[];
|
|
26
|
+
}): Buffer;
|
|
27
|
+
/** Build a Modbus RTU frame (PDU + 2-byte CRC, little-endian). */
|
|
28
|
+
export declare function buildRtuFrame(opts: {
|
|
29
|
+
unit: number;
|
|
30
|
+
fc: number;
|
|
31
|
+
data: Buffer | number[];
|
|
32
|
+
}): Buffer;
|
|
33
|
+
/** Build a Modbus ASCII frame: `:` + hex(unit + fc + data + LRC) + CRLF. */
|
|
34
|
+
export declare function buildAsciiFrame(opts: {
|
|
35
|
+
unit: number;
|
|
36
|
+
fc: number;
|
|
37
|
+
data: Buffer | number[];
|
|
38
|
+
}): Buffer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "njs-modbus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A pure JavaScript implemetation of Modbus for NodeJS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"modbus",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rollup -c",
|
|
35
|
-
"test": "tsx --test test
|
|
35
|
+
"test": "tsx --test \"test/*.test.ts\"",
|
|
36
36
|
"util:sort-package-json": "sort-package-json"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@microsoft/api-extractor": "^7.52.8",
|
|
41
41
|
"@nx/eslint-plugin": "21.1.3",
|
|
42
42
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
43
|
+
"@serialport/binding-mock": "^10.2.2",
|
|
43
44
|
"@swc-node/register": "~1.10.10",
|
|
44
45
|
"@swc/core": "~1.11.31",
|
|
45
46
|
"@swc/helpers": "~0.5.17",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"rollup": "^4.43.0",
|
|
56
57
|
"rollup-plugin-dts": "^6.2.1",
|
|
57
58
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
59
|
+
"serialport": ">=12.0.0",
|
|
58
60
|
"sort-package-json": "^3.2.1",
|
|
59
61
|
"tslib": "^2.8.1",
|
|
60
62
|
"typescript": "~5.8.3",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get time interval between message frames witch well-known as 3.5T.
|
|
3
|
-
* @param baudRate Serial port baud rate.
|
|
4
|
-
* @param {number} [approximation=48] Approximate number of bits corresponding to 3.5T.
|
|
5
|
-
* @returns `ms`.
|
|
6
|
-
*/
|
|
7
|
-
export declare function getThreePointFiveT(baudRate: number, approximation?: number): number;
|