@ya-modbus/transport 0.10.0 → 0.11.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/CHANGELOG.md +12 -0
- package/README.md +22 -0
- package/dist/cjs/src/client-config.d.ts +15 -0
- package/dist/cjs/src/client-config.d.ts.map +1 -1
- package/dist/cjs/src/client-config.js +26 -0
- package/dist/cjs/src/client-config.js.map +1 -1
- package/dist/cjs/src/connection.d.ts +18 -3
- package/dist/cjs/src/connection.d.ts.map +1 -1
- package/dist/cjs/src/connection.js +43 -23
- package/dist/cjs/src/connection.js.map +1 -1
- package/dist/cjs/src/index.d.ts +1 -1
- package/dist/cjs/src/index.d.ts.map +1 -1
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/manager.d.ts +37 -0
- package/dist/cjs/src/manager.d.ts.map +1 -1
- package/dist/cjs/src/manager.js +58 -15
- package/dist/cjs/src/manager.js.map +1 -1
- package/dist/cjs/src/tcp-transport.d.ts +1 -1
- package/dist/cjs/src/tcp-transport.d.ts.map +1 -1
- package/dist/cjs/src/tcp-transport.js +1 -1
- package/dist/cjs/src/tcp-transport.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/client-config.d.ts +15 -0
- package/dist/esm/src/client-config.d.ts.map +1 -1
- package/dist/esm/src/client-config.js +25 -0
- package/dist/esm/src/client-config.js.map +1 -1
- package/dist/esm/src/connection.d.ts +18 -3
- package/dist/esm/src/connection.d.ts.map +1 -1
- package/dist/esm/src/connection.js +43 -23
- package/dist/esm/src/connection.js.map +1 -1
- package/dist/esm/src/index.d.ts +1 -1
- package/dist/esm/src/index.d.ts.map +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/manager.d.ts +37 -0
- package/dist/esm/src/manager.d.ts.map +1 -1
- package/dist/esm/src/manager.js +59 -16
- package/dist/esm/src/manager.js.map +1 -1
- package/dist/esm/src/tcp-transport.d.ts +1 -1
- package/dist/esm/src/tcp-transport.d.ts.map +1 -1
- package/dist/esm/src/tcp-transport.js +2 -2
- package/dist/esm/src/tcp-transport.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -12,4 +12,19 @@ export declare const DEFAULT_TIMEOUT_MS = 1000;
|
|
|
12
12
|
* @param timeout - Response timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
13
13
|
*/
|
|
14
14
|
export declare function configureClient(client: ModbusRTU, slaveId: number, timeout?: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Connect a modbus-serial client to a Modbus TCP server, and give up after `timeout` ms when
|
|
17
|
+
* the host does not answer
|
|
18
|
+
*
|
|
19
|
+
* Without a timeout, the connect waits for the TCP timeout of the system (about 2 minutes on
|
|
20
|
+
* Linux). modbus-serial uses the `timeout` option as the socket timeout, so a connect that
|
|
21
|
+
* takes longer fails with 'TCP Connection Timed Out'. After the connect, the socket keeps
|
|
22
|
+
* the timeout, but then it does not close the socket.
|
|
23
|
+
*
|
|
24
|
+
* @param client - New modbus-serial client
|
|
25
|
+
* @param host - TCP host (IP address or hostname)
|
|
26
|
+
* @param port - TCP port
|
|
27
|
+
* @param timeout - Connect timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
28
|
+
*/
|
|
29
|
+
export declare function connectTCP(client: ModbusRTU, host: string, port: number, timeout?: number): Promise<void>;
|
|
15
30
|
//# sourceMappingURL=client-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAG1F"}
|
|
1
|
+
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAG1F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,SAAqB,GAC3B,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -14,4 +14,29 @@ export function configureClient(client, slaveId, timeout) {
|
|
|
14
14
|
client.setID(slaveId);
|
|
15
15
|
client.setTimeout(timeout ?? DEFAULT_TIMEOUT_MS);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Connect a modbus-serial client to a Modbus TCP server, and give up after `timeout` ms when
|
|
19
|
+
* the host does not answer
|
|
20
|
+
*
|
|
21
|
+
* Without a timeout, the connect waits for the TCP timeout of the system (about 2 minutes on
|
|
22
|
+
* Linux). modbus-serial uses the `timeout` option as the socket timeout, so a connect that
|
|
23
|
+
* takes longer fails with 'TCP Connection Timed Out'. After the connect, the socket keeps
|
|
24
|
+
* the timeout, but then it does not close the socket.
|
|
25
|
+
*
|
|
26
|
+
* @param client - New modbus-serial client
|
|
27
|
+
* @param host - TCP host (IP address or hostname)
|
|
28
|
+
* @param port - TCP port
|
|
29
|
+
* @param timeout - Connect timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
30
|
+
*/
|
|
31
|
+
export async function connectTCP(client, host, port, timeout = DEFAULT_TIMEOUT_MS) {
|
|
32
|
+
try {
|
|
33
|
+
await client.connectTCP(host, { port, timeout });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// After a timeout the socket still tries to connect. A connection that it opens later
|
|
37
|
+
// would stay open with nothing using it.
|
|
38
|
+
client.destroy(() => undefined);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
17
42
|
//# sourceMappingURL=client-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-config.js","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,OAAe,EAAE,OAAgB;IAClF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrB,MAAM,CAAC,UAAU,CAAC,OAAO,IAAI,kBAAkB,CAAC,CAAA;AAClD,CAAC"}
|
|
1
|
+
{"version":3,"file":"client-config.js","sourceRoot":"","sources":["../../../src/client-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,OAAe,EAAE,OAAgB;IAClF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrB,MAAM,CAAC,UAAU,CAAC,OAAO,IAAI,kBAAkB,CAAC,CAAA;AAClD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAiB,EACjB,IAAY,EACZ,IAAY,EACZ,OAAO,GAAG,kBAAkB;IAE5B,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sFAAsF;QACtF,yCAAyC;QACzC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC/B,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -34,13 +34,15 @@ declare const CONNECTION: unique symbol;
|
|
|
34
34
|
* not lead to a successful request, up to MAX_REOPEN_DELAY_MS.
|
|
35
35
|
* - without an `open` function, requests reject until the owner of the client
|
|
36
36
|
* opens it again
|
|
37
|
+
*
|
|
38
|
+
* A connection created with the error of a failed open (for example a USB serial
|
|
39
|
+
* adapter that is not plugged in) starts lost in the same way.
|
|
37
40
|
*/
|
|
38
41
|
export declare class ModbusConnection {
|
|
39
42
|
private readonly target?;
|
|
40
43
|
private readonly open?;
|
|
41
44
|
readonly [CONNECTION] = true;
|
|
42
|
-
private
|
|
43
|
-
private lostError;
|
|
45
|
+
private state;
|
|
44
46
|
private reopenDelay;
|
|
45
47
|
private reopenAt;
|
|
46
48
|
private reopening;
|
|
@@ -51,7 +53,20 @@ export declare class ModbusConnection {
|
|
|
51
53
|
* @param target - Port path or host:port, used in error messages
|
|
52
54
|
* @param open - Opens a new client after the connection is lost
|
|
53
55
|
*/
|
|
54
|
-
constructor(client: ModbusRTU, target?: string
|
|
56
|
+
constructor(client: ModbusRTU, target?: string, open?: OpenClient);
|
|
57
|
+
/**
|
|
58
|
+
* @param openError - Error of a failed attempt to open the port. The connection starts
|
|
59
|
+
* lost: requests reject with a ConnectionLostError, and the first request after
|
|
60
|
+
* REOPEN_DELAY_MS calls `open`.
|
|
61
|
+
* @param target - Port path or host:port, used in error messages
|
|
62
|
+
* @param open - Opens a new client
|
|
63
|
+
*/
|
|
64
|
+
constructor(openError: Error, target: string | undefined, open: OpenClient);
|
|
65
|
+
/**
|
|
66
|
+
* The error that requests reject with while the connection is lost, or undefined while it
|
|
67
|
+
* works. The request that opens the port again clears it.
|
|
68
|
+
*/
|
|
69
|
+
get error(): ModbusError | undefined;
|
|
55
70
|
/**
|
|
56
71
|
* Run a request with the client
|
|
57
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE7E,kFAAkF;AAClF,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,QAAS,CAAA;AAEzC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;AAEjD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAE1E;AAeD,8EAA8E;AAC9E,QAAA,MAAM,UAAU,eAAsD,CAAA;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE7E,kFAAkF;AAClF,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,QAAS,CAAA;AAEzC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;AAEjD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAE1E;AAeD,8EAA8E;AAC9E,QAAA,MAAM,UAAU,eAAsD,CAAA;AAmCtE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAgB;IAyBzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAzBxB,QAAQ,CAAC,CAAC,UAAU,CAAC,QAAO;IAC5B,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAI;IACpB,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE;;;;OAIG;gBACS,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU;IACjE;;;;;;OAMG;gBACS,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,UAAU;IAe1E;;;OAGG;IACH,IAAI,KAAK,IAAI,WAAW,GAAG,SAAS,CAEnC;IAED;;;;;;OAMG;IACG,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA2BpE;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,IAAI;IAaZ,8EAA8E;IAC9E,OAAO,CAAC,WAAW;IAKnB;;;;OAIG;IACH,OAAO,CAAC,MAAM;YAmBA,UAAU;CAqBzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,GAAG,gBAAgB,CAEnF"}
|
|
@@ -33,11 +33,16 @@ function closeClient(client, callback) {
|
|
|
33
33
|
/** Marks ModbusConnection objects, the same for all copies of this package */
|
|
34
34
|
const CONNECTION = Symbol.for('@ya-modbus/transport/ModbusConnection');
|
|
35
35
|
/**
|
|
36
|
-
* Error for a lost connection, with code and errno of a
|
|
36
|
+
* Error for a lost connection, or for a port that was never open, with code and errno of a
|
|
37
|
+
* Node.js system error cause
|
|
37
38
|
*/
|
|
38
|
-
function connectionLostError(target, cause) {
|
|
39
|
+
function connectionLostError(target, cause, wasOpen = true) {
|
|
39
40
|
const reason = normalizeModbusError(cause);
|
|
40
|
-
|
|
41
|
+
// A port that was never open was not lost
|
|
42
|
+
const message = wasOpen
|
|
43
|
+
? `Connection ${target === undefined ? '' : `to ${target} `}lost: ${reason.message}`
|
|
44
|
+
: `Could not open ${target ?? 'the connection'}: ${reason.message}`;
|
|
45
|
+
const error = new Error(message, { cause: reason });
|
|
41
46
|
error.name = 'ConnectionLostError';
|
|
42
47
|
// modbus-serial gives all its port errors errno 'ECONNREFUSED', also an unplugged
|
|
43
48
|
// serial adapter. Only Node.js system errors (they have a code) give a real errno.
|
|
@@ -61,13 +66,11 @@ function connectionLostError(target, cause) {
|
|
|
61
66
|
* not lead to a successful request, up to MAX_REOPEN_DELAY_MS.
|
|
62
67
|
* - without an `open` function, requests reject until the owner of the client
|
|
63
68
|
* opens it again
|
|
69
|
+
*
|
|
70
|
+
* A connection created with the error of a failed open (for example a USB serial
|
|
71
|
+
* adapter that is not plugged in) starts lost in the same way.
|
|
64
72
|
*/
|
|
65
73
|
export class ModbusConnection {
|
|
66
|
-
/**
|
|
67
|
-
* @param client - Connected modbus-serial client
|
|
68
|
-
* @param target - Port path or host:port, used in error messages
|
|
69
|
-
* @param open - Opens a new client after the connection is lost
|
|
70
|
-
*/
|
|
71
74
|
constructor(client, target, open) {
|
|
72
75
|
this.target = target;
|
|
73
76
|
this.open = open;
|
|
@@ -76,8 +79,21 @@ export class ModbusConnection {
|
|
|
76
79
|
this.reopenAt = 0;
|
|
77
80
|
this.closed = false;
|
|
78
81
|
this.inFlight = new Set();
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (client instanceof Error) {
|
|
83
|
+
this.state = { client: undefined, lostError: connectionLostError(target, client, false) };
|
|
84
|
+
this.delayReopen();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.state = { client };
|
|
88
|
+
this.watch(client);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The error that requests reject with while the connection is lost, or undefined while it
|
|
93
|
+
* works. The request that opens the port again clears it.
|
|
94
|
+
*/
|
|
95
|
+
get error() {
|
|
96
|
+
return this.state.lostError;
|
|
81
97
|
}
|
|
82
98
|
/**
|
|
83
99
|
* Run a request with the client
|
|
@@ -87,8 +103,9 @@ export class ModbusConnection {
|
|
|
87
103
|
* @throws ConnectionLostError when the connection is lost before or during the request
|
|
88
104
|
*/
|
|
89
105
|
async run(request) {
|
|
106
|
+
const { state } = this;
|
|
90
107
|
// No await while the connection works, so the request starts at once
|
|
91
|
-
const client =
|
|
108
|
+
const client = state.lostError === undefined ? state.client : await this.reopen(state.lostError);
|
|
92
109
|
// Assigned at once: the promise executor runs synchronously
|
|
93
110
|
let rejectOnLoss;
|
|
94
111
|
const lost = new Promise((_resolve, reject) => {
|
|
@@ -118,11 +135,12 @@ export class ModbusConnection {
|
|
|
118
135
|
*/
|
|
119
136
|
async close() {
|
|
120
137
|
this.closed = true;
|
|
138
|
+
const { state } = this;
|
|
121
139
|
// A lost client or a client that is not open needs no close. modbus-serial never
|
|
122
140
|
// calls back when it closes a TCP client whose socket is closed.
|
|
123
|
-
if (
|
|
141
|
+
if (state.lostError !== undefined || !state.client.isOpen)
|
|
124
142
|
return;
|
|
125
|
-
const client =
|
|
143
|
+
const { client } = state;
|
|
126
144
|
await new Promise((resolve) => {
|
|
127
145
|
closeClient(client, () => resolve());
|
|
128
146
|
});
|
|
@@ -135,12 +153,13 @@ export class ModbusConnection {
|
|
|
135
153
|
}
|
|
136
154
|
lose(client, cause) {
|
|
137
155
|
// Ignore events from clients that were replaced, and repeated events
|
|
138
|
-
if (client !== this.client || this.lostError !== undefined || this.closed)
|
|
156
|
+
if (client !== this.state.client || this.state.lostError !== undefined || this.closed)
|
|
139
157
|
return;
|
|
140
|
-
|
|
158
|
+
const lostError = connectionLostError(this.target, cause);
|
|
159
|
+
this.state = { client, lostError };
|
|
141
160
|
this.delayReopen();
|
|
142
161
|
for (const reject of this.inFlight)
|
|
143
|
-
reject(
|
|
162
|
+
reject(lostError);
|
|
144
163
|
// serialport closes the port on a disconnect. A port that is still open keeps
|
|
145
164
|
// its lock, and the reopen would fail.
|
|
146
165
|
if (client.isOpen)
|
|
@@ -159,9 +178,10 @@ export class ModbusConnection {
|
|
|
159
178
|
reopen(lostError) {
|
|
160
179
|
if (this.open === undefined) {
|
|
161
180
|
// The owner of the client can open it again
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
const { client } = this.state;
|
|
182
|
+
if (client?.isOpen && !this.closed) {
|
|
183
|
+
this.state = { client };
|
|
184
|
+
return Promise.resolve(client);
|
|
165
185
|
}
|
|
166
186
|
return Promise.reject(lostError);
|
|
167
187
|
}
|
|
@@ -179,8 +199,9 @@ export class ModbusConnection {
|
|
|
179
199
|
client = await open();
|
|
180
200
|
}
|
|
181
201
|
catch (error) {
|
|
182
|
-
|
|
183
|
-
this.
|
|
202
|
+
// Without a client, the port has never been open
|
|
203
|
+
const openError = connectionLostError(this.target, error, this.state.client !== undefined);
|
|
204
|
+
this.state = { client: this.state.client, lostError: openError };
|
|
184
205
|
this.delayReopen();
|
|
185
206
|
throw openError;
|
|
186
207
|
}
|
|
@@ -189,8 +210,7 @@ export class ModbusConnection {
|
|
|
189
210
|
closeClient(client, () => undefined);
|
|
190
211
|
throw lostError;
|
|
191
212
|
}
|
|
192
|
-
this.
|
|
193
|
-
this.lostError = undefined;
|
|
213
|
+
this.state = { client };
|
|
194
214
|
this.watch(client);
|
|
195
215
|
return client;
|
|
196
216
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aA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QAED,IAAI,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,CAAA;QACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAClB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;KArKW,UAAU;AAuKtB;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoC;IAC/D,OAAO,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACrE,CAAC"}
|
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { createModbusTransport } from './create-modbus-transport.js';
|
|
|
11
11
|
export { withRetry, MAX_RETRIES, RETRY_DELAY_MS, type RetryLogger } from './retry.js';
|
|
12
12
|
export { normalizeModbusError, type ModbusError } from './normalize-error.js';
|
|
13
13
|
export { isConnectionLostError, ModbusConnection, type OpenClient } from './connection.js';
|
|
14
|
-
export { TransportManager, type TransportStats } from './manager.js';
|
|
14
|
+
export { TransportManager, type TransportManagerOptions, type TransportStats } from './manager.js';
|
|
15
15
|
export { MutexTransport } from './mutex-transport.js';
|
|
16
16
|
export { SlaveTransport } from './slave-transport.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAwB,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAwB,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAqD,MAAM,cAAc,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { Transport } from '@ya-modbus/driver-types';
|
|
2
2
|
import type { TransportConfig } from './factory.js';
|
|
3
|
+
import { type ModbusError } from './normalize-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for TransportManager
|
|
6
|
+
*/
|
|
7
|
+
export interface TransportManagerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Return a transport also when its port cannot be opened (for example a USB serial adapter
|
|
10
|
+
* that is not plugged in). The connection then starts lost: requests reject with a
|
|
11
|
+
* ConnectionLostError, and a request after the reopen delay opens the port (see
|
|
12
|
+
* ModbusConnection). getConnectionError() returns the error.
|
|
13
|
+
*
|
|
14
|
+
* Default: false, getTransport() rejects when the port cannot be opened.
|
|
15
|
+
*/
|
|
16
|
+
startLost?: boolean;
|
|
17
|
+
}
|
|
3
18
|
/**
|
|
4
19
|
* Statistics about managed transports
|
|
5
20
|
*/
|
|
@@ -21,6 +36,8 @@ export interface TransportStats {
|
|
|
21
36
|
* - A lost connection (USB adapter unplugged, TCP connection closed) drops the client.
|
|
22
37
|
* The first request after a backoff opens a new client for all devices on the
|
|
23
38
|
* connection (see ModbusConnection)
|
|
39
|
+
* - With the `startLost` option, a port that cannot be opened (USB adapter missing at
|
|
40
|
+
* start) gives a lost connection instead of an error
|
|
24
41
|
*
|
|
25
42
|
* This architecture solves the multi-device problem:
|
|
26
43
|
* - Each device gets its own SlaveTransport with its own slave ID
|
|
@@ -36,7 +53,10 @@ export interface TransportStats {
|
|
|
36
53
|
* - SlaveTransport.close(): Does not close shared client (use closeAll() for cleanup)
|
|
37
54
|
*/
|
|
38
55
|
export declare class TransportManager {
|
|
56
|
+
private readonly options;
|
|
39
57
|
private readonly connections;
|
|
58
|
+
private readonly opening;
|
|
59
|
+
constructor(options?: TransportManagerOptions);
|
|
40
60
|
/**
|
|
41
61
|
* Get or create a transport for the given configuration.
|
|
42
62
|
* Returns a new SlaveTransport instance bound to the slave ID in the config.
|
|
@@ -44,8 +64,25 @@ export declare class TransportManager {
|
|
|
44
64
|
*
|
|
45
65
|
* @param config - RTU or TCP transport configuration
|
|
46
66
|
* @returns SlaveTransport instance for the specific slave device
|
|
67
|
+
* @throws When the port cannot be opened, unless the `startLost` option is set
|
|
47
68
|
*/
|
|
48
69
|
getTransport(config: TransportConfig): Promise<Transport>;
|
|
70
|
+
/**
|
|
71
|
+
* Open the shared connection for a physical connection and add it to the pool
|
|
72
|
+
*
|
|
73
|
+
* @param key - Physical connection key
|
|
74
|
+
* @param config - Transport configuration
|
|
75
|
+
* @returns The pool entry
|
|
76
|
+
*/
|
|
77
|
+
private openConnection;
|
|
78
|
+
/**
|
|
79
|
+
* Get the error of a lost connection
|
|
80
|
+
*
|
|
81
|
+
* @param config - Configuration of a transport on the connection
|
|
82
|
+
* @returns The error that requests on the connection reject with while it is lost.
|
|
83
|
+
* Undefined while the connection works, or when there is no connection for the config.
|
|
84
|
+
*/
|
|
85
|
+
getConnectionError(config: TransportConfig): ModbusError | undefined;
|
|
49
86
|
/**
|
|
50
87
|
* Get statistics about managed connections
|
|
51
88
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAa7E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,gBAAgB;IAKf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8C;gBAEzC,OAAO,GAAE,uBAA4B;IAElE;;;;;;;;OAQG;IACG,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAwB/D;;;;;;OAMG;YACW,cAAc;IAkB5B;;;;;;OAMG;IACH,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,SAAS;IAIpE;;;;OAIG;IACH,QAAQ,IAAI,cAAc;IAS1B;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB/B;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;OAMG;YACW,eAAe;IAe7B;;;;;;OAMG;YACW,eAAe;IAU7B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/esm/src/manager.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Mutex } from 'async-mutex';
|
|
2
2
|
import ModbusRTU from 'modbus-serial';
|
|
3
|
-
import { DEFAULT_TIMEOUT_MS } from './client-config.js';
|
|
3
|
+
import { connectTCP, DEFAULT_TIMEOUT_MS } from './client-config.js';
|
|
4
4
|
import { ModbusConnection } from './connection.js';
|
|
5
|
+
import { normalizeModbusError } from './normalize-error.js';
|
|
5
6
|
import { SlaveTransport } from './slave-transport.js';
|
|
6
7
|
/**
|
|
7
8
|
* TransportManager pools modbus-serial clients and provides slave-specific transports.
|
|
@@ -16,6 +17,8 @@ import { SlaveTransport } from './slave-transport.js';
|
|
|
16
17
|
* - A lost connection (USB adapter unplugged, TCP connection closed) drops the client.
|
|
17
18
|
* The first request after a backoff opens a new client for all devices on the
|
|
18
19
|
* connection (see ModbusConnection)
|
|
20
|
+
* - With the `startLost` option, a port that cannot be opened (USB adapter missing at
|
|
21
|
+
* start) gives a lost connection instead of an error
|
|
19
22
|
*
|
|
20
23
|
* This architecture solves the multi-device problem:
|
|
21
24
|
* - Each device gets its own SlaveTransport with its own slave ID
|
|
@@ -31,8 +34,11 @@ import { SlaveTransport } from './slave-transport.js';
|
|
|
31
34
|
* - SlaveTransport.close(): Does not close shared client (use closeAll() for cleanup)
|
|
32
35
|
*/
|
|
33
36
|
export class TransportManager {
|
|
34
|
-
constructor() {
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
this.options = options;
|
|
35
39
|
this.connections = new Map();
|
|
40
|
+
// Connections that are opening, so that devices added at the same time share one client
|
|
41
|
+
this.opening = new Map();
|
|
36
42
|
}
|
|
37
43
|
/**
|
|
38
44
|
* Get or create a transport for the given configuration.
|
|
@@ -41,27 +47,57 @@ export class TransportManager {
|
|
|
41
47
|
*
|
|
42
48
|
* @param config - RTU or TCP transport configuration
|
|
43
49
|
* @returns SlaveTransport instance for the specific slave device
|
|
50
|
+
* @throws When the port cannot be opened, unless the `startLost` option is set
|
|
44
51
|
*/
|
|
45
52
|
async getTransport(config) {
|
|
46
53
|
const key = this.getPhysicalConnectionKey(config);
|
|
47
|
-
const isRTU = this.isRTUConfig(config);
|
|
48
54
|
// Get or create the shared connection
|
|
49
55
|
let entry = this.connections.get(key);
|
|
50
56
|
if (!entry) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
config,
|
|
58
|
-
isRTU,
|
|
59
|
-
};
|
|
60
|
-
this.connections.set(key, entry);
|
|
57
|
+
let opening = this.opening.get(key);
|
|
58
|
+
if (!opening) {
|
|
59
|
+
opening = this.openConnection(key, config).finally(() => this.opening.delete(key));
|
|
60
|
+
this.opening.set(key, opening);
|
|
61
|
+
}
|
|
62
|
+
entry = await opening;
|
|
61
63
|
}
|
|
62
64
|
// Return a new SlaveTransport for this specific slave
|
|
63
65
|
return new SlaveTransport(config.slaveId, entry.connection, entry.mutex, config.maxRetries ?? 3, config.logger);
|
|
64
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Open the shared connection for a physical connection and add it to the pool
|
|
69
|
+
*
|
|
70
|
+
* @param key - Physical connection key
|
|
71
|
+
* @param config - Transport configuration
|
|
72
|
+
* @returns The pool entry
|
|
73
|
+
*/
|
|
74
|
+
async openConnection(key, config) {
|
|
75
|
+
const isRTU = this.isRTUConfig(config);
|
|
76
|
+
const open = isRTU ? () => this.createRTUClient(config) : () => this.createTCPClient(config);
|
|
77
|
+
const target = this.getTarget(config);
|
|
78
|
+
let connection;
|
|
79
|
+
try {
|
|
80
|
+
connection = new ModbusConnection(await open(), target, open);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (!this.options.startLost)
|
|
84
|
+
throw error;
|
|
85
|
+
connection = new ModbusConnection(normalizeModbusError(error), target, open);
|
|
86
|
+
}
|
|
87
|
+
const entry = { connection, mutex: new Mutex(), config, isRTU };
|
|
88
|
+
this.connections.set(key, entry);
|
|
89
|
+
return entry;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the error of a lost connection
|
|
93
|
+
*
|
|
94
|
+
* @param config - Configuration of a transport on the connection
|
|
95
|
+
* @returns The error that requests on the connection reject with while it is lost.
|
|
96
|
+
* Undefined while the connection works, or when there is no connection for the config.
|
|
97
|
+
*/
|
|
98
|
+
getConnectionError(config) {
|
|
99
|
+
return this.connections.get(this.getPhysicalConnectionKey(config))?.connection.error;
|
|
100
|
+
}
|
|
65
101
|
/**
|
|
66
102
|
* Get statistics about managed connections
|
|
67
103
|
*
|
|
@@ -80,7 +116,15 @@ export class TransportManager {
|
|
|
80
116
|
* Errors during close are logged but do not stop the process.
|
|
81
117
|
*/
|
|
82
118
|
async closeAll() {
|
|
83
|
-
|
|
119
|
+
// A connection that is still opening is added to the pool when it opens. More opens can
|
|
120
|
+
// start while this waits.
|
|
121
|
+
while (this.opening.size > 0)
|
|
122
|
+
await Promise.allSettled(this.opening.values());
|
|
123
|
+
// Clear the pool first: a connection that opens while these close stays in the pool,
|
|
124
|
+
// so the next closeAll() closes it
|
|
125
|
+
const entries = Array.from(this.connections.values());
|
|
126
|
+
this.connections.clear();
|
|
127
|
+
const closePromises = entries.map(async (entry) => {
|
|
84
128
|
try {
|
|
85
129
|
await entry.connection.close();
|
|
86
130
|
}
|
|
@@ -90,7 +134,6 @@ export class TransportManager {
|
|
|
90
134
|
}
|
|
91
135
|
});
|
|
92
136
|
await Promise.all(closePromises);
|
|
93
|
-
this.connections.clear();
|
|
94
137
|
}
|
|
95
138
|
/**
|
|
96
139
|
* Generate a unique key for a physical connection.
|
|
@@ -144,7 +187,7 @@ export class TransportManager {
|
|
|
144
187
|
*/
|
|
145
188
|
async createTCPClient(config) {
|
|
146
189
|
const client = new ModbusRTU();
|
|
147
|
-
await
|
|
190
|
+
await connectTCP(client, config.host, config.port ?? 502, config.timeout);
|
|
148
191
|
client.setTimeout(config.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
149
192
|
return client;
|
|
150
193
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA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OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,CAAA;IACnF,CAAC;CACF"}
|
|
@@ -10,7 +10,7 @@ export interface TCPConfig {
|
|
|
10
10
|
port?: number | undefined;
|
|
11
11
|
/** Modbus slave ID (1-247) */
|
|
12
12
|
slaveId: number;
|
|
13
|
-
/** Response timeout in milliseconds (default: 1000) */
|
|
13
|
+
/** Response timeout in milliseconds, also used as the connect timeout (default: 1000) */
|
|
14
14
|
timeout?: number | undefined;
|
|
15
15
|
/** Maximum retry attempts (default: 3, use 1 to disable retries) */
|
|
16
16
|
maxRetries?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,
|
|
1
|
+
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAc9E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ModbusRTU from 'modbus-serial';
|
|
2
|
-
import { configureClient } from './client-config.js';
|
|
2
|
+
import { configureClient, connectTCP } from './client-config.js';
|
|
3
3
|
import { ModbusConnection } from './connection.js';
|
|
4
4
|
import { createModbusTransport } from './create-modbus-transport.js';
|
|
5
5
|
/**
|
|
@@ -16,7 +16,7 @@ export async function createTCPTransport(config) {
|
|
|
16
16
|
const open = async () => {
|
|
17
17
|
const client = new ModbusRTU();
|
|
18
18
|
// Connect to TCP server
|
|
19
|
-
await
|
|
19
|
+
await connectTCP(client, config.host, port, config.timeout);
|
|
20
20
|
configureClient(client, config.slaveId, config.timeout);
|
|
21
21
|
return client;
|
|
22
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAqBpE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,GAAG,CAAA;IAC/B,MAAM,IAAI,GAAG,KAAK,IAAwB,EAAE;QAC1C,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAA;QAE9B,wBAAwB;QACxB,MAAM,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAE3D,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QACvD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,MAAM,IAAI,EAAE,EAAE,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;IACrF,OAAO,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AAC5E,CAAC"}
|