import type { Transport } from '@ya-modbus/driver-types'; import type { Mutex } from 'async-mutex'; import type ModbusRTU from 'modbus-serial'; import { type RetryLogger } from './retry.js'; /** * SlaveTransport wraps a shared ModbusRTU client with slave-specific addressing. * * Multiple SlaveTransport instances can share the same physical connection (serial port or TCP), * each communicating with a different slave device. The slave ID is set before each operation * to ensure requests are directed to the correct device. * * @example * ```typescript * const client = new ModbusRTU() * await client.connectRTUBuffered('/dev/ttyUSB0', { baudRate: 9600 }) * const mutex = new Mutex() * * // Two devices on the same serial port * const device1 = new SlaveTransport(1, client, mutex, 3) * const device2 = new SlaveTransport(2, client, mutex, 3) * * // Each device talks to its own slave ID * await device1.readHoldingRegisters(0, 10) // Reads from slave 1 * await device2.readHoldingRegisters(0, 10) // Reads from slave 2 * ``` */ export declare class SlaveTransport implements Transport { private readonly slaveId; private readonly client; private readonly mutex; private readonly maxRetries; private readonly logger?; /** * @param slaveId - Modbus slave/unit ID for this device * @param client - Shared ModbusRTU client instance * @param mutex - Shared mutex for serializing operations on the bus * @param maxRetries - Maximum retry attempts for failed operations (default: 3) * @param logger - Optional callback to log retry attempts */ constructor(slaveId: number, client: ModbusRTU, mutex: Mutex, maxRetries?: number, logger?: RetryLogger | undefined); readHoldingRegisters(address: number, count: number): Promise; readInputRegisters(address: number, count: number): Promise; readCoils(address: number, count: number): Promise; readDiscreteInputs(address: number, count: number): Promise; writeSingleRegister(address: number, value: number): Promise; writeMultipleRegisters(address: number, values: Buffer): Promise; writeSingleCoil(address: number, value: boolean): Promise; writeMultipleCoils(address: number, values: Buffer): Promise; /** * Close the underlying client connection. * * IMPORTANT: This method does not use mutex protection and should only * be called during shutdown via TransportManager.closeAll(). Calling * this while operations are in progress may cause connection errors. * * Individual SlaveTransport instances should NOT call close() directly * as the client is shared across multiple devices on the same bus. */ close(): Promise; } //# sourceMappingURL=slave-transport.d.ts.map