/** * Utility class for Modbus RTU (Remote Terminal Unit) framing. * Provides methods to wrap PDUs into RTU ADUs and validate incoming RTU packets. */ export declare class RtuFramer { /** * Builds a Modbus RTU ADU (Application Data Unit). * Structure: [Slave ID (1b)] [PDU (nb)] [CRC (2b)] * * @param {number} slaveId - The target slave unit identifier (typically 1-247). * @param {Uint8Array} pdu - The Modbus Protocol Data Unit (Function Code + Data). * @returns {Uint8Array} The complete RTU packet ready for transmission. */ static buildAdu(slaveId: number, pdu: Uint8Array): Uint8Array; /** * Parses and validates a raw Modbus RTU packet. * Performs CRC verification and extracts the Unit ID and PDU. * * @param {Uint8Array} packet - The raw byte buffer received from the serial port. * @returns {{ unitId: number; pdu: Uint8Array }} Object containing the extracted unit ID and PDU. * @throws {Error} Throws if the packet is too short or if the CRC checksum is invalid. */ static parseAdu(packet: Uint8Array): { unitId: number; pdu: Uint8Array; }; /** * Predicts the total expected length of an RTU response based on the request PDU. * Useful for knowing how many bytes to read from a serial stream. * * @param {Uint8Array} pdu - The request PDU (the PDU sent to the device). * @returns {number | null} The expected length of the full ADU in bytes, or null if unknown. */ static getExpectedResponseLength(pdu: Uint8Array): number | null; } /** * Utility class for Modbus TCP framing. * Handles the MBAP (Modbus Application Protocol) header used over Ethernet. */ export declare class TcpFramer { /** * Internal transaction counter. * @private */ private static transactionId; /** * Increments and returns the next Transaction Identifier (TID). * Rolls over at 65535. * * @private * @returns {number} The next 16-bit transaction ID. */ private static getNextTid; /** * Builds a Modbus TCP ADU (Application Data Unit). * Structure: [TID (2b)] [PID (2b)] [Length (2b)] [Unit ID (1b)] [PDU (nb)] * * @param {number} unitId - The unit identifier (typically 0xFF or 1 for TCP). * @param {Uint8Array} pdu - The Modbus Protocol Data Unit. * @returns {Uint8Array} The complete TCP packet with MBAP header. */ static buildAdu(unitId: number, pdu: Uint8Array): Uint8Array; /** * Parses and validates a Modbus TCP packet. * Validates the MBAP header and extracts the Unit ID and PDU. * * @param {Uint8Array} packet - The raw byte buffer received from the socket. * @returns {{ unitId: number; pdu: Uint8Array }} Object containing the extracted unit ID and PDU. * @throws {Error} Throws if the packet is too short or if the Protocol ID is not 0. */ static parseAdu(packet: Uint8Array): { unitId: number; pdu: Uint8Array; }; /** * Predicts the total expected length of a TCP response based on the request PDU. * Includes the 7-byte MBAP header. * * @param {Uint8Array} pdu - The request PDU. * @returns {number | null} The expected length of the full ADU in bytes, or null if unknown. */ static getExpectedResponseLength(pdu: Uint8Array): number | null; } declare const _default: { RtuFramer: typeof RtuFramer; TcpFramer: typeof TcpFramer; }; export default _default;