import type { Transport } from '@ya-modbus/driver-types'; import type { TransportConfig } from './factory.js'; /** * Statistics about managed transports */ export interface TransportStats { totalTransports: number; rtuTransports: number; tcpTransports: number; } /** * TransportManager pools modbus-serial clients and provides slave-specific transports. * * Key behaviors: * - Pools modbus-serial clients by physical connection (excluding slave ID) * - RTU clients are pooled by bus configuration (port, baud rate, parity, etc.) * - TCP clients are pooled by host and port * - Returns SlaveTransport instances that set the slave ID before each operation * - Multiple devices on the same connection share a single client and mutex * - All operations are serialized using async-mutex to prevent race conditions * * This architecture solves the multi-device problem: * - Each device gets its own SlaveTransport with its own slave ID * - All devices on the same bus share the same client and mutex * - Slave ID is set dynamically before each operation * - No more hardcoded slave IDs that affect all devices on a bus * * IMPORTANT: Shared Resource Ownership * Multiple SlaveTransport instances share the same client and mutex. This is * intentional and correct: * - Shared client: Avoids port contention (can't open serial port twice) * - Shared mutex: Ensures serialized access to the bus * - SlaveTransport.close(): Does not close shared client (use closeAll() for cleanup) */ export declare class TransportManager { private readonly connections; /** * Get or create a transport for the given configuration. * Returns a new SlaveTransport instance bound to the slave ID in the config. * Multiple devices on the same physical connection share the same client and mutex. * * @param config - RTU or TCP transport configuration * @returns SlaveTransport instance for the specific slave device */ getTransport(config: TransportConfig): Promise; /** * Get statistics about managed connections * * @returns Transport statistics */ getStats(): TransportStats; /** * Close all managed connections and clear the pool. * Errors during close are logged but do not stop the process. */ closeAll(): Promise; /** * Generate a unique key for a physical connection. * Excludes slave ID so multiple devices on the same bus share a connection. * For RTU: Key includes all bus parameters (port, baud, parity, etc.) * For TCP: Key includes host and port * * @param config - Transport configuration * @returns Physical connection key string */ private getPhysicalConnectionKey; /** * Create and configure an RTU modbus-serial client. * Does NOT set slave ID - that's handled by SlaveTransport. * * @param config - RTU configuration * @returns Connected ModbusRTU client */ private createRTUClient; /** * Create and configure a TCP modbus-serial client. * Does NOT set slave ID - that's handled by SlaveTransport. * * @param config - TCP configuration * @returns Connected ModbusRTU client */ private createTCPClient; /** * Type guard to check if config is RTU * * @param config - Transport configuration * @returns True if RTU config */ private isRTUConfig; } //# sourceMappingURL=manager.d.ts.map