modbus-rs 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +51 -33
  2. package/index.d.ts +120 -22
  3. package/index.js +75 -52
  4. package/package.json +8 -8
package/README.md CHANGED
@@ -5,10 +5,13 @@ High-performance Modbus TCP/RTU/ASCII client, server, and gateway for Node.js, p
5
5
  ## Features
6
6
 
7
7
  - **Async/Promise-based API** - All operations return Promises
8
- - **TCP Client** - Full Modbus TCP/IP client implementation
8
+ - **TCP Client** - Full Modbus TCP/IP client implementation (supports communicating with multiple unit IDs behind a single IP address and a serial port)
9
9
  - **Serial Client** - Modbus RTU and ASCII over serial port
10
- - **TCP Server** - Build Modbus TCP servers with JavaScript handlers
11
- - **TCP Gateway** - Route requests to multiple downstream servers based on unit ID
10
+ - **TCP & Serial Servers** - Build Modbus TCP servers, or Serial RTU and ASCII servers, using custom JavaScript handlers to respond to incoming requests
11
+ - **Modbus Gateway** - Deploy high-performance gateways supporting WebSockets, TCP, and Serial (RTU/ASCII) as upstream channels, and TCP/Serial (RTU/ASCII) as downstream channels (WebSocket downstream support planned for a future release), dynamically routing requests based on unit ID mapping tables
12
+ - **Thread Safety & Concurrency** - Rust-backed concurrent architecture ensures safe access across multiple async execution contexts
13
+ - **Safety Locks** - Integrated bus locking to prevent command collisions and state corruption
14
+ - **Multi-drop Serial Support** - Manage and communicate with multiple device unit IDs on a single physical RTU/ASCII bus
12
15
  - **High Performance** - Native Rust core with napi-rs bindings
13
16
  - **Type Safe** - Full TypeScript definitions included
14
17
  - **Cross Platform** - Pre-built binaries for Linux, macOS, and Windows
@@ -33,7 +36,7 @@ async function main() {
33
36
  const transport = await AsyncTcpTransport.connect({
34
37
  host: '127.0.0.1',
35
38
  port: 502,
36
- timeoutMs: 5000,
39
+ requestTimeoutMs: 5000,
37
40
  });
38
41
 
39
42
  const client = transport.createClient({ unitId: 1 });
@@ -96,8 +99,8 @@ const { AsyncTcpModbusServer } = require('modbus-rs');
96
99
 
97
100
  const holdingRegisters = new Array(1000).fill(0);
98
101
 
99
- function main() {
100
- const server = AsyncTcpModbusServer.bind(
102
+ async function main() {
103
+ const server = await AsyncTcpModbusServer.bind(
101
104
  { host: '0.0.0.0', port: 502, unitId: 1 },
102
105
  {
103
106
  onReadHoldingRegisters: (req) => {
@@ -117,11 +120,7 @@ function main() {
117
120
  });
118
121
  }
119
122
 
120
- try {
121
- main();
122
- } catch (err) {
123
- console.error(err);
124
- }
123
+ main().catch(console.error);
125
124
  ```
126
125
 
127
126
  ### TCP Gateway
@@ -155,6 +154,37 @@ async function main() {
155
154
  main().catch(console.error);
156
155
  ```
157
156
 
157
+ ## Migration Guide
158
+
159
+ Detailed step-by-step migration guides are available in the [Migration Guides](https://github.com/Raghava-Ch/modbus-rs/tree/main/documentation/migrations) directory.
160
+
161
+
162
+ ## Error Handling with Code Constants
163
+
164
+ Error code constants are now exported:
165
+
166
+ ```js
167
+ const { getModbusErrorCode, ModbusErrorCode } = require('modbus-rs');
168
+
169
+ try {
170
+ await client.readHoldingRegisters({ address: 0, quantity: 10 });
171
+ } catch (err) {
172
+ const code = getModbusErrorCode(err);
173
+ switch (code) {
174
+ case ModbusErrorCode.EXCEPTION: console.error('Modbus exception'); break;
175
+ case ModbusErrorCode.TIMEOUT: console.error('Request timed out'); break;
176
+ case ModbusErrorCode.CONNECTION_CLOSED: console.error('Disconnected'); break;
177
+ default: console.error('Unknown error:', err.message);
178
+ }
179
+ }
180
+ ```
181
+
182
+ ## Known Limitations
183
+
184
+ - **AbortSignal**: Uses `signal.onabort` instead of `signal.addEventListener`. Only one abort handler per signal object is supported.
185
+ - **Gateway route limit**: `AsyncTcpGateway` supports a maximum of **64 routing entries**. Attempting to add more will throw at `bind()` time.
186
+ - **Gateway Downstream**: WebSockets are currently not supported as a downstream channel (support is planned for a future release).
187
+
158
188
  ## API Reference
159
189
 
160
190
  ### AsyncTcpTransport
@@ -162,7 +192,7 @@ main().catch(console.error);
162
192
  - `static connect(opts: TcpTransportOptions): Promise<AsyncTcpTransport>` - Connect to a Modbus TCP server
163
193
  - `close(): Promise<void>` - Close the connection
164
194
  - `reconnect(): Promise<void>` - Re-establish the connection
165
- - `createClient(opts?: CreateClientOptions): AsyncTcpModbusClient` - Create a logical client instance bound to a specific unit ID (defaults to `1`)
195
+ - `createClient(opts: CreateClientOptions): AsyncTcpModbusClient` - Create a logical client instance bound to a specific unit ID (required)
166
196
  - `setRequestTimeout(ms: number): void` - Set a global request timeout (in milliseconds)
167
197
  - `clearRequestTimeout(): void` - Clear the global request timeout
168
198
  - `pendingRequests: boolean` - (Getter) Returns whether there are requests currently in flight
@@ -199,31 +229,19 @@ These logical clients contain all the Modbus function code methods:
199
229
 
200
230
  ### AsyncTcpModbusServer
201
231
 
202
- - `bind(opts, handlers)` - Create and start a TCP server
203
- - `shutdown()` - Stop the server
204
-
205
- ### AsyncTcpGateway
232
+ - `static bind(opts, handlers): Promise<AsyncTcpModbusServer>` - Create and start a TCP server
233
+ - `shutdown(): Promise<void>` - Stop the server
206
234
 
207
- - `bind(opts, config)` - Create and start a gateway
208
- - `shutdown()` - Stop the gateway
235
+ ### AsyncSerialModbusServer
209
236
 
210
- ## Error Handling
237
+ - `static bindRtu(opts, handlers): Promise<AsyncSerialModbusServer>` - Create and start a Serial RTU server
238
+ - `static bindAscii(opts, handlers): Promise<AsyncSerialModbusServer>` - Create and start a Serial ASCII server
239
+ - `shutdown(): Promise<void>` - Stop the server
211
240
 
212
- All errors are thrown as JavaScript Error objects with descriptive messages:
241
+ ### AsyncTcpGateway
213
242
 
214
- ```javascript
215
- try {
216
- await client.readHoldingRegisters({ address: 0, quantity: 10 });
217
- } catch (err) {
218
- if (err.message.includes('MODBUS_EXCEPTION')) {
219
- console.error('Modbus exception:', err.message);
220
- } else if (err.message.includes('MODBUS_TIMEOUT')) {
221
- console.error('Request timed out');
222
- } else {
223
- console.error('Error:', err.message);
224
- }
225
- }
226
- ```
243
+ - `static bind(opts, config): Promise<AsyncTcpGateway>` - Create and start a gateway
244
+ - `shutdown(): Promise<void>` - Stop the gateway
227
245
 
228
246
  ## Supported platforms
229
247
 
package/index.d.ts CHANGED
@@ -72,10 +72,8 @@ export declare class AsyncSerialModbusClient {
72
72
 
73
73
  /** Async Modbus Serial server supporting RTU and ASCII transports. */
74
74
  export declare class AsyncSerialModbusServer {
75
- /** Binds and starts a new Serial RTU server. */
76
- static bindRtu(opts: SerialServerOptions, handlers: object): AsyncSerialModbusServer
77
- /** Binds and starts a new Serial ASCII server. */
78
- static bindAscii(opts: SerialServerOptions, handlers: object): AsyncSerialModbusServer
75
+ static bindRtu(opts: SerialServerOptions, handlers: ServerHandlers): Promise<AsyncSerialModbusServer>
76
+ static bindAscii(opts: SerialServerOptions, handlers: ServerHandlers): Promise<AsyncSerialModbusServer>
79
77
  /** Stops the server. */
80
78
  shutdown(): Promise<void>
81
79
  }
@@ -145,7 +143,7 @@ export declare class AsyncTcpModbusServer {
145
143
  * @param handlers - Object containing handler functions for each Modbus operation.
146
144
  * @returns A running server instance.
147
145
  */
148
- static bind(opts: TcpServerOptions, handlers: object): AsyncTcpModbusServer
146
+ static bind(opts: TcpServerOptions, handlers: ServerHandlers): Promise<AsyncTcpModbusServer>
149
147
  /** Stops the server. */
150
148
  shutdown(): Promise<void>
151
149
  }
@@ -155,7 +153,7 @@ export declare class AsyncTcpTransport {
155
153
  /** Connects to a Modbus TCP device or gateway. */
156
154
  static connect(opts: TcpTransportOptions): Promise<AsyncTcpTransport>
157
155
  /** Creates a device client bound to the specified unit ID. */
158
- createClient(opts?: CreateClientOptions | undefined | null): AsyncTcpModbusClient
156
+ createClient(opts: CreateClientOptions): AsyncTcpModbusClient
159
157
  /** Sets the per-request timeout in milliseconds. */
160
158
  setRequestTimeout(timeoutMs: number): void
161
159
  /** Clears the per-request timeout. */
@@ -184,12 +182,16 @@ export interface AsciiTransportOptions {
184
182
  responseTimeoutMs?: number
185
183
  /** Per-request timeout in milliseconds. */
186
184
  requestTimeoutMs?: number
185
+ /** Number of retry attempts on failure (0 = none). Default: 0. */
186
+ retryAttempts?: number
187
+ /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
188
+ retryBackoffStrategy?: string
187
189
  }
188
190
 
189
191
  /** Options for creating a device client. */
190
192
  export interface CreateClientOptions {
191
193
  /** Modbus unit ID (1-247). */
192
- unitId?: number
194
+ unitId: number
193
195
  }
194
196
 
195
197
  /** Device identification object. */
@@ -219,7 +221,7 @@ export interface DiagnosticsOptions {
219
221
  /** Data words for the request. */
220
222
  data: Array<number>
221
223
  /** Optional abort signal to cancel the request. */
222
- signal?: object
224
+ signal?: AbortSignal
223
225
  }
224
226
 
225
227
  /** Handler request for diagnostics. */
@@ -247,8 +249,6 @@ export interface DownstreamConfig {
247
249
 
248
250
  /** Response from reading FIFO queue. */
249
251
  export interface FifoQueueResponse {
250
- /** Number of values in the queue. */
251
- count: number
252
252
  /** Queue values. */
253
253
  values: Array<number>
254
254
  }
@@ -263,6 +263,13 @@ export interface FileRecordReadRequest {
263
263
  recordLength: number
264
264
  }
265
265
 
266
+ /** A single file record read sub-request on the server side. */
267
+ export interface FileRecordReadServerSubRequest {
268
+ fileNumber: number
269
+ recordNumber: number
270
+ recordLength: number
271
+ }
272
+
266
273
  /** A single file record write sub-request. */
267
274
  export interface FileRecordWriteRequest {
268
275
  /** File number (1-65535). */
@@ -273,6 +280,13 @@ export interface FileRecordWriteRequest {
273
280
  recordData: Array<number>
274
281
  }
275
282
 
283
+ /** A single file record write sub-request on the server side. */
284
+ export interface FileRecordWriteSubRequest {
285
+ fileNumber: number
286
+ recordNumber: number
287
+ recordData: Array<number>
288
+ }
289
+
276
290
  /** Gateway bind options. */
277
291
  export interface GatewayBindOptions {
278
292
  /** Bind host address (e.g., "0.0.0.0"). */
@@ -289,6 +303,24 @@ export interface GatewayConfig {
289
303
  routes: Array<RouteEntry>
290
304
  }
291
305
 
306
+ /** Stable error code: The connection was closed. */
307
+ export const MODBUS_ERROR_CODE_CONNECTION_CLOSED: string
308
+
309
+ /** Stable error code: Modbus protocol exception received. */
310
+ export const MODBUS_ERROR_CODE_EXCEPTION: string
311
+
312
+ /** Stable error code: Internal library error. */
313
+ export const MODBUS_ERROR_CODE_INTERNAL: string
314
+
315
+ /** Stable error code: Invalid argument passed to the API. */
316
+ export const MODBUS_ERROR_CODE_INVALID_ARGUMENT: string
317
+
318
+ /** Stable error code: Request timed out. */
319
+ export const MODBUS_ERROR_CODE_TIMEOUT: string
320
+
321
+ /** Stable error code: Transport/framing error. */
322
+ export const MODBUS_ERROR_CODE_TRANSPORT: string
323
+
292
324
  /** Options for reading coils or discrete inputs. */
293
325
  export interface ReadBitsOptions {
294
326
  /** Starting address. */
@@ -296,7 +328,7 @@ export interface ReadBitsOptions {
296
328
  /** Number of bits to read. */
297
329
  quantity: number
298
330
  /** Optional abort signal to cancel the request. */
299
- signal?: object
331
+ signal?: AbortSignal
300
332
  }
301
333
 
302
334
  /** Handler request for reading coils. */
@@ -313,7 +345,7 @@ export interface ReadDeviceIdentificationOptions {
313
345
  /** Starting object ID. */
314
346
  objectId: number
315
347
  /** Optional abort signal to cancel the request. */
316
- signal?: object
348
+ signal?: AbortSignal
317
349
  }
318
350
 
319
351
  /** Handler request for reading discrete inputs. */
@@ -323,12 +355,17 @@ export interface ReadDiscreteInputsRequest {
323
355
  quantity: number
324
356
  }
325
357
 
358
+ /** Handler request for reading exception status. */
359
+ export interface ReadExceptionStatusRequest {
360
+ unitId: number
361
+ }
362
+
326
363
  /** Options for reading FIFO queue. */
327
364
  export interface ReadFifoQueueOptions {
328
365
  /** FIFO pointer address. */
329
366
  address: number
330
367
  /** Optional abort signal to cancel the request. */
331
- signal?: object
368
+ signal?: AbortSignal
332
369
  }
333
370
 
334
371
  /** Handler request for reading FIFO queue. */
@@ -342,7 +379,13 @@ export interface ReadFileRecordOptions {
342
379
  /** Array of sub-requests. */
343
380
  requests: Array<FileRecordReadRequest>
344
381
  /** Optional abort signal to cancel the request. */
345
- signal?: object
382
+ signal?: AbortSignal
383
+ }
384
+
385
+ /** Handler request for reading file records. */
386
+ export interface ReadFileRecordRequest {
387
+ unitId: number
388
+ requests: Array<FileRecordReadServerSubRequest>
346
389
  }
347
390
 
348
391
  /** Handler request for reading holding registers. */
@@ -366,7 +409,7 @@ export interface ReadRegistersOptions {
366
409
  /** Number of registers to read. */
367
410
  quantity: number
368
411
  /** Optional abort signal to cancel the request. */
369
- signal?: object
412
+ signal?: AbortSignal
370
413
  }
371
414
 
372
415
  /** Options for read/write multiple registers (FC23). */
@@ -380,7 +423,16 @@ export interface ReadWriteMultipleRegistersOptions {
380
423
  /** Values to write. */
381
424
  writeValues: Array<number>
382
425
  /** Optional abort signal to cancel the request. */
383
- signal?: object
426
+ signal?: AbortSignal
427
+ }
428
+
429
+ /** Handler request for read/write multiple registers (FC23). */
430
+ export interface ReadWriteMultipleRegistersRequest {
431
+ unitId: number
432
+ readAddress: number
433
+ readQuantity: number
434
+ writeAddress: number
435
+ writeValues: Array<number>
384
436
  }
385
437
 
386
438
  /** Route entry mapping unit ID to a downstream channel. */
@@ -407,6 +459,10 @@ export interface RtuTransportOptions {
407
459
  responseTimeoutMs?: number
408
460
  /** Per-request timeout in milliseconds. */
409
461
  requestTimeoutMs?: number
462
+ /** Number of retry attempts on failure (0 = none). Default: 0. */
463
+ retryAttempts?: number
464
+ /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
465
+ retryBackoffStrategy?: string
410
466
  }
411
467
 
412
468
  /** Server bind options for serial port. */
@@ -456,7 +512,11 @@ export interface TcpTransportOptions {
456
512
  /** Target TCP port (typically 502). */
457
513
  port: number
458
514
  /** Per-request timeout in milliseconds (optional). */
459
- timeoutMs?: number
515
+ requestTimeoutMs?: number
516
+ /** Number of retry attempts on failure (0 = none). Default: 0. */
517
+ retryAttempts?: number
518
+ /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". */
519
+ retryBackoffStrategy?: string
460
520
  }
461
521
 
462
522
  /** Options for writing file records. */
@@ -464,7 +524,13 @@ export interface WriteFileRecordOptions {
464
524
  /** Array of sub-requests. */
465
525
  requests: Array<FileRecordWriteRequest>
466
526
  /** Optional abort signal to cancel the request. */
467
- signal?: object
527
+ signal?: AbortSignal
528
+ }
529
+
530
+ /** Handler request for writing file records. */
531
+ export interface WriteFileRecordRequest {
532
+ unitId: number
533
+ requests: Array<FileRecordWriteSubRequest>
468
534
  }
469
535
 
470
536
  /** Options for writing multiple coils. */
@@ -474,7 +540,7 @@ export interface WriteMultipleCoilsOptions {
474
540
  /** Values to write. */
475
541
  values: Array<boolean>
476
542
  /** Optional abort signal to cancel the request. */
477
- signal?: object
543
+ signal?: AbortSignal
478
544
  }
479
545
 
480
546
  /** Handler request for writing multiple coils. */
@@ -491,7 +557,7 @@ export interface WriteMultipleRegistersOptions {
491
557
  /** Values to write. */
492
558
  values: Array<number>
493
559
  /** Optional abort signal to cancel the request. */
494
- signal?: object
560
+ signal?: AbortSignal
495
561
  }
496
562
 
497
563
  /** Handler request for writing multiple registers. */
@@ -508,7 +574,7 @@ export interface WriteSingleCoilOptions {
508
574
  /** Value to write. */
509
575
  value: boolean
510
576
  /** Optional abort signal to cancel the request. */
511
- signal?: object
577
+ signal?: AbortSignal
512
578
  }
513
579
 
514
580
  /** Handler request for writing a single coil. */
@@ -525,7 +591,7 @@ export interface WriteSingleRegisterOptions {
525
591
  /** Value to write. */
526
592
  value: number
527
593
  /** Optional abort signal to cancel the request. */
528
- signal?: object
594
+ signal?: AbortSignal
529
595
  }
530
596
 
531
597
  /** Handler request for writing a single register. */
@@ -534,3 +600,35 @@ export interface WriteSingleRegisterRequest {
534
600
  address: number
535
601
  value: number
536
602
  }
603
+
604
+ export interface ModbusException {
605
+ exception: number;
606
+ }
607
+
608
+ export interface ServerHandlers {
609
+ onReadCoils?: (req: ReadCoilsRequest) => boolean[] | ModbusException | Promise<boolean[] | ModbusException>;
610
+ onReadDiscreteInputs?: (req: ReadDiscreteInputsRequest) => boolean[] | ModbusException | Promise<boolean[] | ModbusException>;
611
+ onReadHoldingRegisters?: (req: ReadHoldingRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
612
+ onReadInputRegisters?: (req: ReadInputRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
613
+ onWriteSingleCoil?: (req: WriteSingleCoilRequest) => void | ModbusException | Promise<void | ModbusException>;
614
+ onWriteSingleRegister?: (req: WriteSingleRegisterRequest) => void | ModbusException | Promise<void | ModbusException>;
615
+ onReadExceptionStatus?: (req: ReadExceptionStatusRequest) => number | ModbusException | Promise<number | ModbusException>;
616
+ onDiagnostics?: (req: DiagnosticsRequest) => ServerDiagnosticsResponse | ModbusException | Promise<ServerDiagnosticsResponse | ModbusException>;
617
+ onWriteMultipleCoils?: (req: WriteMultipleCoilsRequest) => void | ModbusException | Promise<void | ModbusException>;
618
+ onWriteMultipleRegisters?: (req: WriteMultipleRegistersRequest) => void | ModbusException | Promise<void | ModbusException>;
619
+ onReadFileRecord?: (req: ReadFileRecordRequest) => number[][] | ModbusException | Promise<number[][] | ModbusException>;
620
+ onWriteFileRecord?: (req: WriteFileRecordRequest) => void | ModbusException | Promise<void | ModbusException>;
621
+ onReadWriteMultipleRegisters?: (req: ReadWriteMultipleRegistersRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
622
+ onReadFifoQueue?: (req: ReadFifoQueueRequest) => number[] | ModbusException | Promise<number[] | ModbusException>;
623
+ }
624
+
625
+ export declare const ModbusErrorCode: {
626
+ readonly EXCEPTION: 'MODBUS_EXCEPTION';
627
+ readonly TIMEOUT: 'MODBUS_TIMEOUT';
628
+ readonly TRANSPORT: 'MODBUS_TRANSPORT';
629
+ readonly INVALID_ARGUMENT: 'MODBUS_INVALID_ARGUMENT';
630
+ readonly CONNECTION_CLOSED: 'MODBUS_CONNECTION_CLOSED';
631
+ readonly INTERNAL: 'MODBUS_INTERNAL';
632
+ };
633
+
634
+ export declare function getModbusErrorCode(err: Error): string | undefined;
package/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('modbus-rs-android-arm64')
79
79
  const bindingPackageVersion = require('modbus-rs-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('modbus-rs-android-arm-eabi')
95
95
  const bindingPackageVersion = require('modbus-rs-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('modbus-rs-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('modbus-rs-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('modbus-rs-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('modbus-rs-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('modbus-rs-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('modbus-rs-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('modbus-rs-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('modbus-rs-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('modbus-rs-darwin-universal')
184
184
  const bindingPackageVersion = require('modbus-rs-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('modbus-rs-darwin-x64')
200
200
  const bindingPackageVersion = require('modbus-rs-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('modbus-rs-darwin-arm64')
216
216
  const bindingPackageVersion = require('modbus-rs-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('modbus-rs-freebsd-x64')
236
236
  const bindingPackageVersion = require('modbus-rs-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('modbus-rs-freebsd-arm64')
252
252
  const bindingPackageVersion = require('modbus-rs-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('modbus-rs-linux-x64-musl')
273
273
  const bindingPackageVersion = require('modbus-rs-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('modbus-rs-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('modbus-rs-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('modbus-rs-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('modbus-rs-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('modbus-rs-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('modbus-rs-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('modbus-rs-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('modbus-rs-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('modbus-rs-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('modbus-rs-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('modbus-rs-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('modbus-rs-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('modbus-rs-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('modbus-rs-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('modbus-rs-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('modbus-rs-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('modbus-rs-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('modbus-rs-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('modbus-rs-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('modbus-rs-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('modbus-rs-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('modbus-rs-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('modbus-rs-openharmony-arm64')
478
478
  const bindingPackageVersion = require('modbus-rs-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('modbus-rs-openharmony-x64')
494
494
  const bindingPackageVersion = require('modbus-rs-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('modbus-rs-openharmony-arm')
510
510
  const bindingPackageVersion = require('modbus-rs-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '0.14.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 0.14.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -584,3 +584,26 @@ module.exports.AsyncTcpGateway = nativeBinding.AsyncTcpGateway
584
584
  module.exports.AsyncTcpModbusClient = nativeBinding.AsyncTcpModbusClient
585
585
  module.exports.AsyncTcpModbusServer = nativeBinding.AsyncTcpModbusServer
586
586
  module.exports.AsyncTcpTransport = nativeBinding.AsyncTcpTransport
587
+ module.exports.MODBUS_ERROR_CODE_CONNECTION_CLOSED = nativeBinding.MODBUS_ERROR_CODE_CONNECTION_CLOSED
588
+ module.exports.MODBUS_ERROR_CODE_EXCEPTION = nativeBinding.MODBUS_ERROR_CODE_EXCEPTION
589
+ module.exports.MODBUS_ERROR_CODE_INTERNAL = nativeBinding.MODBUS_ERROR_CODE_INTERNAL
590
+ module.exports.MODBUS_ERROR_CODE_INVALID_ARGUMENT = nativeBinding.MODBUS_ERROR_CODE_INVALID_ARGUMENT
591
+ module.exports.MODBUS_ERROR_CODE_TIMEOUT = nativeBinding.MODBUS_ERROR_CODE_TIMEOUT
592
+ module.exports.MODBUS_ERROR_CODE_TRANSPORT = nativeBinding.MODBUS_ERROR_CODE_TRANSPORT
593
+
594
+ // Error code constants
595
+ module.exports.ModbusErrorCode = {
596
+ EXCEPTION: 'MODBUS_EXCEPTION',
597
+ TIMEOUT: 'MODBUS_TIMEOUT',
598
+ TRANSPORT: 'MODBUS_TRANSPORT',
599
+ INVALID_ARGUMENT: 'MODBUS_INVALID_ARGUMENT',
600
+ CONNECTION_CLOSED: 'MODBUS_CONNECTION_CLOSED',
601
+ INTERNAL: 'MODBUS_INTERNAL',
602
+ }
603
+
604
+ // Helper to extract the code from a Modbus error message
605
+ module.exports.getModbusErrorCode = function getModbusErrorCode(err) {
606
+ if (!err || typeof err.message !== 'string') return undefined
607
+ const m = err.message.match(/^\[([A-Z_]+)(?::[^\]]*)?\]/)
608
+ return m ? m[1] : undefined
609
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modbus-rs",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "High-performance Modbus TCP/RTU/ASCII client, server and gateway for Node.js, powered by Rust",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,8 +8,8 @@
8
8
  ".": "./index.js"
9
9
  },
10
10
  "scripts": {
11
- "build": "napi build --platform --release --features nodejs,full --js index.js --dts index.d.ts --output-dir . --manifest-path ../Cargo.toml",
12
- "build:debug": "napi build --platform --features nodejs,full --js index.js --dts index.d.ts --output-dir . --manifest-path ../Cargo.toml",
11
+ "build": "napi build --platform --release --features nodejs-full --js index.js --dts index.d.ts --output-dir . --manifest-path ../Cargo.toml && node scripts/postbuild.js",
12
+ "build:debug": "napi build --platform --features nodejs-full --js index.js --dts index.d.ts --output-dir . --manifest-path ../Cargo.toml && node scripts/postbuild.js",
13
13
  "test": "node --test __test__/*.test.mjs",
14
14
  "prepublishOnly": "napi prepublish -t npm",
15
15
  "artifacts": "napi artifacts",
@@ -64,10 +64,10 @@
64
64
  ],
65
65
  "dependencies": {},
66
66
  "optionalDependencies": {
67
- "modbus-rs-win32-x64-msvc": "0.14.0",
68
- "modbus-rs-linux-x64-gnu": "0.14.0",
69
- "modbus-rs-darwin-x64": "0.14.0",
70
- "modbus-rs-darwin-arm64": "0.14.0",
71
- "modbus-rs-linux-arm64-gnu": "0.14.0"
67
+ "modbus-rs-win32-x64-msvc": "0.15.0",
68
+ "modbus-rs-linux-x64-gnu": "0.15.0",
69
+ "modbus-rs-darwin-x64": "0.15.0",
70
+ "modbus-rs-darwin-arm64": "0.15.0",
71
+ "modbus-rs-linux-arm64-gnu": "0.15.0"
72
72
  }
73
73
  }