@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
@@ -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;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AS,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;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,IAAI;IAaZ,8EAA8E;IAC9E,OAAO,CAAC,WAAW;IAKnB;;;;OAIG;IACH,OAAO,CAAC,MAAM;YAmBA,UAAU;CAuBzB;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 Node.js system error cause
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
- const error = new Error(`Connection ${target === undefined ? '' : `to ${target} `}lost: ${reason.message}`, { cause: reason });
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
- this.client = client;
80
- this.watch(client);
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 = this.lostError === undefined ? this.client : await this.reopen(this.lostError);
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) => {
@@ -114,15 +131,20 @@ export class ModbusConnection {
114
131
  }
115
132
  }
116
133
  /**
117
- * Close the client and stop reopening it
134
+ * Close the client and stop reopening it. Resolves when the port is closed, also when a
135
+ * request was opening it again.
118
136
  */
119
137
  async close() {
120
138
  this.closed = true;
139
+ // A client that opens now is closed at once (see openClient)
140
+ if (this.reopening)
141
+ await this.reopening.catch(() => undefined);
142
+ const { state } = this;
121
143
  // A lost client or a client that is not open needs no close. modbus-serial never
122
144
  // calls back when it closes a TCP client whose socket is closed.
123
- if (this.lostError !== undefined || !this.client.isOpen)
145
+ if (state.lostError !== undefined || !state.client.isOpen)
124
146
  return;
125
- const client = this.client;
147
+ const { client } = state;
126
148
  await new Promise((resolve) => {
127
149
  closeClient(client, () => resolve());
128
150
  });
@@ -135,12 +157,13 @@ export class ModbusConnection {
135
157
  }
136
158
  lose(client, cause) {
137
159
  // Ignore events from clients that were replaced, and repeated events
138
- if (client !== this.client || this.lostError !== undefined || this.closed)
160
+ if (client !== this.state.client || this.state.lostError !== undefined || this.closed)
139
161
  return;
140
- this.lostError = connectionLostError(this.target, cause);
162
+ const lostError = connectionLostError(this.target, cause);
163
+ this.state = { client, lostError };
141
164
  this.delayReopen();
142
165
  for (const reject of this.inFlight)
143
- reject(this.lostError);
166
+ reject(lostError);
144
167
  // serialport closes the port on a disconnect. A port that is still open keeps
145
168
  // its lock, and the reopen would fail.
146
169
  if (client.isOpen)
@@ -159,9 +182,10 @@ export class ModbusConnection {
159
182
  reopen(lostError) {
160
183
  if (this.open === undefined) {
161
184
  // The owner of the client can open it again
162
- if (this.client.isOpen && !this.closed) {
163
- this.lostError = undefined;
164
- return Promise.resolve(this.client);
185
+ const { client } = this.state;
186
+ if (client?.isOpen && !this.closed) {
187
+ this.state = { client };
188
+ return Promise.resolve(client);
165
189
  }
166
190
  return Promise.reject(lostError);
167
191
  }
@@ -179,18 +203,20 @@ export class ModbusConnection {
179
203
  client = await open();
180
204
  }
181
205
  catch (error) {
182
- const openError = connectionLostError(this.target, error);
183
- this.lostError = openError;
206
+ // Without a client, the port has never been open
207
+ const openError = connectionLostError(this.target, error, this.state.client !== undefined);
208
+ this.state = { client: this.state.client, lostError: openError };
184
209
  this.delayReopen();
185
210
  throw openError;
186
211
  }
187
212
  if (this.closed) {
188
- // close() was called while the client was opening
189
- closeClient(client, () => undefined);
213
+ // close() was called while the client was opening, and waits until the port is closed
214
+ await new Promise((resolve) => {
215
+ closeClient(client, () => resolve());
216
+ });
190
217
  throw lostError;
191
218
  }
192
- this.client = client;
193
- this.lostError = undefined;
219
+ this.state = { client };
194
220
  this.watch(client);
195
221
  return client;
196
222
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAE7E,kFAAkF;AAClF,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAA;AAEnC,kFAAkF;AAClF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAM,CAAA;AAOzC;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,CAAA;AACvE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,MAAiB,EAAE,QAAoB;IAC1D,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClD,IAAI,IAAI,YAAY,YAAY;QAAE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IACnE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACxB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;AAEtE;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAA0B,EAAE,KAAc;IACrE,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,KAAK,GAAgB,IAAI,KAAK,CAClC,cAAc,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAA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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;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,e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EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
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,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,MAAM,cAAc,CAAA;AAazE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE;;;;;;;OAOG;IACG,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IA8B/D;;;;OAIG;IACH,QAAQ,IAAI,cAAc;IAS1B;;;OAGG;IACG,QAAQ,IAAI,OAAO,CA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AW,GAAG,SAAS;IAIpE;;;;OAIG;IACH,QAAQ,IAAI,cAAc;IAS1B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B;;;;;OAKG;YACW,eAAe;IAQ7B;;;;;;;;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"}
@@ -2,6 +2,7 @@ import { Mutex } from 'async-mutex';
2
2
  import ModbusRTU from 'modbus-serial';
3
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,10 @@ 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
22
+ * - A connection stays open while a transport on it is not released. releaseTransport()
23
+ * closes it when its last transport is released, so the port is free again
19
24
  *
20
25
  * This architecture solves the multi-device problem:
21
26
  * - Each device gets its own SlaveTransport with its own slave ID
@@ -28,11 +33,17 @@ import { SlaveTransport } from './slave-transport.js';
28
33
  * intentional and correct:
29
34
  * - Shared client: Avoids port contention (can't open serial port twice)
30
35
  * - Shared mutex: Ensures serialized access to the bus
31
- * - SlaveTransport.close(): Does not close shared client (use closeAll() for cleanup)
36
+ * - SlaveTransport.close() closes the shared client for all devices on the connection. Use
37
+ * releaseTransport() when a device is removed, and closeAll() at shutdown.
32
38
  */
33
39
  export class TransportManager {
34
- constructor() {
40
+ constructor(options = {}) {
41
+ this.options = options;
35
42
  this.connections = new Map();
43
+ // Connections that are opening, so that devices added at the same time share one client
44
+ this.opening = new Map();
45
+ // Connections that close because their last transport was released
46
+ this.closing = new Set();
36
47
  }
37
48
  /**
38
49
  * Get or create a transport for the given configuration.
@@ -41,26 +52,93 @@ export class TransportManager {
41
52
  *
42
53
  * @param config - RTU or TCP transport configuration
43
54
  * @returns SlaveTransport instance for the specific slave device
55
+ * @throws When the port cannot be opened, unless the `startLost` option is set
44
56
  */
45
57
  async getTransport(config) {
46
58
  const key = this.getPhysicalConnectionKey(config);
47
- const isRTU = this.isRTUConfig(config);
48
59
  // Get or create the shared connection
49
60
  let entry = this.connections.get(key);
50
61
  if (!entry) {
51
- // Create new client for this physical connection
52
- const open = isRTU ? () => this.createRTUClient(config) : () => this.createTCPClient(config);
53
- const client = await open();
54
- entry = {
55
- connection: new ModbusConnection(client, this.getTarget(config), open),
56
- mutex: new Mutex(),
57
- config,
58
- isRTU,
59
- };
60
- this.connections.set(key, entry);
62
+ let opening = this.opening.get(key);
63
+ if (!opening) {
64
+ opening = this.openConnection(key, config).finally(() => this.opening.delete(key));
65
+ this.opening.set(key, opening);
66
+ }
67
+ entry = await opening;
61
68
  }
62
69
  // Return a new SlaveTransport for this specific slave
63
- return new SlaveTransport(config.slaveId, entry.connection, entry.mutex, config.maxRetries ?? 3, config.logger);
70
+ const transport = new SlaveTransport(config.slaveId, entry.connection, entry.mutex, config.maxRetries ?? 3, config.logger);
71
+ entry.transports.add(transport);
72
+ return transport;
73
+ }
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
+ async releaseTransport(transport) {
87
+ for (const [key, entry] of this.connections) {
88
+ if (!entry.transports.delete(transport))
89
+ continue;
90
+ if (entry.transports.size > 0)
91
+ return;
92
+ this.connections.delete(key);
93
+ const closed = this.closeConnection(entry);
94
+ this.closing.add(closed);
95
+ await closed;
96
+ this.closing.delete(closed);
97
+ return;
98
+ }
99
+ }
100
+ /**
101
+ * Open the shared connection for a physical connection and add it to the pool
102
+ *
103
+ * @param key - Physical connection key
104
+ * @param config - Transport configuration
105
+ * @returns The pool entry
106
+ */
107
+ async openConnection(key, config) {
108
+ // A serial port is locked until its close finishes, also with other serial settings
109
+ if (this.closing.size > 0)
110
+ await Promise.all(this.closing);
111
+ const isRTU = this.isRTUConfig(config);
112
+ const open = isRTU ? () => this.createRTUClient(config) : () => this.createTCPClient(config);
113
+ const target = this.getTarget(config);
114
+ let connection;
115
+ try {
116
+ connection = new ModbusConnection(await open(), target, open);
117
+ }
118
+ catch (error) {
119
+ if (!this.options.startLost)
120
+ throw error;
121
+ connection = new ModbusConnection(normalizeModbusError(error), target, open);
122
+ }
123
+ const entry = {
124
+ connection,
125
+ mutex: new Mutex(),
126
+ config,
127
+ isRTU,
128
+ transports: new Set(),
129
+ };
130
+ this.connections.set(key, entry);
131
+ return entry;
132
+ }
133
+ /**
134
+ * Get the error of a lost connection
135
+ *
136
+ * @param config - Configuration of a transport on the connection
137
+ * @returns The error that requests on the connection reject with while it is lost.
138
+ * Undefined while the connection works, or when there is no connection for the config.
139
+ */
140
+ getConnectionError(config) {
141
+ return this.connections.get(this.getPhysicalConnectionKey(config))?.connection.error;
64
142
  }
65
143
  /**
66
144
  * Get statistics about managed connections
@@ -77,20 +155,34 @@ export class TransportManager {
77
155
  }
78
156
  /**
79
157
  * Close all managed connections and clear the pool.
158
+ * Waits for connections that are opening or closing.
80
159
  * Errors during close are logged but do not stop the process.
81
160
  */
82
161
  async closeAll() {
83
- const closePromises = Array.from(this.connections.values()).map(async (entry) => {
84
- try {
85
- await entry.connection.close();
86
- }
87
- catch (error) {
88
- // Log but don't throw - we want to close all connections
89
- console.error('Error closing connection:', error);
90
- }
91
- });
92
- await Promise.all(closePromises);
162
+ // A connection that is still opening is added to the pool when it opens. More opens can
163
+ // start while this waits.
164
+ while (this.opening.size > 0)
165
+ await Promise.allSettled(this.opening.values());
166
+ // Clear the pool first: a connection that opens while these close stays in the pool,
167
+ // so the next closeAll() closes it
168
+ const entries = Array.from(this.connections.values());
93
169
  this.connections.clear();
170
+ // Also wait for connections that close because their last transport was released
171
+ await Promise.all([...entries.map((entry) => this.closeConnection(entry)), ...this.closing]);
172
+ }
173
+ /**
174
+ * Close a connection that is no longer in the pool. Errors are logged, so that the other
175
+ * connections close too.
176
+ *
177
+ * @param entry - Pool entry of the connection
178
+ */
179
+ async closeConnection(entry) {
180
+ try {
181
+ await entry.connection.close();
182
+ }
183
+ catch (error) {
184
+ console.error('Error closing connection:', error);
185
+ }
94
186
  }
95
187
  /**
96
188
  * Generate a unique key for a physical connection.
@@ -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,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAqBrD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,gBAAgB;IAA7B;QACmB,gBAAW,GAAG,IAAI,GAAG,EAA2B,CAAA;IAoJnE,CAAC;IAlJC;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAAC,MAAuB;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACjD,MAAM,KAAK,GAA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57
- * IMPORTANT: This method does not use mutex protection and should only
58
- * be called during shutdown via TransportManager.closeAll(). Calling
59
- * this while operations are in progress may cause connection errors.
57
+ * IMPORTANT: This method does not use mutex protection. Calling this while
58
+ * operations are in progress may cause connection errors.
60
59
  *
61
- * Individual SlaveTransport instances should NOT call close() directly
62
- * as the client is shared across multiple devices on the same bus.
60
+ * Do NOT call close() on a transport from TransportManager: the client is
61
+ * shared across multiple devices on the same bus. Use
62
+ * TransportManager.releaseTransport() when a device is removed, and
63
+ * TransportManager.closeAll() at shutdown.
63
64
  */
64
65
  close(): Promise<void>;
65
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"slave-transport.d.ts","sourceRoot":"","sources":["../../../src/slave-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,SAAS,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,cAAe,YAAW,SAAS;IAW5C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAd1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAE7C;;;;;;OAMG;gBAEgB,OAAO,EAAE,MAAM,EAChC,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACnB,KAAK,EAAE,KAAK,EACZ,UAAU,GAAE,MAAU,EACtB,MAAM,CAAC,EAAE,WAAW,YAAA;IAKjC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAA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