modbus-rs 0.15.0 → 0.15.2

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 (3) hide show
  1. package/index.d.ts +627 -111
  2. package/index.js +67 -54
  3. package/package.json +6 -6
package/index.d.ts CHANGED
@@ -1,80 +1,260 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
- /** Physical serial port in ASCII mode. Factory for device clients. */
3
+ /**
4
+ * Physical serial port in ASCII mode. Factory for device clients.
5
+ * Manages a physical serial port connection in ASCII mode.
6
+ * This class is a factory for creating lightweight `AsyncSerialModbusClient` instances
7
+ * that are bound to a specific unit ID and share the underlying serial connection.
8
+ *
9
+ * Use the static `open` method to establish a connection.
10
+ */
4
11
  export declare class AsyncAsciiTransport {
5
- /** Opens the serial port in ASCII mode. */
12
+ /**
13
+ * Opens the serial port in ASCII mode.
14
+ * Opens a serial port and establishes a connection in ASCII mode.
15
+ * @param opts Options for the serial ASCII transport.
16
+ * @param opts.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3').
17
+ * @param opts.baudRate The baud rate for the serial communication.
18
+ * @returns A `Promise` that resolves to an `AsyncAsciiTransport` instance.
19
+ */
6
20
  static open(opts: AsciiTransportOptions): Promise<AsyncAsciiTransport>
7
- /** Creates a device client bound to the specified unit ID. */
21
+ /**
22
+ * Creates a device client bound to the specified unit ID.
23
+ * Creates a lightweight device client that communicates through this transport.
24
+ * The client is bound to a specific Modbus unit ID.
25
+ * @param opts Options specifying the unit ID.
26
+ */
8
27
  createClient(opts: CreateClientOptions): AsyncSerialModbusClient
9
- /** Sets the per-request timeout in milliseconds. */
28
+ /**
29
+ * Sets the per-request timeout in milliseconds.
30
+ * Sets the timeout for individual Modbus requests made through this transport.
31
+ * @param timeout_ms The timeout duration in milliseconds.
32
+ */
10
33
  setRequestTimeout(timeoutMs: number): void
11
- /** Clears the per-request timeout. */
34
+ /**
35
+ * Clears the per-request timeout.
36
+ * Clears any previously set per-request timeout.
37
+ */
12
38
  clearRequestTimeout(): void
13
- /** Returns whether there are pending requests. */
39
+ /**
40
+ * Returns whether there are pending requests.
41
+ * Checks if there are any Modbus requests currently in-flight on this transport.
42
+ */
14
43
  get pendingRequests(): boolean
15
- /** Closes the transport. */
44
+ /**
45
+ * Closes the transport.
46
+ * Closes the underlying serial port connection.
47
+ */
16
48
  close(): Promise<void>
17
- /** Reconnects the transport after a disconnect. */
49
+ /**
50
+ * Reconnects the transport after a disconnect.
51
+ * Attempts to re-establish the serial connection if it has been closed.
52
+ */
18
53
  reconnect(): Promise<void>
19
54
  }
20
55
 
21
- /** Physical serial port in RTU mode. Factory for device clients. */
56
+ /**
57
+ * Physical serial port in RTU mode. Factory for device clients.
58
+ * Manages a physical serial port connection in RTU mode.
59
+ * This class is a factory for creating lightweight `AsyncSerialModbusClient` instances
60
+ * that are bound to a specific unit ID and share the underlying serial connection.
61
+ *
62
+ * Use the static `open` method to establish a connection.
63
+ */
22
64
  export declare class AsyncRtuTransport {
23
- /** Opens the serial port in RTU mode. */
65
+ /**
66
+ * Opens the serial port in RTU mode.
67
+ * Opens a serial port and establishes a connection in RTU mode.
68
+ * @param opts Options for the serial RTU transport.
69
+ * @param opts.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3').
70
+ * @param opts.baudRate The baud rate for the serial communication.
71
+ * @returns A `Promise` that resolves to an `AsyncRtuTransport` instance.
72
+ */
24
73
  static open(opts: RtuTransportOptions): Promise<AsyncRtuTransport>
25
- /** Creates a device client bound to the specified unit ID. */
74
+ /**
75
+ * Creates a device client bound to the specified unit ID.
76
+ * Creates a lightweight device client that communicates through this transport.
77
+ * The client is bound to a specific Modbus unit ID.
78
+ * @param opts Options specifying the unit ID.
79
+ */
26
80
  createClient(opts: CreateClientOptions): AsyncSerialModbusClient
27
- /** Sets the per-request timeout in milliseconds. */
81
+ /**
82
+ * Sets the per-request timeout in milliseconds.
83
+ * Sets the timeout for individual Modbus requests made through this transport.
84
+ * @param timeout_ms The timeout duration in milliseconds.
85
+ */
28
86
  setRequestTimeout(timeoutMs: number): void
29
- /** Clears the per-request timeout. */
87
+ /**
88
+ * Clears the per-request timeout.
89
+ * Clears any previously set per-request timeout.
90
+ */
30
91
  clearRequestTimeout(): void
31
- /** Returns whether there are pending requests. */
92
+ /**
93
+ * Returns whether there are pending requests.
94
+ * Checks if there are any Modbus requests currently in-flight on this transport.
95
+ */
32
96
  get pendingRequests(): boolean
33
- /** Closes the transport. */
97
+ /**
98
+ * Closes the transport.
99
+ * Closes the underlying serial port connection.
100
+ */
34
101
  close(): Promise<void>
35
- /** Reconnects the transport after a disconnect. */
102
+ /**
103
+ * Reconnects the transport after a disconnect.
104
+ * Attempts to re-establish the serial connection if it has been closed.
105
+ */
36
106
  reconnect(): Promise<void>
37
107
  }
38
108
 
39
- /** Lightweight device client sharing the serial transport. */
109
+ /**
110
+ * Lightweight device client sharing the serial transport.
111
+ * A lightweight Modbus client that sends requests for a specific unit ID
112
+ * over a shared `AsyncRtuTransport` or `AsyncAsciiTransport`.
113
+ */
40
114
  export declare class AsyncSerialModbusClient {
41
- /** Reads holding registers (FC03). */
115
+ /**
116
+ * Reads holding registers (FC03).
117
+ * Reads one or more holding registers (Function Code 03).
118
+ * @param opts Options for reading registers.
119
+ * @param opts.address The starting register address.
120
+ * @param opts.quantity The number of registers to read.
121
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
122
+ */
42
123
  readHoldingRegisters(opts: ReadRegistersOptions): Promise<number[]>
43
- /** Reads input registers (FC04). */
124
+ /**
125
+ * Reads input registers (FC04).
126
+ * Reads one or more input registers (Function Code 04).
127
+ * @param opts Options for reading registers.
128
+ * @param opts.address The starting register address.
129
+ * @param opts.quantity The number of registers to read.
130
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
131
+ */
44
132
  readInputRegisters(opts: ReadRegistersOptions): Promise<number[]>
45
- /** Writes a single register (FC06). */
133
+ /**
134
+ * Writes a single register (FC06).
135
+ * Writes a single holding register (Function Code 06).
136
+ * @param opts Options for writing a single register.
137
+ * @param opts.address The register address.
138
+ * @param opts.value The 16-bit value to write.
139
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
140
+ */
46
141
  writeSingleRegister(opts: WriteSingleRegisterOptions): Promise<void>
47
- /** Writes multiple registers (FC16). */
142
+ /**
143
+ * Writes multiple registers (FC16).
144
+ * Writes multiple consecutive holding registers (Function Code 16).
145
+ * @param opts Options for writing multiple registers.
146
+ * @param opts.address The starting register address.
147
+ * @param opts.values An array of 16-bit values to write.
148
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
149
+ */
48
150
  writeMultipleRegisters(opts: WriteMultipleRegistersOptions): Promise<void>
49
- /** Reads and writes multiple registers atomically (FC23). */
151
+ /**
152
+ * Reads and writes multiple registers atomically (FC23).
153
+ * Performs an atomic read/write operation on multiple registers (Function Code 23).
154
+ * @param opts Options for the read/write operation.
155
+ * @param opts.read_address The starting address for the read operation.
156
+ * @param opts.read_quantity The number of registers to read.
157
+ * @param opts.write_address The starting address for the write operation.
158
+ * @param opts.write_values An array of 16-bit values to write.
159
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
160
+ */
50
161
  readWriteMultipleRegisters(opts: ReadWriteMultipleRegistersOptions): Promise<number[]>
51
- /** Reads coils (FC01). */
162
+ /**
163
+ * Reads coils (FC01).
164
+ * Reads the status of one or more coils (Function Code 01).
165
+ * @param opts Options for reading bits.
166
+ * @param opts.address The starting coil address.
167
+ * @param opts.quantity The number of coils to read.
168
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
169
+ */
52
170
  readCoils(opts: ReadBitsOptions): Promise<boolean[]>
53
- /** Writes a single coil (FC05). */
171
+ /**
172
+ * Writes a single coil (FC05).
173
+ * Writes a single coil (Function Code 05).
174
+ * @param opts Options for writing a single coil.
175
+ * @param opts.address The coil address.
176
+ * @param opts.value The boolean value to write (true for ON, false for OFF).
177
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
178
+ */
54
179
  writeSingleCoil(opts: WriteSingleCoilOptions): Promise<void>
55
- /** Writes multiple coils (FC15). */
180
+ /**
181
+ * Writes multiple coils (FC15).
182
+ * Writes multiple consecutive coils (Function Code 15).
183
+ * @param opts Options for writing multiple coils.
184
+ * @param opts.address The starting coil address.
185
+ * @param opts.values An array of boolean values to write.
186
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
187
+ */
56
188
  writeMultipleCoils(opts: WriteMultipleCoilsOptions): Promise<void>
57
- /** Reads discrete inputs (FC02). */
189
+ /**
190
+ * Reads discrete inputs (FC02).
191
+ * Reads the status of one or more discrete inputs (Function Code 02).
192
+ * @param opts Options for reading bits.
193
+ * @param opts.address The starting discrete input address.
194
+ * @param opts.quantity The number of discrete inputs to read.
195
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
196
+ */
58
197
  readDiscreteInputs(opts: ReadBitsOptions): Promise<boolean[]>
59
- /** Reads FIFO queue (FC24). */
198
+ /**
199
+ * Reads FIFO queue (FC24).
200
+ * Reads from a FIFO queue register (Function Code 24).
201
+ * @param opts Options for reading the FIFO queue.
202
+ * @param opts.address The FIFO pointer address.
203
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
204
+ */
60
205
  readFifoQueue(opts: ReadFifoQueueOptions): Promise<FifoQueueResponse>
61
- /** Reads file records (FC20). */
206
+ /**
207
+ * Reads file records (FC20).
208
+ * Reads one or more file records (Function Code 20).
209
+ * @param opts Options for reading file records.
210
+ * @param opts.requests An array of file record read sub-requests.
211
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
212
+ */
62
213
  readFileRecord(opts: ReadFileRecordOptions): Promise<number[][]>
63
- /** Writes file records (FC21). */
214
+ /**
215
+ * Writes file records (FC21).
216
+ * Writes one or more file records (Function Code 21).
217
+ * @param opts Options for writing file records.
218
+ * @param opts.requests An array of file record write sub-requests.
219
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
220
+ */
64
221
  writeFileRecord(opts: WriteFileRecordOptions): Promise<void>
65
- /** Reads exception status (FC07). */
222
+ /**
223
+ * Reads exception status (FC07).
224
+ * Reads the device's exception status byte (Function Code 07).
225
+ */
66
226
  readExceptionStatus(): Promise<number>
67
- /** Sends a diagnostics request (FC08). */
227
+ /**
228
+ * Sends a diagnostics request (FC08).
229
+ * Executes a diagnostic function on the device (Function Code 08).
230
+ * @param opts Options for the diagnostics request.
231
+ * @param opts.sub_function The diagnostic sub-function code.
232
+ * @param opts.data Data to be sent with the request.
233
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
234
+ */
68
235
  diagnostics(opts: DiagnosticsOptions): Promise<DiagnosticsResponse>
69
- /** Reads device identification (FC43/MEI14). */
236
+ /**
237
+ * Reads device identification (FC43/MEI14).
238
+ * Reads device identification information (Function Code 43, MEI 14).
239
+ * @param opts Options for reading device identification.
240
+ * @param opts.read_device_id_code The category of objects to read (e.g., basic, regular).
241
+ * @param opts.object_id The ID of the first object to read.
242
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
243
+ */
70
244
  readDeviceIdentification(opts: ReadDeviceIdentificationOptions): Promise<DeviceIdentificationResponse>
71
245
  }
72
246
 
73
- /** Async Modbus Serial server supporting RTU and ASCII transports. */
247
+ /**
248
+ * Async Modbus Serial server supporting RTU and ASCII transports.
249
+ * An asynchronous Modbus server that listens on a serial port for incoming requests.
250
+ * It supports both RTU and ASCII transport modes.
251
+ * Use the static `bindRtu` or `bindAscii` methods to create and start a server instance.
252
+ */
74
253
  export declare class AsyncSerialModbusServer {
75
- static bindRtu(opts: SerialServerOptions, handlers: ServerHandlers): Promise<AsyncSerialModbusServer>
76
- static bindAscii(opts: SerialServerOptions, handlers: ServerHandlers): Promise<AsyncSerialModbusServer>
77
- /** Stops the server. */
254
+ /**
255
+ * Stops the server.
256
+ * Stops the server and closes the serial port.
257
+ */
78
258
  shutdown(): Promise<void>
79
259
  }
80
260
 
@@ -96,73 +276,222 @@ export declare class AsyncTcpGateway {
96
276
  shutdown(): Promise<void>
97
277
  }
98
278
 
99
- /** Lightweight device client sharing the TCP transport. */
279
+ /**
280
+ * Lightweight device client sharing the TCP transport.
281
+ * A lightweight Modbus client that sends requests for a specific unit ID
282
+ * over a shared `AsyncTcpTransport`.
283
+ */
100
284
  export declare class AsyncTcpModbusClient {
101
- /** Reads holding registers (FC03). */
285
+ /**
286
+ * Reads holding registers (FC03).
287
+ * Reads one or more holding registers (Function Code 03).
288
+ * @param opts Options for reading registers.
289
+ * @param opts.address The starting register address.
290
+ * @param opts.quantity The number of registers to read.
291
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
292
+ */
102
293
  readHoldingRegisters(opts: ReadRegistersOptions): Promise<number[]>
103
- /** Reads input registers (FC04). */
294
+ /**
295
+ * Reads input registers (FC04).
296
+ * Reads one or more input registers (Function Code 04).
297
+ * @param opts Options for reading registers.
298
+ * @param opts.address The starting register address.
299
+ * @param opts.quantity The number of registers to read.
300
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
301
+ */
104
302
  readInputRegisters(opts: ReadRegistersOptions): Promise<number[]>
105
- /** Writes a single register (FC06). */
303
+ /**
304
+ * Writes a single register (FC06).
305
+ * Writes a single holding register (Function Code 06).
306
+ * @param opts Options for writing a single register.
307
+ * @param opts.address The register address.
308
+ * @param opts.value The 16-bit value to write.
309
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
310
+ */
106
311
  writeSingleRegister(opts: WriteSingleRegisterOptions): Promise<void>
107
- /** Writes multiple registers (FC16). */
312
+ /**
313
+ * Writes multiple registers (FC16).
314
+ * Writes multiple consecutive holding registers (Function Code 16).
315
+ * @param opts Options for writing multiple registers.
316
+ * @param opts.address The starting register address.
317
+ * @param opts.values An array of 16-bit values to write.
318
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
319
+ */
108
320
  writeMultipleRegisters(opts: WriteMultipleRegistersOptions): Promise<void>
109
- /** Reads and writes multiple registers atomically (FC23). */
321
+ /**
322
+ * Reads and writes multiple registers atomically (FC23).
323
+ * Performs an atomic read/write operation on multiple registers (Function Code 23).
324
+ * @param opts Options for the read/write operation.
325
+ * @param opts.read_address The starting address for the read operation.
326
+ * @param opts.read_quantity The number of registers to read.
327
+ * @param opts.write_address The starting address for the write operation.
328
+ * @param opts.write_values An array of 16-bit values to write.
329
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
330
+ */
110
331
  readWriteMultipleRegisters(opts: ReadWriteMultipleRegistersOptions): Promise<number[]>
111
- /** Reads coils (FC01). */
332
+ /**
333
+ * Reads coils (FC01).
334
+ * Reads the status of one or more coils (Function Code 01).
335
+ * @param opts Options for reading bits.
336
+ * @param opts.address The starting coil address.
337
+ * @param opts.quantity The number of coils to read.
338
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
339
+ */
112
340
  readCoils(opts: ReadBitsOptions): Promise<boolean[]>
113
- /** Writes a single coil (FC05). */
341
+ /**
342
+ * Writes a single coil (FC05).
343
+ * Writes a single coil (Function Code 05).
344
+ * @param opts Options for writing a single coil.
345
+ * @param opts.address The coil address.
346
+ * @param opts.value The boolean value to write (true for ON, false for OFF).
347
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
348
+ */
114
349
  writeSingleCoil(opts: WriteSingleCoilOptions): Promise<void>
115
- /** Writes multiple coils (FC15). */
350
+ /**
351
+ * Writes multiple coils (FC15).
352
+ * Writes multiple consecutive coils (Function Code 15).
353
+ * @param opts Options for writing multiple coils.
354
+ * @param opts.address The starting coil address.
355
+ * @param opts.values An array of boolean values to write.
356
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
357
+ */
116
358
  writeMultipleCoils(opts: WriteMultipleCoilsOptions): Promise<void>
117
- /** Reads discrete inputs (FC02). */
359
+ /**
360
+ * Reads discrete inputs (FC02).
361
+ * Reads the status of one or more discrete inputs (Function Code 02).
362
+ * @param opts Options for reading bits.
363
+ * @param opts.address The starting discrete input address.
364
+ * @param opts.quantity The number of discrete inputs to read.
365
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
366
+ */
118
367
  readDiscreteInputs(opts: ReadBitsOptions): Promise<boolean[]>
119
- /** Reads FIFO queue (FC24). */
368
+ /**
369
+ * Reads FIFO queue (FC24).
370
+ * Reads from a FIFO queue register (Function Code 24).
371
+ * @param opts Options for reading the FIFO queue.
372
+ * @param opts.address The FIFO pointer address.
373
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
374
+ */
120
375
  readFifoQueue(opts: ReadFifoQueueOptions): Promise<FifoQueueResponse>
121
- /** Reads file records (FC20). */
376
+ /**
377
+ * Reads file records (FC20).
378
+ * Reads one or more file records (Function Code 20).
379
+ * @param opts Options for reading file records.
380
+ * @param opts.requests An array of file record read sub-requests.
381
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
382
+ */
122
383
  readFileRecord(opts: ReadFileRecordOptions): Promise<number[][]>
123
- /** Writes file records (FC21). */
384
+ /**
385
+ * Writes file records (FC21).
386
+ * Writes one or more file records (Function Code 21).
387
+ * @param opts Options for writing file records.
388
+ * @param opts.requests An array of file record write sub-requests.
389
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
390
+ */
124
391
  writeFileRecord(opts: WriteFileRecordOptions): Promise<void>
125
- /** Reads exception status (FC07). */
392
+ /**
393
+ * Reads exception status (FC07).
394
+ * Reads the device's exception status byte (Function Code 07).
395
+ */
126
396
  readExceptionStatus(): Promise<number>
127
- /** Sends a diagnostics request (FC08). */
397
+ /**
398
+ * Sends a diagnostics request (FC08).
399
+ * Executes a diagnostic function on the device (Function Code 08).
400
+ * @param opts Options for the diagnostics request.
401
+ * @param opts.sub_function The diagnostic sub-function code.
402
+ * @param opts.data Data to be sent with the request.
403
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
404
+ */
128
405
  diagnostics(opts: DiagnosticsOptions): Promise<DiagnosticsResponse>
129
- /** Reads device identification (FC43/MEI14). */
406
+ /**
407
+ * Reads device identification (FC43/MEI14).
408
+ * Reads device identification information (Function Code 43, MEI 14).
409
+ * @param opts Options for reading device identification.
410
+ * @param opts.read_device_id_code The category of objects to read (e.g., basic, regular).
411
+ * @param opts.object_id The ID of the first object to read.
412
+ * @param opts.signal An optional `AbortSignal` to cancel the operation.
413
+ */
130
414
  readDeviceIdentification(opts: ReadDeviceIdentificationOptions): Promise<DeviceIdentificationResponse>
131
415
  }
132
416
 
133
417
  /**
134
- * Async Modbus TCP server.
418
+ * Async Modbus TCP server.
135
419
  *
136
- * Binds to a TCP port and handles incoming Modbus requests using JS callbacks.
420
+ * Binds to a TCP port and handles incoming Modbus requests using JS callbacks.
421
+ * An asynchronous Modbus TCP server that listens for incoming client connections.
137
422
  */
138
423
  export declare class AsyncTcpModbusServer {
139
424
  /**
140
- * Creates and starts a new TCP server.
425
+ * Creates and starts a new TCP server.
426
+ * Creates and starts a new Modbus TCP server.
141
427
  *
142
- * @param opts - Server bind options.
143
- * @param handlers - Object containing handler functions for each Modbus operation.
144
- * @returns A running server instance.
428
+ * @param opts Server bind options.
429
+ * @param opts.host The host address to bind to (e.g., '0.0.0.0').
430
+ * @param opts.port The TCP port to listen on.
431
+ * @param opts.unitId The Modbus unit ID the server will respond to.
432
+ * @param handlers An object containing callback functions to handle Modbus requests (matches the `ServerHandlers` interface in TypeScript).
433
+ * @returns A `Promise` that resolves to a running `AsyncTcpModbusServer` instance.
145
434
  */
146
435
  static bind(opts: TcpServerOptions, handlers: ServerHandlers): Promise<AsyncTcpModbusServer>
147
- /** Stops the server. */
436
+ /**
437
+ * Stops the server.
438
+ * Stops the server and closes all active connections.
439
+ */
148
440
  shutdown(): Promise<void>
149
441
  }
150
442
 
151
- /** Physical TCP socket connection to a Modbus device or gateway. */
443
+ /**
444
+ * Physical TCP socket connection to a Modbus device or gateway.
445
+ * Manages a physical TCP socket connection to a Modbus device or gateway.
446
+ * This class is a factory for creating lightweight `AsyncTcpModbusClient` instances
447
+ * that are bound to a specific unit ID and share the underlying TCP connection.
448
+ *
449
+ * Use the static `connect` method to establish a connection.
450
+ */
152
451
  export declare class AsyncTcpTransport {
153
- /** Connects to a Modbus TCP device or gateway. */
452
+ /**
453
+ * Connects to a Modbus TCP device or gateway.
454
+ * Establishes a connection to a Modbus TCP device or gateway.
455
+ *
456
+ * @param opts - Connection options including host, port, and timeout settings.
457
+ * @param opts.host - Target host address (IP or hostname).
458
+ * @param opts.port - Target TCP port (typically 502).
459
+ */
154
460
  static connect(opts: TcpTransportOptions): Promise<AsyncTcpTransport>
155
- /** Creates a device client bound to the specified unit ID. */
461
+ /**
462
+ * Creates a device client bound to the specified unit ID.
463
+ * Creates a lightweight device client that communicates through this transport.
464
+ * The client is bound to a specific Modbus unit ID.
465
+ *
466
+ * @param opts - Options specifying the unit ID.
467
+ */
156
468
  createClient(opts: CreateClientOptions): AsyncTcpModbusClient
157
- /** Sets the per-request timeout in milliseconds. */
469
+ /**
470
+ * Sets the per-request timeout in milliseconds.
471
+ * Sets the timeout for individual Modbus requests made through this transport.
472
+ *
473
+ * @param timeout_ms - The timeout duration in milliseconds.
474
+ */
158
475
  setRequestTimeout(timeoutMs: number): void
159
- /** Clears the per-request timeout. */
476
+ /**
477
+ * Clears the per-request timeout.
478
+ * Clears any previously set per-request timeout, reverting to the default behavior.
479
+ */
160
480
  clearRequestTimeout(): void
161
- /** Returns whether there are pending requests. */
481
+ /**
482
+ * Returns whether there are pending requests.
483
+ * Checks if there are any Modbus requests currently in-flight on this transport.
484
+ */
162
485
  get pendingRequests(): boolean
163
- /** Closes the connection. */
486
+ /**
487
+ * Closes the connection.
488
+ * Closes the underlying TCP connection and shuts down the transport.
489
+ */
164
490
  close(): Promise<void>
165
- /** Reconnects the transport after a disconnect. */
491
+ /**
492
+ * Reconnects the transport after a disconnect.
493
+ * Attempts to re-establish the TCP connection if it has been closed.
494
+ */
166
495
  reconnect(): Promise<void>
167
496
  }
168
497
 
@@ -184,33 +513,35 @@ export interface AsciiTransportOptions {
184
513
  requestTimeoutMs?: number
185
514
  /** Number of retry attempts on failure (0 = none). Default: 0. */
186
515
  retryAttempts?: number
516
+ /** Delay between retry attempts in milliseconds. */
517
+ retryDelayMs?: number
187
518
  /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
188
519
  retryBackoffStrategy?: string
189
520
  }
190
521
 
191
522
  /** Options for creating a device client. */
192
523
  export interface CreateClientOptions {
193
- /** Modbus unit ID (1-247). */
524
+ /** Modbus unit ID (slave address) from 1 to 247. */
194
525
  unitId: number
195
526
  }
196
527
 
197
528
  /** Device identification object. */
198
529
  export interface DeviceIdentificationObject {
199
- /** Object ID. */
530
+ /** The object ID. */
200
531
  id: number
201
- /** Object value as string. */
532
+ /** The value of the object, represented as a string. */
202
533
  value: string
203
534
  }
204
535
 
205
536
  /** Response from device identification request. */
206
537
  export interface DeviceIdentificationResponse {
207
- /** Conformity level. */
538
+ /** The conformity level of the device. */
208
539
  conformityLevel: number
209
- /** Whether more objects follow. */
540
+ /** Indicates if more objects are available to be read. */
210
541
  moreFollows: boolean
211
- /** Next object ID if more follows. */
542
+ /** The ID of the next object to read if `moreFollows` is true. */
212
543
  nextObjectId: number
213
- /** Retrieved objects. */
544
+ /** An array of device identification objects. */
214
545
  objects: Array<DeviceIdentificationObject>
215
546
  }
216
547
 
@@ -218,24 +549,27 @@ export interface DeviceIdentificationResponse {
218
549
  export interface DiagnosticsOptions {
219
550
  /** Diagnostic sub-function code. */
220
551
  subFunction: number
221
- /** Data words for the request. */
552
+ /** Data to be sent with the diagnostics request. */
222
553
  data: Array<number>
223
- /** Optional abort signal to cancel the request. */
554
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
224
555
  signal?: AbortSignal
225
556
  }
226
557
 
227
558
  /** Handler request for diagnostics. */
228
559
  export interface DiagnosticsRequest {
560
+ /** The unit ID of the device that sent the request. */
229
561
  unitId: number
562
+ /** The diagnostic sub-function code to execute. */
230
563
  subFunction: number
564
+ /** Data sent with the diagnostics request. */
231
565
  data: Array<number>
232
566
  }
233
567
 
234
568
  /** Response from diagnostics request. */
235
569
  export interface DiagnosticsResponse {
236
- /** Echoed sub-function code. */
570
+ /** The sub-function code from the request. */
237
571
  subFunction: number
238
- /** Response data words. */
572
+ /** The data returned by the diagnostics function. */
239
573
  data: Array<number>
240
574
  }
241
575
 
@@ -255,35 +589,41 @@ export interface FifoQueueResponse {
255
589
 
256
590
  /** A single file record read sub-request. */
257
591
  export interface FileRecordReadRequest {
258
- /** File number (1-65535). */
592
+ /** The file number (1-65535). */
259
593
  fileNumber: number
260
- /** Starting record number. */
594
+ /** The starting record number within the file. */
261
595
  recordNumber: number
262
- /** Number of records to read. */
596
+ /** The number of records to read. */
263
597
  recordLength: number
264
598
  }
265
599
 
266
600
  /** A single file record read sub-request on the server side. */
267
601
  export interface FileRecordReadServerSubRequest {
602
+ /** The file number (1-65535). */
268
603
  fileNumber: number
604
+ /** The starting record number within the file. */
269
605
  recordNumber: number
606
+ /** The number of records to read. */
270
607
  recordLength: number
271
608
  }
272
609
 
273
610
  /** A single file record write sub-request. */
274
611
  export interface FileRecordWriteRequest {
275
- /** File number (1-65535). */
612
+ /** The file number (1-65535). */
276
613
  fileNumber: number
277
- /** Starting record number. */
614
+ /** The starting record number within the file. */
278
615
  recordNumber: number
279
- /** Record data to write. */
616
+ /** The record data to write, as an array of 16-bit values. */
280
617
  recordData: Array<number>
281
618
  }
282
619
 
283
620
  /** A single file record write sub-request on the server side. */
284
621
  export interface FileRecordWriteSubRequest {
622
+ /** The file number (1-65535). */
285
623
  fileNumber: number
624
+ /** The starting record number within the file. */
286
625
  recordNumber: number
626
+ /** The record data to write, as an array of 16-bit values. */
287
627
  recordData: Array<number>
288
628
  }
289
629
 
@@ -325,16 +665,19 @@ export const MODBUS_ERROR_CODE_TRANSPORT: string
325
665
  export interface ReadBitsOptions {
326
666
  /** Starting address. */
327
667
  address: number
328
- /** Number of bits to read. */
668
+ /** Number of bits (coils or discrete inputs) to read. */
329
669
  quantity: number
330
- /** Optional abort signal to cancel the request. */
670
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
331
671
  signal?: AbortSignal
332
672
  }
333
673
 
334
674
  /** Handler request for reading coils. */
335
675
  export interface ReadCoilsRequest {
676
+ /** The unit ID of the device that sent the request. */
336
677
  unitId: number
678
+ /** The starting address of the coils to read. */
337
679
  address: number
680
+ /** The number of coils to read. */
338
681
  quantity: number
339
682
  }
340
683
 
@@ -342,21 +685,25 @@ export interface ReadCoilsRequest {
342
685
  export interface ReadDeviceIdentificationOptions {
343
686
  /** Read device ID code (1=basic, 2=regular, 3=extended, 4=individual). */
344
687
  readDeviceIdCode: number
345
- /** Starting object ID. */
688
+ /** The ID of the first object to read. */
346
689
  objectId: number
347
- /** Optional abort signal to cancel the request. */
690
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
348
691
  signal?: AbortSignal
349
692
  }
350
693
 
351
694
  /** Handler request for reading discrete inputs. */
352
695
  export interface ReadDiscreteInputsRequest {
696
+ /** The unit ID of the device that sent the request. */
353
697
  unitId: number
698
+ /** The starting address of the discrete inputs to read. */
354
699
  address: number
700
+ /** The number of discrete inputs to read. */
355
701
  quantity: number
356
702
  }
357
703
 
358
704
  /** Handler request for reading exception status. */
359
705
  export interface ReadExceptionStatusRequest {
706
+ /** The unit ID of the device that sent the request. */
360
707
  unitId: number
361
708
  }
362
709
 
@@ -364,41 +711,51 @@ export interface ReadExceptionStatusRequest {
364
711
  export interface ReadFifoQueueOptions {
365
712
  /** FIFO pointer address. */
366
713
  address: number
367
- /** Optional abort signal to cancel the request. */
714
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
368
715
  signal?: AbortSignal
369
716
  }
370
717
 
371
718
  /** Handler request for reading FIFO queue. */
372
719
  export interface ReadFifoQueueRequest {
720
+ /** The unit ID of the device that sent the request. */
373
721
  unitId: number
722
+ /** The address of the FIFO queue pointer register. */
374
723
  address: number
375
724
  }
376
725
 
377
726
  /** Options for reading file records. */
378
727
  export interface ReadFileRecordOptions {
379
- /** Array of sub-requests. */
728
+ /** An array of file record read sub-requests. */
380
729
  requests: Array<FileRecordReadRequest>
381
- /** Optional abort signal to cancel the request. */
730
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
382
731
  signal?: AbortSignal
383
732
  }
384
733
 
385
734
  /** Handler request for reading file records. */
386
735
  export interface ReadFileRecordRequest {
736
+ /** The unit ID of the device that sent the request. */
387
737
  unitId: number
738
+ /** An array of file record read sub-requests. */
388
739
  requests: Array<FileRecordReadServerSubRequest>
389
740
  }
390
741
 
391
742
  /** Handler request for reading holding registers. */
392
743
  export interface ReadHoldingRegistersRequest {
744
+ /** The unit ID of the device that sent the request. */
393
745
  unitId: number
746
+ /** The starting address of the holding registers to read. */
394
747
  address: number
748
+ /** The number of holding registers to read. */
395
749
  quantity: number
396
750
  }
397
751
 
398
752
  /** Handler request for reading input registers. */
399
753
  export interface ReadInputRegistersRequest {
754
+ /** The unit ID of the device that sent the request. */
400
755
  unitId: number
756
+ /** The starting address of the input registers to read. */
401
757
  address: number
758
+ /** The number of input registers to read. */
402
759
  quantity: number
403
760
  }
404
761
 
@@ -406,9 +763,9 @@ export interface ReadInputRegistersRequest {
406
763
  export interface ReadRegistersOptions {
407
764
  /** Starting register address. */
408
765
  address: number
409
- /** Number of registers to read. */
766
+ /** Number of registers to read (quantity). */
410
767
  quantity: number
411
- /** Optional abort signal to cancel the request. */
768
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
412
769
  signal?: AbortSignal
413
770
  }
414
771
 
@@ -416,22 +773,27 @@ export interface ReadRegistersOptions {
416
773
  export interface ReadWriteMultipleRegistersOptions {
417
774
  /** Starting address for read operation. */
418
775
  readAddress: number
419
- /** Number of registers to read. */
776
+ /** Number of registers to read (quantity). */
420
777
  readQuantity: number
421
778
  /** Starting address for write operation. */
422
779
  writeAddress: number
423
- /** Values to write. */
780
+ /** An array of 16-bit values to write. */
424
781
  writeValues: Array<number>
425
- /** Optional abort signal to cancel the request. */
782
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
426
783
  signal?: AbortSignal
427
784
  }
428
785
 
429
786
  /** Handler request for read/write multiple registers (FC23). */
430
787
  export interface ReadWriteMultipleRegistersRequest {
788
+ /** The unit ID of the device that sent the request. */
431
789
  unitId: number
790
+ /** The starting address for the read operation. */
432
791
  readAddress: number
792
+ /** The number of registers to read. */
433
793
  readQuantity: number
794
+ /** The starting address for the write operation. */
434
795
  writeAddress: number
796
+ /** The array of 16-bit values to write. */
435
797
  writeValues: Array<number>
436
798
  }
437
799
 
@@ -461,6 +823,8 @@ export interface RtuTransportOptions {
461
823
  requestTimeoutMs?: number
462
824
  /** Number of retry attempts on failure (0 = none). Default: 0. */
463
825
  retryAttempts?: number
826
+ /** Delay between retry attempts in milliseconds. */
827
+ retryDelayMs?: number
464
828
  /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
465
829
  retryBackoffStrategy?: string
466
830
  }
@@ -477,7 +841,7 @@ export interface SerialServerOptions {
477
841
  parity?: string
478
842
  /** Stop bits (1 or 2). */
479
843
  stopBits?: number
480
- /** Modbus unit ID (1-247). */
844
+ /** Modbus unit ID (1-247) for the server to respond to. */
481
845
  unitId: number
482
846
  /** Response timeout in milliseconds. */
483
847
  responseTimeoutMs?: number
@@ -485,13 +849,18 @@ export interface SerialServerOptions {
485
849
 
486
850
  /** Handler response for diagnostics. */
487
851
  export interface ServerDiagnosticsResponse {
852
+ /** The sub-function code from the request. */
488
853
  subFunction: number
854
+ /** The data to be returned by the diagnostics function. */
489
855
  data: Array<number>
490
856
  }
491
857
 
492
858
  /** Response that may include an exception code. */
493
859
  export interface ServerExceptionResponse {
494
- /** Modbus exception code if this is an error response. */
860
+ /**
861
+ * The Modbus exception code (e.g., 1 for Illegal Function).
862
+ * Modbus exception code if this is an error response.
863
+ */
495
864
  exception?: number
496
865
  }
497
866
 
@@ -511,25 +880,29 @@ export interface TcpTransportOptions {
511
880
  host: string
512
881
  /** Target TCP port (typically 502). */
513
882
  port: number
514
- /** Per-request timeout in milliseconds (optional). */
883
+ /** Per-request timeout in milliseconds. */
515
884
  requestTimeoutMs?: number
516
- /** Number of retry attempts on failure (0 = none). Default: 0. */
885
+ /** Number of retry attempts on failure. Default: 0 (no retries). */
517
886
  retryAttempts?: number
518
- /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
887
+ /** Delay between retry attempts in milliseconds. */
888
+ retryDelayMs?: number
889
+ /** Backoff strategy for retries: "immediate", "fixed", or "exponential". Default: "immediate". */
519
890
  retryBackoffStrategy?: string
520
891
  }
521
892
 
522
893
  /** Options for writing file records. */
523
894
  export interface WriteFileRecordOptions {
524
- /** Array of sub-requests. */
895
+ /** An array of file record write sub-requests. */
525
896
  requests: Array<FileRecordWriteRequest>
526
- /** Optional abort signal to cancel the request. */
897
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
527
898
  signal?: AbortSignal
528
899
  }
529
900
 
530
901
  /** Handler request for writing file records. */
531
902
  export interface WriteFileRecordRequest {
903
+ /** The unit ID of the device that sent the request. */
532
904
  unitId: number
905
+ /** An array of file record write sub-requests. */
533
906
  requests: Array<FileRecordWriteSubRequest>
534
907
  }
535
908
 
@@ -537,16 +910,19 @@ export interface WriteFileRecordRequest {
537
910
  export interface WriteMultipleCoilsOptions {
538
911
  /** Starting coil address. */
539
912
  address: number
540
- /** Values to write. */
913
+ /** An array of boolean values to write. */
541
914
  values: Array<boolean>
542
- /** Optional abort signal to cancel the request. */
915
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
543
916
  signal?: AbortSignal
544
917
  }
545
918
 
546
919
  /** Handler request for writing multiple coils. */
547
920
  export interface WriteMultipleCoilsRequest {
921
+ /** The unit ID of the device that sent the request. */
548
922
  unitId: number
923
+ /** The starting address of the coils to write to. */
549
924
  address: number
925
+ /** The array of boolean values to write. */
550
926
  values: Array<boolean>
551
927
  }
552
928
 
@@ -554,16 +930,19 @@ export interface WriteMultipleCoilsRequest {
554
930
  export interface WriteMultipleRegistersOptions {
555
931
  /** Starting register address. */
556
932
  address: number
557
- /** Values to write. */
933
+ /** An array of 16-bit values to write. */
558
934
  values: Array<number>
559
- /** Optional abort signal to cancel the request. */
935
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
560
936
  signal?: AbortSignal
561
937
  }
562
938
 
563
939
  /** Handler request for writing multiple registers. */
564
940
  export interface WriteMultipleRegistersRequest {
941
+ /** The unit ID of the device that sent the request. */
565
942
  unitId: number
943
+ /** The starting address of the registers to write to. */
566
944
  address: number
945
+ /** The array of 16-bit values to write. */
567
946
  values: Array<number>
568
947
  }
569
948
 
@@ -571,16 +950,19 @@ export interface WriteMultipleRegistersRequest {
571
950
  export interface WriteSingleCoilOptions {
572
951
  /** Coil address. */
573
952
  address: number
574
- /** Value to write. */
953
+ /** The boolean value to write (true for ON, false for OFF). */
575
954
  value: boolean
576
- /** Optional abort signal to cancel the request. */
955
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
577
956
  signal?: AbortSignal
578
957
  }
579
958
 
580
959
  /** Handler request for writing a single coil. */
581
960
  export interface WriteSingleCoilRequest {
961
+ /** The unit ID of the device that sent the request. */
582
962
  unitId: number
963
+ /** The address of the coil to write to. */
583
964
  address: number
965
+ /** The value to write (true for ON, false for OFF). */
584
966
  value: boolean
585
967
  }
586
968
 
@@ -588,16 +970,19 @@ export interface WriteSingleCoilRequest {
588
970
  export interface WriteSingleRegisterOptions {
589
971
  /** Register address. */
590
972
  address: number
591
- /** Value to write. */
973
+ /** The 16-bit value to write to the register. */
592
974
  value: number
593
- /** Optional abort signal to cancel the request. */
975
+ /** An optional `AbortSignal` to cancel the asynchronous operation. */
594
976
  signal?: AbortSignal
595
977
  }
596
978
 
597
979
  /** Handler request for writing a single register. */
598
980
  export interface WriteSingleRegisterRequest {
981
+ /** The unit ID of the device that sent the request. */
599
982
  unitId: number
983
+ /** The address of the register to write to. */
600
984
  address: number
985
+ /** The 16-bit value to write. */
601
986
  value: number
602
987
  }
603
988
 
@@ -605,30 +990,161 @@ export interface ModbusException {
605
990
  exception: number;
606
991
  }
607
992
 
993
+ /**
994
+ * Callback functions to handle Modbus server requests.
995
+ *
996
+ * Each handler corresponds to a specific Modbus function code. If a handler is not provided,
997
+ * the server will respond with an "Illegal Function" exception (0x01).
998
+ *
999
+ * Handlers can return the expected data directly or return a Promise for async operations.
1000
+ * To return a Modbus exception, return an object matching the `ModbusException` interface.
1001
+ */
608
1002
  export interface ServerHandlers {
1003
+ /**
1004
+ * Handle Read Coils (FC 01).
1005
+ * @param req The request object.
1006
+ * @param req.address The starting coil address (0x0000 to 0xFFFF).
1007
+ * @param req.quantity The number of coils to read (1 to 2000).
1008
+ * @returns An array of booleans representing the coil states, or a ModbusException.
1009
+ */
609
1010
  onReadCoils?: (req: ReadCoilsRequest) => boolean[] | ModbusException | Promise<boolean[] | ModbusException>;
1011
+
1012
+ /**
1013
+ * Handle Read Discrete Inputs (FC 02).
1014
+ * @param req The request object.
1015
+ * @param req.address The starting discrete input address (0x0000 to 0xFFFF).
1016
+ * @param req.quantity The number of inputs to read (1 to 2000).
1017
+ * @returns An array of booleans representing the input states, or a ModbusException.
1018
+ */
610
1019
  onReadDiscreteInputs?: (req: ReadDiscreteInputsRequest) => boolean[] | ModbusException | Promise<boolean[] | ModbusException>;
1020
+
1021
+ /**
1022
+ * Handle Read Holding Registers (FC 03).
1023
+ * @param req The request object.
1024
+ * @param req.address The starting holding register address (0x0000 to 0xFFFF).
1025
+ * @param req.quantity The number of registers to read (1 to 125).
1026
+ * @returns An array of 16-bit numbers representing the registers, or a ModbusException.
1027
+ */
611
1028
  onReadHoldingRegisters?: (req: ReadHoldingRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
1029
+
1030
+ /**
1031
+ * Handle Read Input Registers (FC 04).
1032
+ * @param req The request object.
1033
+ * @param req.address The starting input register address (0x0000 to 0xFFFF).
1034
+ * @param req.quantity The number of registers to read (1 to 125).
1035
+ * @returns An array of 16-bit numbers representing the registers, or a ModbusException.
1036
+ */
612
1037
  onReadInputRegisters?: (req: ReadInputRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
1038
+
1039
+ /**
1040
+ * Handle Write Single Coil (FC 05).
1041
+ * @param req The request object.
1042
+ * @param req.address The address of the coil to write (0x0000 to 0xFFFF).
1043
+ * @param req.value The boolean value to write (true for ON, false for OFF).
1044
+ * @returns void on success, or a ModbusException.
1045
+ */
613
1046
  onWriteSingleCoil?: (req: WriteSingleCoilRequest) => void | ModbusException | Promise<void | ModbusException>;
1047
+
1048
+ /**
1049
+ * Handle Write Single Register (FC 06).
1050
+ * @param req The request object.
1051
+ * @param req.address The address of the register to write (0x0000 to 0xFFFF).
1052
+ * @param req.value The 16-bit value to write.
1053
+ * @returns void on success, or a ModbusException.
1054
+ */
614
1055
  onWriteSingleRegister?: (req: WriteSingleRegisterRequest) => void | ModbusException | Promise<void | ModbusException>;
1056
+
1057
+ /**
1058
+ * Handle Read Exception Status (FC 07).
1059
+ * @param req The read exception status request object (empty).
1060
+ * @returns An 8-bit exception status byte, or a ModbusException.
1061
+ */
615
1062
  onReadExceptionStatus?: (req: ReadExceptionStatusRequest) => number | ModbusException | Promise<number | ModbusException>;
1063
+
1064
+ /**
1065
+ * Handle Diagnostics (FC 08).
1066
+ * @param req The diagnostics request object.
1067
+ * @param req.subFunction The 16-bit sub-function code.
1068
+ * @param req.data The 16-bit data payload for the sub-function.
1069
+ * @returns A response containing the sub-function and data, or a ModbusException.
1070
+ */
616
1071
  onDiagnostics?: (req: DiagnosticsRequest) => ServerDiagnosticsResponse | ModbusException | Promise<ServerDiagnosticsResponse | ModbusException>;
1072
+
1073
+ /**
1074
+ * Handle Write Multiple Coils (FC 15).
1075
+ * @param req The request object.
1076
+ * @param req.address The starting address of the coils to write.
1077
+ * @param req.values An array of booleans to write.
1078
+ * @returns void on success, or a ModbusException.
1079
+ */
617
1080
  onWriteMultipleCoils?: (req: WriteMultipleCoilsRequest) => void | ModbusException | Promise<void | ModbusException>;
1081
+
1082
+ /**
1083
+ * Handle Write Multiple Registers (FC 16).
1084
+ * @param req The request object.
1085
+ * @param req.address The starting address of the registers to write.
1086
+ * @param req.values An array of 16-bit numbers to write.
1087
+ * @returns void on success, or a ModbusException.
1088
+ */
618
1089
  onWriteMultipleRegisters?: (req: WriteMultipleRegistersRequest) => void | ModbusException | Promise<void | ModbusException>;
1090
+
1091
+ /**
1092
+ * Handle Read File Record (FC 20).
1093
+ * @param req The request object.
1094
+ * @param req.subRequests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordLength`.
1095
+ * @returns An array of register arrays for each sub-request, or a ModbusException.
1096
+ */
619
1097
  onReadFileRecord?: (req: ReadFileRecordRequest) => number[][] | ModbusException | Promise<number[][] | ModbusException>;
1098
+
1099
+ /**
1100
+ * Handle Write File Record (FC 21).
1101
+ * @param req The request object.
1102
+ * @param req.subRequests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordData` (a number array).
1103
+ * @returns void on success, or a ModbusException.
1104
+ */
620
1105
  onWriteFileRecord?: (req: WriteFileRecordRequest) => void | ModbusException | Promise<void | ModbusException>;
1106
+
1107
+ /**
1108
+ * Handle Read/Write Multiple Registers (FC 23).
1109
+ * @param req The request containing addresses and values to read and write.
1110
+ * @param req.readAddress The starting address for the read operation.
1111
+ * @param req.readQuantity The number of registers to read.
1112
+ * @param req.writeAddress The starting address for the write operation.
1113
+ * @param req.values An array of 16-bit numbers to write.
1114
+ * @returns An array of 16-bit numbers read, or a ModbusException.
1115
+ */
621
1116
  onReadWriteMultipleRegisters?: (req: ReadWriteMultipleRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
1117
+
1118
+ /**
1119
+ * Handle Read FIFO Queue (FC 24).
1120
+ * @param req The request object containing the FIFO pointer `address`.
1121
+ * @returns An array of 16-bit numbers from the queue, or a ModbusException.
1122
+ */
622
1123
  onReadFifoQueue?: (req: ReadFifoQueueRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
623
1124
  }
624
1125
 
1126
+ /**
1127
+ * Stable error codes for identifying Modbus-related errors.
1128
+ * These can be used with the `getModbusErrorCode` helper to check for specific error types.
1129
+ */
625
1130
  export declare const ModbusErrorCode: {
1131
+ /** A Modbus exception response was received from the server (e.g., illegal function). */
626
1132
  readonly EXCEPTION: 'MODBUS_EXCEPTION';
1133
+ /** The request timed out waiting for a response. */
627
1134
  readonly TIMEOUT: 'MODBUS_TIMEOUT';
1135
+ /** A transport-level error occurred (e.g., framing error, checksum mismatch). */
628
1136
  readonly TRANSPORT: 'MODBUS_TRANSPORT';
1137
+ /** An invalid argument was provided to a client or server function. */
629
1138
  readonly INVALID_ARGUMENT: 'MODBUS_INVALID_ARGUMENT';
1139
+ /** The underlying connection was closed. */
630
1140
  readonly CONNECTION_CLOSED: 'MODBUS_CONNECTION_CLOSED';
1141
+ /** An unexpected internal error occurred within the library. */
631
1142
  readonly INTERNAL: 'MODBUS_INTERNAL';
632
1143
  };
633
1144
 
1145
+ /**
1146
+ * Extracts a stable error code from a Modbus error object.
1147
+ * @param err The error object.
1148
+ * @returns The corresponding code from `ModbusErrorCode`, or undefined if not a Modbus error.
1149
+ */
634
1150
  export declare function getModbusErrorCode(err: Error): string | undefined;