$ show MangoAutomation/modbus4j
modbus4j is a Java library implementing the Modbus protocol (ASCII, RTU, TCP, UDP) for industrial automation. It provides both master (client) and slave (server) functionality, supporting standard function codes (read/write coils, discrete inputs, holding/input registers, mask write) and a wide range of data types including BCD, floats, and custom swapped variants. The architecture is modular with separate transport layers, a generic messaging framework (MessageControl, WaitingRoom, Transport), and locator-based high-level access. The library includes a process image simulation for slave devices and batch read capabilities. It was originally developed for Mango Automation and has a parallel Java 1.4 backport (src_cdc) that indicates aging. The codebase shows good separation of concerns and reusable patterns but suffers from technical drift (RXTX dependency, manual byte manipulation, outdated build tools) and lack of modern testing infrastructure.
The LLM identified 3 files worth highlighting for reuse:
Implements a generic bidirectional messaging control with retry, timeout, and request/response correlation using a WaitingRoom pattern. It is transport-agnostic and can be extracted for any protocol that requires synchronous request-response matching over streams. Demonstrates clean separation of concerns with pluggable parsers, transports, and waiting room key factories.
A reusable circular byte buffer with push, pop, peek, mark/reset, and hex string conversion. Used extensively for message building and parsing. Self-contained and could be extracted into any Java project needing efficient byte-level FIFO operations.
Static utility methods for I/O operations including stream transfer, reading, writing, and hex dump formatting. Provides a clean, reusable set of helpers for byte-level I/O that can be extracted independently.