@ya-modbus/transport 0.10.1 → 0.11.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +64 -0
  3. package/dist/cjs/src/connection.d.ts +20 -4
  4. package/dist/cjs/src/connection.d.ts.map +1 -1
  5. package/dist/cjs/src/connection.js +52 -26
  6. package/dist/cjs/src/connection.js.map +1 -1
  7. package/dist/cjs/src/index.d.ts +1 -1
  8. package/dist/cjs/src/index.d.ts.map +1 -1
  9. package/dist/cjs/src/index.js.map +1 -1
  10. package/dist/cjs/src/manager.d.ts +63 -1
  11. package/dist/cjs/src/manager.d.ts.map +1 -1
  12. package/dist/cjs/src/manager.js +116 -24
  13. package/dist/cjs/src/manager.js.map +1 -1
  14. package/dist/cjs/src/slave-transport.d.ts +6 -5
  15. package/dist/cjs/src/slave-transport.d.ts.map +1 -1
  16. package/dist/cjs/src/slave-transport.js +6 -5
  17. package/dist/cjs/src/slave-transport.js.map +1 -1
  18. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  19. package/dist/esm/src/connection.d.ts +20 -4
  20. package/dist/esm/src/connection.d.ts.map +1 -1
  21. package/dist/esm/src/connection.js +52 -26
  22. package/dist/esm/src/connection.js.map +1 -1
  23. package/dist/esm/src/index.d.ts +1 -1
  24. package/dist/esm/src/index.d.ts.map +1 -1
  25. package/dist/esm/src/index.js.map +1 -1
  26. package/dist/esm/src/manager.d.ts +63 -1
  27. package/dist/esm/src/manager.d.ts.map +1 -1
  28. package/dist/esm/src/manager.js +116 -24
  29. package/dist/esm/src/manager.js.map +1 -1
  30. package/dist/esm/src/slave-transport.d.ts +6 -5
  31. package/dist/esm/src/slave-transport.d.ts.map +1 -1
  32. package/dist/esm/src/slave-transport.js +6 -5
  33. package/dist/esm/src/slave-transport.js.map +1 -1
  34. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  35. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.11.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.11.0...@ya-modbus/transport@0.11.1) (2026-10-12)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **transport:** close a pooled connection when its last device is removed ([#593](https://github.com/groupsky/ya-modbus/issues/593)) ([cd58d95](https://github.com/groupsky/ya-modbus/commit/cd58d95450cebaf2c2958d5d8585fee81190a7cf)), closes [#534](https://github.com/groupsky/ya-modbus/issues/534) [#534](https://github.com/groupsky/ya-modbus/issues/534)
11
+
12
+ # [0.11.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.10.1...@ya-modbus/transport@0.11.0) (2026-10-12)
13
+
14
+ ### Features
15
+
16
+ - **transport:** let the mqtt-bridge start when a serial adapter is missing ([#587](https://github.com/groupsky/ya-modbus/issues/587)) ([38a2c9b](https://github.com/groupsky/ya-modbus/commit/38a2c9b4dc07b987c474afec995f6bc0a67ed20f)), closes [#549](https://github.com/groupsky/ya-modbus/issues/549) [#568](https://github.com/groupsky/ya-modbus/issues/568)
17
+
6
18
  ## [0.10.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.10.0...@ya-modbus/transport@0.10.1) (2026-10-12)
7
19
 
8
20
  ### Bug Fixes
package/README.md CHANGED
@@ -8,6 +8,7 @@ Modbus transport implementations for RTU (serial) and TCP connections.
8
8
  - TCP/IP transport
9
9
  - Automatic retry on transient failures
10
10
  - Survives a lost port (unplugged USB adapter) and opens it again
11
+ - Shares one connection between the devices on a bus, and closes it when the last one is removed
11
12
  - Factory for auto-detecting transport type
12
13
  - TypeScript support
13
14
 
@@ -43,6 +44,53 @@ const tcpTransport = await createTransport({
43
44
  await rtuTransport.readHoldingRegisters(0, 10)
44
45
  ```
45
46
 
47
+ ## Several devices on one connection
48
+
49
+ `TransportManager` shares one connection between the devices on a serial port with the same
50
+ serial settings, or on the same TCP host and port. The requests of these devices run one at a
51
+ time.
52
+
53
+ ```typescript
54
+ import { TransportManager } from '@ya-modbus/transport'
55
+
56
+ const manager = new TransportManager()
57
+ const bus = {
58
+ port: '/dev/ttyUSB0',
59
+ baudRate: 9600,
60
+ dataBits: 8,
61
+ parity: 'none',
62
+ stopBits: 1,
63
+ } as const
64
+
65
+ // Both devices use one open serial port
66
+ const meter = await manager.getTransport({ ...bus, slaveId: 1 })
67
+ const sensor = await manager.getTransport({ ...bus, slaveId: 2 })
68
+
69
+ // The sensor still uses the port, so it stays open
70
+ await manager.releaseTransport(meter)
71
+
72
+ // The last device on the port: the port is closed
73
+ await manager.releaseTransport(sensor)
74
+
75
+ // At shutdown
76
+ await manager.closeAll()
77
+ ```
78
+
79
+ The life of a pooled connection:
80
+
81
+ - `getTransport(config)` opens the connection for the first device on it, and returns a new
82
+ transport for each device. Devices that are added at the same time wait for the same open.
83
+ - When you remove a device, call `releaseTransport(transport)`. The connection stays open while
84
+ other devices use it. When the last device releases its transport, the connection is closed
85
+ and removed from the pool. The promise resolves when the connection is closed, also when the
86
+ port was lost or was opening again at that moment. A later `getTransport()` waits until the
87
+ port is closed, and opens it again, also with other serial settings. An open serial port is
88
+ locked, so without the release other settings cannot open it.
89
+ - Releasing a transport again does nothing. Do not use a transport after you release it: its
90
+ requests fail when its connection is closed.
91
+ - `closeAll()` closes all connections and stops opening lost ports again. It waits for
92
+ connections that are opening or closing. Use it at shutdown.
93
+
46
94
  ## Error handling
47
95
 
48
96
  Some `modbus-serial` failures (response timeouts, closed port) are plain objects instead of `Error`
@@ -100,6 +148,17 @@ Requests between the attempts reject with the last error. The delay also doubles
100
148
  opens but is lost again before a request succeeds. A successful request sets the delay back to
101
149
  1 second. `TransportManager` opens one new client for all devices on the bus.
102
150
 
151
+ `createTransport` and `TransportManager.getTransport()` reject when the port cannot be opened,
152
+ for example when a USB adapter is not plugged in. A long-running program can start anyway with
153
+ `new TransportManager({ startLost: true })`. Then `getTransport()` returns the transport, and
154
+ its connection starts lost with the error of the failed open. Requests reject with a
155
+ `ConnectionLostError` with a message like
156
+ `Could not open /dev/ttyUSB0: Error: No such file or directory, cannot open /dev/ttyUSB0`, until
157
+ the port opens for the first time. The port is opened again after the same delays as above.
158
+ `getConnectionError(config)` returns the error while the connection is lost, and `undefined`
159
+ while it works. The MQTT bridge uses this, so one missing adapter does not stop the other
160
+ devices.
161
+
103
162
  A short-lived program, like a CLI command, can stop at the first `ConnectionLostError`.
104
163
 
105
164
  ```typescript
@@ -143,6 +202,11 @@ const transport = createModbusTransport(connection)
143
202
  Without the `open` function, a lost connection works again only when you open the same client
144
203
  again.
145
204
 
205
+ When the first `open()` fails, you can pass its error instead of the client:
206
+ `new ModbusConnection(error, '/dev/ttyUSB0', open)`. The connection then starts lost with that
207
+ error, and opens the port later in the same way. `connection.error` is the error while the
208
+ connection is lost, and `undefined` while it works.
209
+
146
210
  ## License
147
211
 
148
212
  GPL-3.0-or-later
@@ -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 client;
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 | undefined, open?: OpenClient | undefined);
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
  *
@@ -61,7 +76,8 @@ export declare class ModbusConnection {
61
76
  */
62
77
  run<T>(request: (client: ModbusRTU) => Promise<T>): Promise<T>;
63
78
  /**
64
- * Close the client and stop reopening it
79
+ * Close the client and stop reopening it. Resolves when the port is closed, also when a
80
+ * request was opening it again.
65
81
  */
66
82
  close(): Promise<void>;
67
83
  private watch;
@@ -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;AAqBtE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAgB;IAiBzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAjBxB,QAAQ,CAAC,CAAC,UAAU,CAAC,QAAO;IAC5B,OAAO,CAA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usConnection objects, the same for all copies of this package */
39
39
  const CONNECTION = Symbol.for('@ya-modbus/transport/ModbusConnection');
40
40
  /**
41
- * Error for a lost connection, with code and errno of a Node.js system error cause
41
+ * Error for a lost connection, or for a port that was never open, with code and errno of a
42
+ * Node.js system error cause
42
43
  */
43
- function connectionLostError(target, cause) {
44
+ function connectionLostError(target, cause, wasOpen = true) {
44
45
  const reason = (0, normalize_error_js_1.normalizeModbusError)(cause);
45
- const error = new Error(`Connection ${target === undefined ? '' : `to ${target} `}lost: ${reason.message}`, { cause: reason });
46
+ // A port that was never open was not lost
47
+ const message = wasOpen
48
+ ? `Connection ${target === undefined ? '' : `to ${target} `}lost: ${reason.message}`
49
+ : `Could not open ${target ?? 'the connection'}: ${reason.message}`;
50
+ const error = new Error(message, { cause: reason });
46
51
  error.name = 'ConnectionLostError';
47
52
  // modbus-serial gives all its port errors errno 'ECONNREFUSED', also an unplugged
48
53
  // serial adapter. Only Node.js system errors (they have a code) give a real errno.
@@ -66,13 +71,11 @@ function connectionLostError(target, cause) {
66
71
  * not lead to a successful request, up to MAX_REOPEN_DELAY_MS.
67
72
  * - without an `open` function, requests reject until the owner of the client
68
73
  * opens it again
74
+ *
75
+ * A connection created with the error of a failed open (for example a USB serial
76
+ * adapter that is not plugged in) starts lost in the same way.
69
77
  */
70
78
  class ModbusConnection {
71
- /**
72
- * @param client - Connected modbus-serial client
73
- * @param target - Port path or host:port, used in error messages
74
- * @param open - Opens a new client after the connection is lost
75
- */
76
79
  constructor(client, target, open) {
77
80
  this.target = target;
78
81
  this.open = open;
@@ -81,8 +84,21 @@ class ModbusConnection {
81
84
  this.reopenAt = 0;
82
85
  this.closed = false;
83
86
  this.inFlight = new Set();
84
- this.client = client;
85
- this.watch(client);
87
+ if (client instanceof Error) {
88
+ this.state = { client: undefined, lostError: connectionLostError(target, client, false) };
89
+ this.delayReopen();
90
+ }
91
+ else {
92
+ this.state = { client };
93
+ this.watch(client);
94
+ }
95
+ }
96
+ /**
97
+ * The error that requests reject with while the connection is lost, or undefined while it
98
+ * works. The request that opens the port again clears it.
99
+ */
100
+ get error() {
101
+ return this.state.lostError;
86
102
  }
87
103
  /**
88
104
  * Run a request with the client
@@ -92,8 +108,9 @@ class ModbusConnection {
92
108
  * @throws ConnectionLostError when the connection is lost before or during the request
93
109
  */
94
110
  async run(request) {
111
+ const { state } = this;
95
112
  // No await while the connection works, so the request starts at once
96
- const client = this.lostError === undefined ? this.client : await this.reopen(this.lostError);
113
+ const client = state.lostError === undefined ? state.client : await this.reopen(state.lostError);
97
114
  // Assigned at once: the promise executor runs synchronously
98
115
  let rejectOnLoss;
99
116
  const lost = new Promise((_resolve, reject) => {
@@ -119,15 +136,20 @@ class ModbusConnection {
119
136
  }
120
137
  }
121
138
  /**
122
- * Close the client and stop reopening it
139
+ * Close the client and stop reopening it. Resolves when the port is closed, also when a
140
+ * request was opening it again.
123
141
  */
124
142
  async close() {
125
143
  this.closed = true;
144
+ // A client that opens now is closed at once (see openClient)
145
+ if (this.reopening)
146
+ await this.reopening.catch(() => undefined);
147
+ const { state } = this;
126
148
  // A lost client or a client that is not open needs no close. modbus-serial never
127
149
  // calls back when it closes a TCP client whose socket is closed.
128
- if (this.lostError !== undefined || !this.client.isOpen)
150
+ if (state.lostError !== undefined || !state.client.isOpen)
129
151
  return;
130
- const client = this.client;
152
+ const { client } = state;
131
153
  await new Promise((resolve) => {
132
154
  closeClient(client, () => resolve());
133
155
  });
@@ -140,12 +162,13 @@ class ModbusConnection {
140
162
  }
141
163
  lose(client, cause) {
142
164
  // Ignore events from clients that were replaced, and repeated events
143
- if (client !== this.client || this.lostError !== undefined || this.closed)
165
+ if (client !== this.state.client || this.state.lostError !== undefined || this.closed)
144
166
  return;
145
- this.lostError = connectionLostError(this.target, cause);
167
+ const lostError = connectionLostError(this.target, cause);
168
+ this.state = { client, lostError };
146
169
  this.delayReopen();
147
170
  for (const reject of this.inFlight)
148
- reject(this.lostError);
171
+ reject(lostError);
149
172
  // serialport closes the port on a disconnect. A port that is still open keeps
150
173
  // its lock, and the reopen would fail.
151
174
  if (client.isOpen)
@@ -164,9 +187,10 @@ class ModbusConnection {
164
187
  reopen(lostError) {
165
188
  if (this.open === undefined) {
166
189
  // The owner of the client can open it again
167
- if (this.client.isOpen && !this.closed) {
168
- this.lostError = undefined;
169
- return Promise.resolve(this.client);
190
+ const { client } = this.state;
191
+ if (client?.isOpen && !this.closed) {
192
+ this.state = { client };
193
+ return Promise.resolve(client);
170
194
  }
171
195
  return Promise.reject(lostError);
172
196
  }
@@ -184,18 +208,20 @@ class ModbusConnection {
184
208
  client = await open();
185
209
  }
186
210
  catch (error) {
187
- const openError = connectionLostError(this.target, error);
188
- this.lostError = openError;
211
+ // Without a client, the port has never been open
212
+ const openError = connectionLostError(this.target, error, this.state.client !== undefined);
213
+ this.state = { client: this.state.client, lostError: openError };
189
214
  this.delayReopen();
190
215
  throw openError;
191
216
  }
192
217
  if (this.closed) {
193
- // close() was called while the client was opening
194
- closeClient(client, () => undefined);
218
+ // close() was called while the client was opening, and waits until the port is closed
219
+ await new Promise((resolve) => {
220
+ closeClient(client, () => resolve());
221
+ });
195
222
  throw lostError;
196
223
  }
197
- this.client = client;
198
- this.lostError = undefined;
224
+ this.state = { client };
199
225
  this.watch(client);
200
226
  return client;
201
227
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/connection.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAyBH,sDAEC;AA4MD,oCAEC;AAvOD,6CAA0C;AAI1C,6DAA6E;AAE7E,kFAAkF;AACrE,QAAA,eAAe,GAAG,IAAI,CAAA;AAEnC,kFAAkF;AACrE,QAAA,mBAAmB,GAAG,KAAM,CAAA;AAOzC;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,KAAc;IAClD,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,CAAA;AACvE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,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AAO,EAAE,EAAE;gBAClC,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;YACtC,CAAC,CAAC,CAAA;YACF,MAAM,SAAS,CAAA;QACjB,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,CAAA;QACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAClB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA3KD,4CA2KC;KA1KW,UAAU;AA4KtB;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,MAAoC;IAC/D,OAAO,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACrE,CAAC"}
@@ -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,O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.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2CAAoE;AAA3D,6GAAA,eAAe,OAAA;AACxB,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,2EAAoE;AAA3D,mIAAA,qBAAqB,OAAA;AAC9B,uCAAqF;AAA5E,qGAAA,SAAS,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,0GAAA,cAAc,OAAA;AAC/C,2DAA6E;AAApE,0HAAA,oBAAoB,OAAA;AAC7B,iDAA0F;AAAjF,sHAAA,qBAAqB,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AAChD,2CAAoE;AAA3D,8GAAA,gBAAgB,OAAA;AACzB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA;AACvB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2CAAoE;AAA3D,6GAAA,eAAe,OAAA;AACxB,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,uDAAuE;AAA9D,sHAAA,kBAAkB,OAAA;AAC3B,2EAAoE;AAA3D,mIAAA,qBAAqB,OAAA;AAC9B,uCAAqF;AAA5E,qGAAA,SAAS,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,0GAAA,cAAc,OAAA;AAC/C,2DAA6E;AAApE,0HAAA,oBAAoB,OAAA;AAC7B,iDAA0F;AAAjF,sHAAA,qBAAqB,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AAChD,2CAAkG;AAAzF,8GAAA,gBAAgB,OAAA;AACzB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA;AACvB,2DAAqD;AAA5C,oHAAA,cAAc,OAAA"}
@@ -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,10 @@ 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
41
+ * - A connection stays open while a transport on it is not released. releaseTransport()
42
+ * closes it when its last transport is released, so the port is free again
24
43
  *
25
44
  * This architecture solves the multi-device problem:
26
45
  * - Each device gets its own SlaveTransport with its own slave ID
@@ -33,10 +52,15 @@ export interface TransportStats {
33
52
  * intentional and correct:
34
53
  * - Shared client: Avoids port contention (can't open serial port twice)
35
54
  * - Shared mutex: Ensures serialized access to the bus
36
- * - SlaveTransport.close(): Does not close shared client (use closeAll() for cleanup)
55
+ * - SlaveTransport.close() closes the shared client for all devices on the connection. Use
56
+ * releaseTransport() when a device is removed, and closeAll() at shutdown.
37
57
  */
38
58
  export declare class TransportManager {
59
+ private readonly options;
39
60
  private readonly connections;
61
+ private readonly opening;
62
+ private readonly closing;
63
+ constructor(options?: TransportManagerOptions);
40
64
  /**
41
65
  * Get or create a transport for the given configuration.
42
66
  * Returns a new SlaveTransport instance bound to the slave ID in the config.
@@ -44,8 +68,38 @@ export declare class TransportManager {
44
68
  *
45
69
  * @param config - RTU or TCP transport configuration
46
70
  * @returns SlaveTransport instance for the specific slave device
71
+ * @throws When the port cannot be opened, unless the `startLost` option is set
47
72
  */
48
73
  getTransport(config: TransportConfig): Promise<Transport>;
74
+ /**
75
+ * Release the transport of a device that does not use it any more, for example a device
76
+ * that is removed. When no other transport uses the connection, the connection is closed
77
+ * and removed from the pool. A later getTransport() waits until the port is closed, and
78
+ * opens it again, also with other serial settings.
79
+ *
80
+ * Releasing a transport again, or a transport whose connection closeAll() closes, does
81
+ * nothing and does not wait.
82
+ *
83
+ * @param transport - Transport that getTransport() returned
84
+ * @returns Resolves when the connection is closed, or at once while other transports use it
85
+ */
86
+ releaseTransport(transport: Transport): Promise<void>;
87
+ /**
88
+ * Open the shared connection for a physical connection and add it to the pool
89
+ *
90
+ * @param key - Physical connection key
91
+ * @param config - Transport configuration
92
+ * @returns The pool entry
93
+ */
94
+ private openConnection;
95
+ /**
96
+ * Get the error of a lost connection
97
+ *
98
+ * @param config - Configuration of a transport on the connection
99
+ * @returns The error that requests on the connection reject with while it is lost.
100
+ * Undefined while the connection works, or when there is no connection for the config.
101
+ */
102
+ getConnectionError(config: TransportConfig): ModbusError | undefined;
49
103
  /**
50
104
  * Get statistics about managed connections
51
105
  *
@@ -54,9 +108,17 @@ export declare class TransportManager {
54
108
  getStats(): TransportStats;
55
109
  /**
56
110
  * Close all managed connections and clear the pool.
111
+ * Waits for connections that are opening or closing.
57
112
  * Errors during close are logged but do not stop the process.
58
113
  */
59
114
  closeAll(): Promise<void>;
115
+ /**
116
+ * Close a connection that is no longer in the pool. Errors are logged, so that the other
117
+ * connections close too.
118
+ *
119
+ * @param entry - Pool entry of the connection
120
+ */
121
+ private closeConnection;
60
122
  /**
61
123
  * Generate a unique key for a physical connection.
62
124
  * Excludes slave ID so multiple devices on the same bus share a connection.
@@ -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,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