import * as framer from '../protocol/framing.js'; import { IModbusProtocol } from '../types/internal.js'; import { ITransport } from '../types/public.js'; /** * ModbusProtocol is a low-level class responsible for reliable Modbus ADU (Application Data Unit) exchange. * It handles framing (RTU or TCP), request transmission, response reception, and basic error recovery. * This class is used internally by ModbusClient and abstracts the differences between RTU and TCP protocols. */ export declare class ModbusProtocol implements IModbusProtocol { private _transport; private _framerClass; private minLen; /** * Creates a new ModbusProtocol instance. * @param _transport - Transport layer used for reading and writing raw bytes * @param _framerClass - Framer class (RtuFramer or TcpFramer) responsible for ADU construction and parsing */ constructor(_transport: ITransport, _framerClass: typeof framer.RtuFramer | typeof framer.TcpFramer); /** * Performs a complete Modbus request-response exchange. * * Steps performed: * 1. Builds the ADU (Application Data Unit) from the given PDU using the selected framer * 2. Optionally flushes the transport buffer (for serial/RS485) * 3. Writes the request to the transport * 4. Reads the response in chunks until a valid ADU can be parsed * 5. Handles partial responses, CRC errors, and short frames gracefully * 6. Returns only the PDU portion of the received ADU * * @param unitId - Modbus slave/unit identifier (0-255) * @param pduRequest - Protocol Data Unit containing function code and data * @param timeout - Maximum time in milliseconds to wait for a complete response * @returns The parsed PDU from the device's response * * @throws ModbusCRCError if CRC check fails and enough data was received * @throws ModbusResponseError for malformed or incomplete responses * @throws Error with timeout message if the operation exceeds the timeout */ exchange(unitId: number, pduRequest: Uint8Array, timeout: number): Promise; /** * Returns the underlying transport instance used by this protocol. * Useful for advanced use cases or debugging. */ get transport(): ITransport; /** * Returns the framer class (RtuFramer or TcpFramer) currently in use. * Can be used to inspect which framing protocol is active. */ get framerClass(): typeof framer.RtuFramer | typeof framer.TcpFramer; }