Skip to content

Commit 7259914

Browse files
authored
fix(transport): multiple devices on same bus use correct slave ID (#235)
Multiple devices sharing the same serial port were using the wrong slave ID because TransportManager pooled transports by connection key (excluding slave ID) and modbus-serial client had a static slave ID set once at creation time. Solution: SlaveTransport wrapper - Created SlaveTransport class that binds a slave ID to a shared client - TransportManager now pools modbus-serial clients (not Transport instances) - Each device gets its own SlaveTransport with its own slave ID - Slave ID is set before each operation within a mutex-protected context - Multiple devices on same bus share the same client and mutex Changes: - Add SlaveTransport class implementing Transport interface - Modify TransportManager to pool clients by physical connection - SlaveTransport sets slave ID before each operation - Shared mutex ensures serialized access across all slaves - Absorb retry logic into SlaveTransport - Add comprehensive documentation for shared resource ownership - Enable e2e test for multiple devices on same bus Tests: - Add comprehensive SlaveTransport tests (21 tests) - Update TransportManager tests for new architecture (17 tests) - All 1534 tests pass - E2E test validates multiple devices work correctly Closes #171
1 parent bc341ec commit 7259914

6 files changed

Lines changed: 970 additions & 194 deletions

File tree

packages/transport/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export { createModbusTransport } from './create-modbus-transport.js'
1212
export { withRetry, MAX_RETRIES, RETRY_DELAY_MS, type RetryLogger } from './retry.js'
1313
export { TransportManager, type TransportStats } from './manager.js'
1414
export { MutexTransport } from './mutex-transport.js'
15+
export { SlaveTransport } from './slave-transport.js'

0 commit comments

Comments
 (0)