/* auto-generated by NAPI-RS */ /* eslint-disable */ /** * Physical serial port in ASCII mode. Factory for device clients. * Manages a physical serial port connection in ASCII mode. * This class is a factory for creating lightweight `AsyncSerialModbusClient` instances * that are bound to a specific unit ID and share the underlying serial connection. * * Use the static `open` method to establish a connection. */ export declare class AsyncAsciiTransport { /** * Opens the serial port in ASCII mode. * Opens a serial port and establishes a connection in ASCII mode. * @param options Options for the serial ASCII transport. * @param options.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3'). * @param options.baudRate The baud rate for the serial communication. * @returns A `Promise` that resolves to an `AsyncAsciiTransport` instance. */ static open(options: AsciiTransportOptions): Promise; /** * Creates a device client bound to the specified unit ID. * Creates a lightweight device client that communicates through this transport. * The client is bound to a specific Modbus unit ID. * @param options Options specifying the unit ID. */ createClient(options: CreateClientOptions): AsyncSerialModbusClient; /** * Sets the per-request timeout in milliseconds. * * Sets the timeout for individual Modbus requests made through this transport. * On multi-drop buses, a timeout on a silent unit does not disconnect or close the transport. * * Note: This feature is effective, but based on ongoing RFC discussions it might be * removed or revised in a future release. If you feel this is a mandatory feature for your use case, * it is suggested to leave a comment on the GitHub RFC discussion. * * @param timeout_ms The timeout duration in milliseconds. */ setRequestTimeout(timeoutMs: number): void; /** * Clears the per-request timeout. * * Clears any previously set per-request timeout, allowing requests to wait without a timeout. */ clearRequestTimeout(): void; /** * Returns whether there are pending requests. * Checks if there are any Modbus requests currently in-flight on this transport. */ readonly pendingRequests: boolean; /** * Closes the transport. * Closes the underlying serial port connection. */ close(): Promise; /** * Reconnects the transport after a disconnect. * Attempts to re-establish the serial connection if it has been closed. */ reconnect(): Promise; } /** * Physical serial port in RTU mode. Factory for device clients. * Manages a physical serial port connection in RTU mode. * This class is a factory for creating lightweight `AsyncSerialModbusClient` instances * that are bound to a specific unit ID and share the underlying serial connection. * * Use the static `open` method to establish a connection. */ export declare class AsyncRtuTransport { /** * Opens the serial port in RTU mode. * Opens a serial port and establishes a connection in RTU mode. * @param options Options for the serial RTU transport. * @param options.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3'). * @param options.baudRate The baud rate for the serial communication. * @returns A `Promise` that resolves to an `AsyncRtuTransport` instance. */ static open(options: RtuTransportOptions): Promise; /** * Creates a device client bound to the specified unit ID. * Creates a lightweight device client that communicates through this transport. * The client is bound to a specific Modbus unit ID. * @param options Options specifying the unit ID. */ createClient(options: CreateClientOptions): AsyncSerialModbusClient; /** * Sets the per-request timeout in milliseconds. * * Sets the timeout for individual Modbus requests made through this transport. * On multi-drop buses, a timeout on a silent unit does not disconnect or close the transport. * * Note: This feature is effective, but based on ongoing RFC discussions it might be * removed or revised in a future release. If you feel this is a mandatory feature for your use case, * it is suggested to leave a comment on the GitHub RFC discussion. * * @param timeout_ms The timeout duration in milliseconds. */ setRequestTimeout(timeoutMs: number): void; /** * Clears the per-request timeout. * * Clears any previously set per-request timeout, allowing requests to wait without a timeout. */ clearRequestTimeout(): void; /** * Returns whether there are pending requests. * Checks if there are any Modbus requests currently in-flight on this transport. */ readonly pendingRequests: boolean; /** * Closes the transport. * Closes the underlying serial port connection. */ close(): Promise; /** * Reconnects the transport after a disconnect. * Attempts to re-establish the serial connection if it has been closed. */ reconnect(): Promise; } /** * Lightweight device client sharing the serial transport. * A lightweight Modbus client that sends requests for a specific unit ID * over a shared `AsyncRtuTransport` or `AsyncAsciiTransport`. */ export declare class AsyncSerialModbusClient { /** * Returns whether there are pending requests. * Checks if there are any Modbus requests currently in-flight for this client. */ readonly pendingRequests: boolean; /** * Checks if the client is connected to the transport. * Checks if the underlying client transport connection is active. */ isConnected(): boolean; /** * Reads holding registers (FC03). * Reads one or more holding registers (Function Code 03). * @param options Options for reading registers. * @param options.address The starting register address. * @param options.quantity The number of registers to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readHoldingRegisters(options: ReadRegistersOptions): Promise; /** * Reads input registers (FC04). * Reads one or more input registers (Function Code 04). * @param options Options for reading registers. * @param options.address The starting register address. * @param options.quantity The number of registers to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readInputRegisters(options: ReadRegistersOptions): Promise; /** * Writes a single register (FC06). * Writes a single holding register (Function Code 06). * @param options Options for writing a single register. * @param options.address The register address. * @param options.value The 16-bit value to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeSingleRegister(options: WriteSingleRegisterOptions): Promise; /** * Writes multiple registers (FC16). * Writes multiple consecutive holding registers (Function Code 16). * @param options Options for writing multiple registers. * @param options.address The starting register address. * @param options.values An array of 16-bit values to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeMultipleRegisters(options: WriteMultipleRegistersOptions): Promise; /** * Reads and writes multiple registers atomically (FC23). * Performs an atomic read/write operation on multiple registers (Function Code 23). * @param options Options for the read/write operation. * @param options.read_address The starting address for the read operation. * @param options.read_quantity The number of registers to read. * @param options.write_address The starting address for the write operation. * @param options.write_values An array of 16-bit values to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readWriteMultipleRegisters(options: ReadWriteMultipleRegistersOptions): Promise; /** * Reads coils (FC01). * Reads the status of one or more coils (Function Code 01). * @param {ReadBitsOptions} options - Options for reading bits. * @param {number} options.address - The starting coil address. * @param {number} options.quantity - The number of coils to read. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {Promise} - A promise that resolves to an array representing the coil states. * * @example * ```javascript * const coils = await client.readCoils({ address: 0, quantity: 8 }); * console.log(coils); // e.g., [CoilState.On, CoilState.Off, ...] * ``` */ readCoils(options: ReadBitsOptions): Promise; /** * Writes a single coil (FC05). * Writes a single coil (Function Code 05). * @param {WriteSingleCoilOptions} options - Options for writing a single coil. * @param {number} options.address - The coil address. * @param {CoilState} options.value - The coil state to write. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {`Promise`} - A promise that resolves when the write is complete. * * @example * ```javascript * await client.writeSingleCoil({ address: 10, value: CoilState.On }); * ``` */ writeSingleCoil(options: WriteSingleCoilOptions): Promise; /** * Writes multiple coils (FC15). * Writes multiple consecutive coils (Function Code 15). * @param {WriteMultipleCoilsOptions} options - Options for writing multiple coils. * @param {number} options.address - The starting coil address. * @param {CoilState[]} options.values - An array of coil states to write. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {`Promise`} - A promise that resolves when the write is complete. * * @example * ```javascript * await client.writeMultipleCoils({ address: 20, values: [CoilState.On, CoilState.Off] }); * ``` */ writeMultipleCoils(options: WriteMultipleCoilsOptions): Promise; /** * Reads discrete inputs (FC02). * Reads the status of one or more discrete inputs (Function Code 02). * @param {ReadBitsOptions} options - Options for reading bits. * @param {number} options.address - The starting discrete input address. * @param {number} options.quantity - The number of discrete inputs to read. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {Promise} - A promise that resolves to an array of states. * * @example * ```javascript * const inputs = await client.readDiscreteInputs({ address: 0, quantity: 4 }); * ``` */ readDiscreteInputs(options: ReadBitsOptions): Promise; /** * Reads FIFO queue (FC24). * Reads from a FIFO queue register (Function Code 24). * @param options Options for reading the FIFO queue. * @param options.address The FIFO pointer address. * @param options.signal An optional `AbortSignal` to cancel the operation. * * @example * ```javascript * const fifoContents = await client.readFifoQueue({ address: 42 }); * ``` */ readFifoQueue(options: ReadFifoQueueOptions): Promise; /** * Reads file records (FC20). * Reads one or more file records (Function Code 20). * @param options Options for reading file records. * @param options.requests An array of file record read sub-requests. * @param options.signal An optional `AbortSignal` to cancel the operation. * * @example * ```javascript * const records = await client.readFileRecord({ * requests: [ * { fileNumber: 4, recordNumber: 1, recordLength: 2 } * ] * }); * ``` */ readFileRecord(options: ReadFileRecordOptions): Promise; /** * Writes file records (FC21). * Writes one or more file records (Function Code 21). * @param options Options for writing file records. * @param options.requests An array of file record write sub-requests. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeFileRecord(options: WriteFileRecordOptions): Promise; /** * Reads exception status (FC07). * Reads the device's exception status byte (Function Code 07). */ readExceptionStatus(): Promise; /** * Sends a diagnostics request (FC08). * Executes a diagnostic function on the device (Function Code 08). * @param options Options for the diagnostics request. * @param options.sub_function The diagnostic sub-function code. * @param options.data Data to be sent with the request. * @param options.signal An optional `AbortSignal` to cancel the operation. */ diagnostics(options: DiagnosticsOptions): Promise; /** * Reads device identification (FC43/MEI14). * Reads device identification information (Function Code 43, MEI 14). * @param options Options for reading device identification. * @param options.read_device_id_code The category of objects to read (e.g., basic, regular). * @param options.object_id The ID of the first object to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readDeviceIdentification(options: ReadDeviceIdentificationOptions): Promise; } /** * Async Modbus Serial server supporting RTU and ASCII transports. * An asynchronous Modbus server that listens on a serial port for incoming requests. * It supports both RTU and ASCII transport modes. * Use the static `bindRtu` or `bindAscii` methods to create and start a server instance. */ export declare class AsyncSerialModbusServer { /** * Creates and starts a new Modbus RTU server on a serial port. * * @param {SerialServerOptions} options Server configuration options. * @param {string} options.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3'). * @param {number} options.baudRate The communication speed (e.g., 9600, 19200). * @param {number} options.unitId The Modbus unit ID the server will respond to. * @param {number} [options.dataBits] Optional number of data bits (5, 6, 7, or 8). Defaults to 8. * @param {string} [options.parity] Optional parity setting ('none', 'even', 'odd'). Defaults to 'none'. * @param {number} [options.stopBits] Optional number of stop bits (1 or 2). Defaults to 1. * @param {number} [options.responseTimeoutMs] Optional response timeout in milliseconds. Defaults to 1000. * * @param {ServerHandlers} handlers An object containing callback functions to handle Modbus requests. * @returns {`Promise`} A `Promise` that resolves to a running `AsyncSerialModbusServer` instance. */ static bindRtu(options: SerialServerOptions, handlers: ServerHandlers): Promise; /** * Creates and starts a new Modbus ASCII server on a serial port. * * @param {SerialServerOptions} options Server configuration options. * @param {string} options.portPath The path to the serial port (e.g., '/dev/ttyUSB0', 'COM3'). * @param {number} options.baudRate The communication speed (e.g., 9600, 19200). * @param {number} options.unitId The Modbus unit ID the server will respond to. * @param {number} [options.dataBits] Optional number of data bits (7 or 8). Defaults to 8. * @param {string} [options.parity] Optional parity setting ('none', 'even', 'odd'). Defaults to 'none'. * @param {number} [options.stopBits] Optional number of stop bits (1 or 2). Defaults to 1. * @param {number} [options.responseTimeoutMs] Optional response timeout in milliseconds. Defaults to 1000. * * @param {ServerHandlers} handlers An object containing callback functions to handle Modbus requests. * @returns {`Promise`} A `Promise` that resolves to a running `AsyncSerialModbusServer` instance. */ static bindAscii(options: SerialServerOptions, handlers: ServerHandlers): Promise; /** * Stops the server. * Stops the server and closes the serial port. */ shutdown(): Promise; } /** * Async Modbus TCP gateway. * * Forwards incoming Modbus requests to downstream servers based on unit ID routing. */ export declare class AsyncTcpGateway { /** * Creates and starts a new TCP gateway. * * @param {GatewayBindOptions} options - Gateway bind options. * @param {string} options.host - Bind host address (e.g., "0.0.0.0"). * @param {number} options.port - Bind port. * * @param {GatewayConfig} config - Gateway configuration including downstreams and routes. * @param {DownstreamConfig[]} config.downstreams - List of downstream servers. * @param {RouteEntry[]} config.routes - Routing table mapping unit IDs to downstream channels. * @returns {`Promise`} A promise that resolves to the running gateway instance. */ static bind(options: GatewayBindOptions, config: GatewayConfig): Promise; /** Stops the gateway. */ shutdown(): Promise; } /** * Lightweight device client sharing the TCP transport. * A lightweight Modbus client that sends requests for a specific unit ID * over a shared `AsyncTcpTransport`. */ export declare class AsyncTcpModbusClient { /** * Returns whether there are pending requests. * Checks if there are any Modbus requests currently in-flight for this client. */ readonly pendingRequests: boolean; /** * Checks if the client is connected to the server. * Checks if the underlying client transport connection is active. */ isConnected(): boolean; /** * Reads holding registers (FC03). * Reads one or more holding registers (Function Code 03). * @param options Options for reading registers. * @param options.address The starting register address. * @param options.quantity The number of registers to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readHoldingRegisters(options: ReadRegistersOptions): Promise; /** * Reads input registers (FC04). * Reads one or more input registers (Function Code 04). * @param options Options for reading registers. * @param options.address The starting register address. * @param options.quantity The number of registers to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readInputRegisters(options: ReadRegistersOptions): Promise; /** * Writes a single register (FC06). * Writes a single holding register (Function Code 06). * @param options Options for writing a single register. * @param options.address The register address. * @param options.value The 16-bit value to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeSingleRegister(options: WriteSingleRegisterOptions): Promise; /** * Writes multiple registers (FC16). * Writes multiple consecutive holding registers (Function Code 16). * @param options Options for writing multiple registers. * @param options.address The starting register address. * @param options.values An array of 16-bit values to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeMultipleRegisters(options: WriteMultipleRegistersOptions): Promise; /** * Reads and writes multiple registers atomically (FC23). * Performs an atomic read/write operation on multiple registers (Function Code 23). * @param options Options for the read/write operation. * @param options.read_address The starting address for the read operation. * @param options.read_quantity The number of registers to read. * @param options.write_address The starting address for the write operation. * @param options.write_values An array of 16-bit values to write. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readWriteMultipleRegisters(options: ReadWriteMultipleRegistersOptions): Promise; /** * Reads coils (FC01). * Reads the status of one or more coils (Function Code 01). * @param {ReadBitsOptions} options - Options for reading bits. * @param {number} options.address - The starting coil address. * @param {number} options.quantity - The number of coils to read. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {Promise} - A promise that resolves to an array representing the coil states. * * @example * ```javascript * const coils = await client.readCoils({ address: 0, quantity: 8 }); * console.log(coils); // e.g., [1, 0, 1, ...] * ``` */ readCoils(options: ReadBitsOptions): Promise; /** * Writes a single coil (FC05). * Writes a single coil (Function Code 05). * @param {WriteSingleCoilOptions} options - Options for writing a single coil. * @param {number} options.address - The coil address. * @param {CoilState} options.value - The coil state to write. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {`Promise`} - A promise that resolves when the write is complete. * * @example * ```javascript * await client.writeSingleCoil({ address: 10, value: CoilState.On }); * ``` */ writeSingleCoil(options: WriteSingleCoilOptions): Promise; /** * Writes multiple coils (FC15). * Writes multiple consecutive coils (Function Code 15). * @param {WriteMultipleCoilsOptions} options - Options for writing multiple coils. * @param {number} options.address - The starting coil address. * @param {CoilState[]} options.values - An array of coil states to write. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {`Promise`} - A promise that resolves when the write is complete. * * @example * ```javascript * await client.writeMultipleCoils({ address: 20, values: [CoilState.On, CoilState.Off] }); * ``` */ writeMultipleCoils(options: WriteMultipleCoilsOptions): Promise; /** * Reads discrete inputs (FC02). * Reads the status of one or more discrete inputs (Function Code 02). * @param {ReadBitsOptions} options - Options for reading bits. * @param {number} options.address - The starting discrete input address. * @param {number} options.quantity - The number of discrete inputs to read. * @param {AbortSignal} [options.signal] - An optional cancellation signal. * @returns {Promise} - A promise that resolves to an array of states. * * @example * ```javascript * const inputs = await client.readDiscreteInputs({ address: 0, quantity: 4 }); * ``` */ readDiscreteInputs(options: ReadBitsOptions): Promise; /** * Reads FIFO queue (FC24). * Reads from a FIFO queue register (Function Code 24). * @param options Options for reading the FIFO queue. * @param options.address The FIFO pointer address. * @param options.signal An optional `AbortSignal` to cancel the operation. * * @example * ```javascript * const fifoContents = await client.readFifoQueue({ address: 42 }); * ``` */ readFifoQueue(options: ReadFifoQueueOptions): Promise; /** * Reads file records (FC20). * Reads one or more file records (Function Code 20). * @param options Options for reading file records. * @param options.requests An array of file record read sub-requests. * @param options.signal An optional `AbortSignal` to cancel the operation. * * @example * ```javascript * const records = await client.readFileRecord({ * requests: [ * { fileNumber: 4, recordNumber: 1, recordLength: 2 } * ] * }); * ``` */ readFileRecord(options: ReadFileRecordOptions): Promise; /** * Writes file records (FC21). * Writes one or more file records (Function Code 21). * @param options Options for writing file records. * @param options.requests An array of file record write sub-requests. * @param options.signal An optional `AbortSignal` to cancel the operation. */ writeFileRecord(options: WriteFileRecordOptions): Promise; /** * Reads exception status (FC07). * Reads the device's exception status byte (Function Code 07). */ readExceptionStatus(): Promise; /** * Sends a diagnostics request (FC08). * Executes a diagnostic function on the device (Function Code 08). * @param options Options for the diagnostics request. * @param options.sub_function The diagnostic sub-function code. * @param options.data Data to be sent with the request. * @param options.signal An optional `AbortSignal` to cancel the operation. */ diagnostics(options: DiagnosticsOptions): Promise; /** * Reads device identification (FC43/MEI14). * Reads device identification information (Function Code 43, MEI 14). * @param options Options for reading device identification. * @param options.read_device_id_code The category of objects to read (e.g., basic, regular). * @param options.object_id The ID of the first object to read. * @param options.signal An optional `AbortSignal` to cancel the operation. */ readDeviceIdentification(options: ReadDeviceIdentificationOptions): Promise; } /** * Async Modbus TCP server. * * Binds to a TCP port and handles incoming Modbus requests using JS callbacks. * An asynchronous Modbus TCP server that listens for incoming client connections. */ export declare class AsyncTcpModbusServer { /** * Creates and starts a new TCP server. * Creates and starts a new Modbus TCP server. * * @param {TcpServerOptions} options Server bind options. * @param {string} options.host The host address to bind to (e.g., '0.0.0.0'). * @param {number} options.port The TCP port to listen on. * @param {number} options.unitId The Modbus unit ID the server will respond to. * @param {ServerHandlers} handlers An object containing callback functions to handle Modbus requests. * @returns {`Promise`} A `Promise` that resolves to a running `AsyncTcpModbusServer` instance. */ static bind(options: TcpServerOptions, handlers: ServerHandlers): Promise; /** * Stops the server. * Stops the server and closes all active connections. */ shutdown(): Promise; } /** * Physical TCP socket connection to a Modbus device or gateway. * Manages a physical TCP socket connection to a Modbus device or gateway. * This class is a factory for creating lightweight `AsyncTcpModbusClient` instances * that are bound to a specific unit ID and share the underlying TCP connection. * * Use the static `connect` method to establish a connection. */ export declare class AsyncTcpTransport { /** * Connects to a Modbus TCP device or gateway. * Establishes a connection to a Modbus TCP device or gateway. * * @param options - Connection options including host, port, and timeout settings. * @param options.host - Target host address (IP or hostname). * @param options.port - Target TCP port (typically 502). */ static connect(options: TcpTransportOptions): Promise; /** * Creates a device client bound to the specified unit ID. * Creates a lightweight device client that communicates through this transport. * The client is bound to a specific Modbus unit ID. * * @param options - Options specifying the unit ID. */ createClient(options: CreateClientOptions): AsyncTcpModbusClient; /** * Sets the per-request timeout in milliseconds. * * Sets the timeout for individual Modbus requests made through this transport. * * Note: This feature is effective, but based on ongoing RFC discussions it might be * removed or revised in a future release. If you feel this is a mandatory feature for your use case, * it is suggested to leave a comment on the GitHub RFC discussion. * * @param timeout_ms The timeout duration in milliseconds. */ setRequestTimeout(timeoutMs: number): void; /** * Clears the per-request timeout. * * Clears any previously set per-request timeout, reverting to the default behavior. */ clearRequestTimeout(): void; /** * Returns whether there are pending requests. * Checks if there are any Modbus requests currently in-flight on this transport. */ readonly pendingRequests: boolean; /** * Closes the connection. * Closes the underlying TCP connection and shuts down the transport. */ close(): Promise; /** * Reconnects the transport after a disconnect. * Attempts to re-establish the TCP connection if it has been closed. */ reconnect(): Promise; } /** Connection options for the serial ASCII transport. */ export interface AsciiTransportOptions { /** Serial port path (e.g., "/dev/ttyUSB0", "COM3"). Note: The maximum path length is limited at compile time (default: 128 chars, configurable via the `MBUS_PORT_PATH_STRING_LEN` environment variable). */ portPath: string; /** Baud rate (e.g., 9600, 19200, 38400, 57600, 115200). */ baudRate: number; /** Data bits (5, 6, 7, or 8). */ dataBits?: 5 | 6 | 7 | 8; /** Parity ("none", "even", "odd"). */ parity?: 'none' | 'even' | 'odd'; /** Stop bits (1 or 2). */ stopBits?: 1 | 2; /** Response turnaround timeout in milliseconds. Time to wait for the target slave device to respond once the request has been dispatched onto the wire. */ responseTimeoutMs?: number; /** Queue waiting timeout in milliseconds. If the transport pipeline is congested and the request cannot be dispatched onto the wire within this time, it fails early with ModbusErrorCode.TIMEOUT without reaching the wire. Note: This feature is effective, but based on ongoing RFC discussions it might be removed or revised in a future release. If you feel this is a mandatory feature for your use case, it is suggested to leave a comment on the GitHub RFC discussion. */ requestTimeoutMs?: number; /** Number of retry attempts on failure (0 = none). Default: 0. */ retryAttempts?: number; /** Delay between retry attempts in milliseconds. */ retryDelayMs?: number; /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". Note: This feature is currently ineffective and is reserved for future implementation. A GitHub RFC discussion is open to decide whether to implement or remove it. */ retryBackoffStrategy?: string; } /** Represents a Modbus coil or discrete input state. */ export enum CoilState { /** Coil is OFF (wire value: 0). */ Off = 0, /** Coil is ON (wire value: 1). */ On = 1 } /** Options for creating a client bound to a specific unit ID. */ export interface CreateClientOptions { /** Modbus unit ID (slave address) from 1 to 247. */ unitId: number; } /** Device identification object. */ export interface DeviceIdentificationObject { /** The object ID. */ id: number; /** The value of the object, represented as a string. */ value: string; } /** Response from device identification request. */ export interface DeviceIdentificationResponse { /** The conformity level of the device. */ conformityLevel: number; /** Indicates if more objects are available to be read. */ moreFollows: boolean; /** The ID of the next object to read if moreFollows is true. */ nextObjectId: number; /** An array of device identification objects. */ objects: Array; } /** Options for diagnostics request. */ export interface DiagnosticsOptions { /** Diagnostic sub-function code. */ subFunction: number; /** Data to be sent with the diagnostics request. */ data?: Uint16Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for diagnostics. */ export interface DiagnosticsRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The diagnostic sub-function code to execute. */ subFunction: number; /** Data sent with the diagnostics request. */ data: Uint16Array; } /** Response from diagnostics request. */ export interface DiagnosticsResponse { /** The sub-function code from the request. */ subFunction: number; /** The data returned by the diagnostics function. */ data: Uint16Array; } /** Downstream server configuration. */ export interface DownstreamConfig { /** Downstream server host. */ host: string; /** Downstream server port. */ port: number; } /** Response from reading FIFO queue. */ export interface FifoQueueResponse { /** The number of 16-bit values in the queue. */ count: number; /** Queue values. */ values: Uint16Array; } /** A single file record read sub-request. */ export interface FileRecordReadRequest { /** The file number (1-65535). */ fileNumber: number; /** The starting record number within the file. */ recordNumber: number; /** The number of records to read. */ recordLength: number; } /** A single file record read sub-request on the server side. */ export interface FileRecordReadServerSubRequest { /** The file number (1-65535). */ fileNumber: number; /** The starting record number within the file. */ recordNumber: number; /** The number of records to read. */ recordLength: number; } /** A single file record write sub-request. */ export interface FileRecordWriteRequest { /** The file number (1-65535). */ fileNumber: number; /** The starting record number within the file. */ recordNumber: number; /** The record data to write, as an array of 16-bit values. */ recordData: Uint16Array; } /** A single file record write sub-request on the server side. */ export interface FileRecordWriteSubRequest { /** The file number (1-65535). */ fileNumber: number; /** The starting record number within the file. */ recordNumber: number; /** The record data to write, as an array of 16-bit values. */ recordData: Uint16Array; } /** Gateway bind options. */ export interface GatewayBindOptions { /** Bind host address (e.g., "0.0.0.0"). */ host: string; /** Bind port. */ port: number; } /** Gateway configuration. */ export interface GatewayConfig { /** List of downstream servers. */ downstreams: Array; /** Routing table mapping unit IDs to downstream channels. */ routes: Array; } /** Options for modifying a register with a bitwise mask (FC22). */ export interface MaskWriteRegisterOptions { /** Target register address. */ address: number; /** Bitwise AND mask. */ andMask: number; /** Bitwise OR mask. */ orMask: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Standard Modbus exception codes. */ export enum ModbusExceptionCode { /** Function code received in the query is not an allowable action for the server. */ IllegalFunction = 1, /** The data address received in the query is not an allowable address for the server. */ IllegalDataAddress = 2, /** A value contained in the query data field is not an allowable value for the server. */ IllegalDataValue = 3, /** An unrecoverable error occurred while the server was attempting to perform the requested action. */ ServerDeviceFailure = 4, /** The server has accepted the request and is processing it, but a long duration of time will be required. */ Acknowledge = 5, /** The server is engaged in processing a long-duration program command. */ SlaveDeviceBusy = 6, /** The server attempted to read record file, but detected a parity error in the memory. */ MemoryParityError = 8, /** Specialized for gateways: The gateway was unable to allocate an internal communication path. */ GatewayPathUnavailable = 10, /** Specialized for gateways: No response was received from the target device. */ GatewayTargetDeviceFailedToRespond = 11 } /** Options for reading coils or discrete inputs. */ export interface ReadBitsOptions { /** Starting address. */ address: number; /** Number of bits (coils or discrete inputs) to read. */ quantity: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for reading coils. */ export interface ReadCoilsRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the coils to read. */ address: number; /** The number of coils to read. */ quantity: number; } /** Options for device identification. */ export interface ReadDeviceIdentificationOptions { /** Read device ID code (1=basic, 2=regular, 3=extended, 4=individual). */ readDeviceIdCode?: number; /** The ID of the first object to read. */ objectId?: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Request parameters for reading device identification (MEI FC43/14). */ export interface ReadDeviceIdentificationRequest { /** Target device address. */ unitId: number; /** Read device ID code (1, 2, 3, or 4). */ readDeviceIdCode: number; /** Starting object ID (0 to 255). */ objectId: number; } /** Handler request for reading discrete inputs. */ export interface ReadDiscreteInputsRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the discrete inputs to read. */ address: number; /** The number of discrete inputs to read. */ quantity: number; } /** Handler request for reading exception status. */ export interface ReadExceptionStatusRequest { /** The unit ID of the device that sent the request. */ unitId: number; } /** Options for reading FIFO queue. */ export interface ReadFifoQueueOptions { /** FIFO pointer address. */ address: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for reading FIFO queue. */ export interface ReadFifoQueueRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The address of the FIFO queue pointer register. */ address: number; } /** Options for reading file records. */ export interface ReadFileRecordOptions { /** An array of file record read sub-requests. */ requests: Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for reading file records. */ export interface ReadFileRecordRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** An array of file record read sub-requests. */ requests: Array; } /** Handler request for reading holding registers. */ export interface ReadHoldingRegistersRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the holding registers to read. */ address: number; /** The number of holding registers to read. */ quantity: number; } /** Handler request for reading input registers. */ export interface ReadInputRegistersRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the input registers to read. */ address: number; /** The number of input registers to read. */ quantity: number; } /** Options for reading registers. */ export interface ReadRegistersOptions { /** Starting register address. */ address: number; /** Number of registers to read (quantity). */ quantity: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Options for read/write multiple registers (FC23). */ export interface ReadWriteMultipleRegistersOptions { /** Starting address for read operation. */ readAddress: number; /** Number of registers to read (quantity). */ readQuantity: number; /** Starting address for write operation. */ writeAddress: number; /** An array of 16-bit values to write. */ writeValues: Uint16Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for read/write multiple registers (FC23). */ export interface ReadWriteMultipleRegistersRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address for the read operation. */ readAddress: number; /** The number of registers to read. */ readQuantity: number; /** The starting address for the write operation. */ writeAddress: number; /** The array of 16-bit values to write. */ writeValues: Uint16Array; } /** Route entry mapping unit ID to a downstream channel. */ export interface RouteEntry { /** Modbus unit ID (1-247). */ unitId: number; /** Index into the downstreams array. */ channel: number; } /** Connection options for the serial RTU transport. */ export interface RtuTransportOptions { /** Serial port path (e.g., "/dev/ttyUSB0", "COM3"). Note: The maximum path length is limited at compile time (default: 128 chars, configurable via the `MBUS_PORT_PATH_STRING_LEN` environment variable). */ portPath: string; /** Baud rate (e.g., 9600, 19200, 38400, 57600, 115200). */ baudRate: number; /** Data bits (5, 6, 7, or 8). */ dataBits?: 5 | 6 | 7 | 8; /** Parity ("none", "even", "odd"). */ parity?: 'none' | 'even' | 'odd'; /** Stop bits (1 or 2). */ stopBits?: 1 | 2; /** Response turnaround timeout in milliseconds. Time to wait for the target slave device to respond once the request has been dispatched onto the wire. */ responseTimeoutMs?: number; /** Queue waiting timeout in milliseconds. If the transport pipeline is congested and the request cannot be dispatched onto the wire within this time, it fails early with ModbusErrorCode.TIMEOUT without reaching the wire. Note: This feature is effective, but based on ongoing RFC discussions it might be removed or revised in a future release. If you feel this is a mandatory feature for your use case, it is suggested to leave a comment on the GitHub RFC discussion. */ requestTimeoutMs?: number; /** Number of retry attempts on failure (0 = none). Default: 0. */ retryAttempts?: number; /** Delay between retry attempts in milliseconds. */ retryDelayMs?: number; /** Backoff strategy: "immediate", "fixed", or "exponential". Default: "immediate". Note: This feature is currently ineffective and is reserved for future implementation. A GitHub RFC discussion is open to decide whether to implement or remove it. */ retryBackoffStrategy?: string; } /** Server bind options for serial port. */ export interface SerialServerOptions { /** Serial port path (e.g., "/dev/ttyUSB0", "COM3"). Note: The maximum path length is limited at compile time (default: 128 chars, configurable via the `MBUS_PORT_PATH_STRING_LEN` environment variable). */ portPath: string; /** Baud rate (e.g., 9600, 19200, 38400, 57600, 115200). */ baudRate: number; /** Data bits (5, 6, 7, or 8). */ dataBits?: 5 | 6 | 7 | 8; /** Parity ("none", "even", "odd"). */ parity?: 'none' | 'even' | 'odd'; /** Stop bits (1 or 2). */ stopBits?: 1 | 2; /** Modbus unit ID (1-247) for the server to respond to. */ unitId: number; /** Response timeout in milliseconds. */ responseTimeoutMs?: number; } /** Handler response for diagnostics. */ export interface ServerDiagnosticsResponse { /** The sub-function code from the request. */ subFunction: number; /** The data to be returned by the diagnostics function. */ data: Uint16Array; } /** Server bind options. */ export interface TcpServerOptions { /** Bind host address (e.g., "0.0.0.0"). */ host: string; /** Bind port. */ port: number; /** Modbus unit ID to respond to. */ unitId: number; } /** Connection options for the TCP transport. */ export interface TcpTransportOptions { /** Target host address (IP or hostname). */ host: string; /** Target TCP port (typically 502). */ port: number; /** Queue waiting timeout in milliseconds. If the transport pipeline is congested and the request cannot be dispatched onto the wire within this time, it fails early with ModbusErrorCode.TIMEOUT without reaching the wire. Note: This feature is effective, but based on ongoing RFC discussions it might be removed or revised in a future release. If you feel this is a mandatory feature for your use case, it is suggested to leave a comment on the GitHub RFC discussion. */ requestTimeoutMs?: number; /** Response turnaround timeout in milliseconds. Time to wait for the target server/device to respond once the request has been dispatched onto the wire. */ responseTimeoutMs?: number; /** Number of retry attempts on failure. Default: 0 (no retries). */ retryAttempts?: number; /** Delay between retry attempts in milliseconds. */ retryDelayMs?: number; /** Backoff strategy for retries: "immediate", "fixed", or "exponential". Default: "immediate". Note: This feature is currently ineffective and is reserved for future implementation. A GitHub RFC discussion is open to decide whether to implement or remove it. */ retryBackoffStrategy?: string; } /** Options for writing file records. */ export interface WriteFileRecordOptions { /** An array of file record write sub-requests. */ requests: Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for writing file records. */ export interface WriteFileRecordRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** An array of file record write sub-requests. */ requests: Array; } /** Options for writing multiple coils. */ export interface WriteMultipleCoilsOptions { /** Starting coil address. */ address: number; /** An array of coil states to write. */ values: Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for writing multiple coils. */ export interface WriteMultipleCoilsRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the coils to write to. */ address: number; /** The array of coil states to write. */ values: CoilState[]; } /** Options for writing multiple registers. */ export interface WriteMultipleRegistersOptions { /** The starting register address. */ address: number; /** An array of 16-bit values to write. */ values: Uint16Array; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for writing multiple registers. */ export interface WriteMultipleRegistersRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The starting address of the registers to write to. */ address: number; /** The array of 16-bit values to write. */ values: Uint16Array; } /** Options for writing a single coil. */ export interface WriteSingleCoilOptions { /** The coil address. */ address: number; /** The coil state (CoilState.On = 1, CoilState.Off = 0). */ value: CoilState; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for writing a single coil. */ export interface WriteSingleCoilRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The address of the coil to write to. */ address: number; /** The coil state (CoilState.On = 1, CoilState.Off = 0). */ value: CoilState; } /** Options for writing a single register. */ export interface WriteSingleRegisterOptions { /** The register address. */ address: number; /** The 16-bit value to write. */ value: number; /** An optional `AbortSignal` to cancel the asynchronous operation. */ signal?: AbortSignal; } /** Handler request for writing a single register. */ export interface WriteSingleRegisterRequest { /** The unit ID of the device that sent the request. */ unitId: number; /** The address of the register to write to. */ address: number; /** The 16-bit value to write. */ value: number; } /** Represents a Modbus discrete input pin state (alias for CoilState). */ export type DiscreteInputState = CoilState; export declare const DiscreteInputState: typeof CoilState; /** Modbus exception returned from a server handler. */ export interface ModbusException { /** The Modbus exception code. */ exceptionCode: ModbusExceptionCode | number; } /** * Callback functions to handle Modbus server requests. * * Each handler corresponds to a specific Modbus function code. If a handler is not provided, * the server will respond with an "Illegal Function" exception (0x01). * * Handlers can return the expected data directly or return a Promise for async operations. * To return a Modbus exception, return an object matching the `ModbusException` interface. */ export interface ServerHandlers { /** * Handle Read Coils (FC 01). * @param req The request object. * @param req.address The starting coil address (0x0000 to 0xFFFF). * @param req.quantity The number of coils to read (1 to 2000). * @returns An array of booleans representing the coil states, or a ModbusException. */ onReadCoils?: (req: ReadCoilsRequest) => CoilState[] | ModbusException | Promise; /** * Handle Read Discrete Inputs (FC 02). * @param req The request object. * @param req.address The starting discrete input address (0x0000 to 0xFFFF). * @param req.quantity The number of inputs to read (1 to 2000). * @returns An array of discrete input states, or a ModbusException. */ onReadDiscreteInputs?: (req: ReadDiscreteInputsRequest) => DiscreteInputState[] | ModbusException | Promise; /** * Handle Read Holding Registers (FC 03). * @param req The request object. * @param req.address The starting holding register address (0x0000 to 0xFFFF). * @param req.quantity The number of registers to read (1 to 125). * @returns An array of 16-bit numbers representing the registers, or a ModbusException. */ onReadHoldingRegisters?: (req: ReadHoldingRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read Input Registers (FC 04). * @param req The request object. * @param req.address The starting input register address (0x0000 to 0xFFFF). * @param req.quantity The number of registers to read (1 to 125). * @returns An array of 16-bit numbers representing the registers, or a ModbusException. */ onReadInputRegisters?: (req: ReadInputRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Write Single Coil (FC 05). * @param req The request object. * @param req.address The address of the coil to write (0x0000 to 0xFFFF). * @param req.value The boolean value to write (true for ON, false for OFF). * @returns void on success, or a ModbusException. */ onWriteSingleCoil?: (req: WriteSingleCoilRequest) => void | ModbusException | Promise; /** * Handle Write Single Register (FC 06). * @param req The request object. * @param req.address The address of the register to write (0x0000 to 0xFFFF). * @param req.value The 16-bit value to write. * @returns void on success, or a ModbusException. */ onWriteSingleRegister?: (req: WriteSingleRegisterRequest) => void | ModbusException | Promise; /** * Handle Read Exception Status (FC 07). * @param req The read exception status request object (empty). * @returns An 8-bit exception status byte, or a ModbusException. */ onReadExceptionStatus?: (req: ReadExceptionStatusRequest) => number | ModbusException | Promise; /** * Handle Diagnostics (FC 08). * @param req The diagnostics request object. * @param req.subFunction The 16-bit sub-function code. * @param req.data The 16-bit data payload for the sub-function. * @returns A response containing the sub-function and data, or a ModbusException. */ onDiagnostics?: (req: DiagnosticsRequest) => ServerDiagnosticsResponse | ModbusException | Promise; /** * Handle Write Multiple Coils (FC 15). * @param req The request object. * @param req.address The starting address of the coils to write. * @param req.values An array of booleans to write. * @returns void on success, or a ModbusException. */ onWriteMultipleCoils?: (req: WriteMultipleCoilsRequest) => void | ModbusException | Promise; /** * Handle Write Multiple Registers (FC 16). * @param req The request object. * @param req.address The starting address of the registers to write. * @param req.values An array of 16-bit numbers to write. * @returns void on success, or a ModbusException. */ onWriteMultipleRegisters?: (req: WriteMultipleRegistersRequest) => void | ModbusException | Promise; /** * Handle Read File Record (FC 20). * @param req The request object. * @param req.requests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordLength`. * @returns An array of register arrays for each sub-request, or a ModbusException. */ onReadFileRecord?: (req: ReadFileRecordRequest) => Uint16Array[] | ModbusException | Promise; /** * Handle Write File Record (FC 21). * @param req The request object. * @param req.requests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordData` (a Uint16Array). * @returns void on success, or a ModbusException. */ onWriteFileRecord?: (req: WriteFileRecordRequest) => void | ModbusException | Promise; /** * Handle Read/Write Multiple Registers (FC 23). * @param req The request containing addresses and values to read and write. * @param req.readAddress The starting address for the read operation. * @param req.readQuantity The number of registers to read. * @param req.writeAddress The starting address for the write operation. * @param req.values An array of 16-bit numbers to write. * @returns An array of 16-bit numbers read, or a ModbusException. */ onReadWriteMultipleRegisters?: (req: ReadWriteMultipleRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read FIFO Queue (FC 24). * @param req The request object containing the FIFO pointer `address`. * @returns An array of 16-bit numbers from the queue, or a ModbusException. */ onReadFifoQueue?: (req: ReadFifoQueueRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read Device Identification (FC 43/14). * @param req The request object. * @returns Device identification response, or a ModbusException. */ onReadDeviceIdentification?: (req: ReadDeviceIdentificationRequest) => DeviceIdentificationResponse | ModbusException | Promise; } /** * Stable error codes for identifying Modbus-related errors. * These can be used with the `getModbusErrorCode` helper to check for specific error types. */ export declare const ModbusErrorCode: { /** A Modbus exception response was received from the server (e.g., illegal function). */ readonly EXCEPTION: 'MODBUS_EXCEPTION'; /** The request timed out waiting for a response. */ readonly TIMEOUT: 'MODBUS_TIMEOUT'; /** A transport-level error occurred (e.g., framing error, checksum mismatch). */ readonly TRANSPORT: 'MODBUS_TRANSPORT'; /** An invalid argument was provided to a client or server function. */ readonly INVALID_ARGUMENT: 'MODBUS_INVALID_ARGUMENT'; /** The underlying connection was closed. */ readonly CONNECTION_CLOSED: 'MODBUS_CONNECTION_CLOSED'; /** An unexpected internal error occurred within the library. */ readonly INTERNAL: 'MODBUS_INTERNAL'; }; /** * Extracts a stable error code from a Modbus error object. * @param err The error object. * @returns The corresponding code from `ModbusErrorCode`, or undefined if not a Modbus error. */ export declare function getModbusErrorCode(err: Error): string | undefined; export { WasmWsTransport, WasmWsModbusClient, WasmWsModbusServer, WasmSerialModbusClient, WasmSerialModbusServer, WasmSerialPortHandle, WasmRtuTransport, WasmAsciiTransport, WasmServerTransportKind, requestSerialPort } from 'modbus-rs-wasm'; /** Represents a Modbus discrete input pin state (alias for CoilState). */ export type DiscreteInputState = CoilState; export declare const DiscreteInputState: typeof CoilState; /** Modbus exception returned from a server handler. */ export interface ModbusException { /** The Modbus exception code. */ exceptionCode: ModbusExceptionCode | number; } /** * Callback functions to handle Modbus server requests. * * Each handler corresponds to a specific Modbus function code. If a handler is not provided, * the server will respond with an "Illegal Function" exception (0x01). * * Handlers can return the expected data directly or return a Promise for async operations. * To return a Modbus exception, return an object matching the `ModbusException` interface. */ export interface ServerHandlers { /** * Handle Read Coils (FC 01). * @param req The request object. * @param req.address The starting coil address (0x0000 to 0xFFFF). * @param req.quantity The number of coils to read (1 to 2000). * @returns An array of booleans representing the coil states, or a ModbusException. */ onReadCoils?: (req: ReadCoilsRequest) => CoilState[] | ModbusException | Promise; /** * Handle Read Discrete Inputs (FC 02). * @param req The request object. * @param req.address The starting discrete input address (0x0000 to 0xFFFF). * @param req.quantity The number of inputs to read (1 to 2000). * @returns An array of discrete input states, or a ModbusException. */ onReadDiscreteInputs?: (req: ReadDiscreteInputsRequest) => DiscreteInputState[] | ModbusException | Promise; /** * Handle Read Holding Registers (FC 03). * @param req The request object. * @param req.address The starting holding register address (0x0000 to 0xFFFF). * @param req.quantity The number of registers to read (1 to 125). * @returns An array of 16-bit numbers representing the registers, or a ModbusException. */ onReadHoldingRegisters?: (req: ReadHoldingRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read Input Registers (FC 04). * @param req The request object. * @param req.address The starting input register address (0x0000 to 0xFFFF). * @param req.quantity The number of registers to read (1 to 125). * @returns An array of 16-bit numbers representing the registers, or a ModbusException. */ onReadInputRegisters?: (req: ReadInputRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Write Single Coil (FC 05). * @param req The request object. * @param req.address The address of the coil to write (0x0000 to 0xFFFF). * @param req.value The boolean value to write (true for ON, false for OFF). * @returns void on success, or a ModbusException. */ onWriteSingleCoil?: (req: WriteSingleCoilRequest) => void | ModbusException | Promise; /** * Handle Write Single Register (FC 06). * @param req The request object. * @param req.address The address of the register to write (0x0000 to 0xFFFF). * @param req.value The 16-bit value to write. * @returns void on success, or a ModbusException. */ onWriteSingleRegister?: (req: WriteSingleRegisterRequest) => void | ModbusException | Promise; /** * Handle Read Exception Status (FC 07). * @param req The read exception status request object (empty). * @returns An 8-bit exception status byte, or a ModbusException. */ onReadExceptionStatus?: (req: ReadExceptionStatusRequest) => number | ModbusException | Promise; /** * Handle Diagnostics (FC 08). * @param req The diagnostics request object. * @param req.subFunction The 16-bit sub-function code. * @param req.data The 16-bit data payload for the sub-function. * @returns A response containing the sub-function and data, or a ModbusException. */ onDiagnostics?: (req: DiagnosticsRequest) => ServerDiagnosticsResponse | ModbusException | Promise; /** * Handle Write Multiple Coils (FC 15). * @param req The request object. * @param req.address The starting address of the coils to write. * @param req.values An array of booleans to write. * @returns void on success, or a ModbusException. */ onWriteMultipleCoils?: (req: WriteMultipleCoilsRequest) => void | ModbusException | Promise; /** * Handle Write Multiple Registers (FC 16). * @param req The request object. * @param req.address The starting address of the registers to write. * @param req.values An array of 16-bit numbers to write. * @returns void on success, or a ModbusException. */ onWriteMultipleRegisters?: (req: WriteMultipleRegistersRequest) => void | ModbusException | Promise; /** * Handle Read File Record (FC 20). * @param req The request object. * @param req.requests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordLength`. * @returns An array of register arrays for each sub-request, or a ModbusException. */ onReadFileRecord?: (req: ReadFileRecordRequest) => Uint16Array[] | ModbusException | Promise; /** * Handle Write File Record (FC 21). * @param req The request object. * @param req.requests An array of sub-requests, each with `fileNumber`, `recordNumber`, and `recordData` (a Uint16Array). * @returns void on success, or a ModbusException. */ onWriteFileRecord?: (req: WriteFileRecordRequest) => void | ModbusException | Promise; /** * Handle Read/Write Multiple Registers (FC 23). * @param req The request containing addresses and values to read and write. * @param req.readAddress The starting address for the read operation. * @param req.readQuantity The number of registers to read. * @param req.writeAddress The starting address for the write operation. * @param req.values An array of 16-bit numbers to write. * @returns An array of 16-bit numbers read, or a ModbusException. */ onReadWriteMultipleRegisters?: (req: ReadWriteMultipleRegistersRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read FIFO Queue (FC 24). * @param req The request object containing the FIFO pointer `address`. * @returns An array of 16-bit numbers from the queue, or a ModbusException. */ onReadFifoQueue?: (req: ReadFifoQueueRequest) => Uint16Array | ModbusException | Promise; /** * Handle Read Device Identification (FC 43/14). * @param req The request object. * @returns Device identification response, or a ModbusException. */ onReadDeviceIdentification?: (req: ReadDeviceIdentificationRequest) => DeviceIdentificationResponse | ModbusException | Promise; } /** * Stable error codes for identifying Modbus-related errors. * These can be used with the `getModbusErrorCode` helper to check for specific error types. */ export declare const ModbusErrorCode: { /** A Modbus exception response was received from the server (e.g., illegal function). */ readonly EXCEPTION: 'MODBUS_EXCEPTION'; /** The request timed out waiting for a response. */ readonly TIMEOUT: 'MODBUS_TIMEOUT'; /** A transport-level error occurred (e.g., framing error, checksum mismatch). */ readonly TRANSPORT: 'MODBUS_TRANSPORT'; /** An invalid argument was provided to a client or server function. */ readonly INVALID_ARGUMENT: 'MODBUS_INVALID_ARGUMENT'; /** The underlying connection was closed. */ readonly CONNECTION_CLOSED: 'MODBUS_CONNECTION_CLOSED'; /** An unexpected internal error occurred within the library. */ readonly INTERNAL: 'MODBUS_INTERNAL'; }; /** * Extracts a stable error code from a Modbus error object. * @param err The error object. * @returns The corresponding code from `ModbusErrorCode`, or undefined if not a Modbus error. */ export declare function getModbusErrorCode(err: Error): string | undefined; export { WasmWsTransport, WasmWsModbusClient, WasmWsModbusServer, WasmSerialModbusClient, WasmSerialModbusServer, WasmSerialPortHandle, WasmRtuTransport, WasmAsciiTransport, WasmServerTransportKind, requestSerialPort } from 'modbus-rs-wasm';