# modbus4j **Repository Path**: z81118x/modbus4j ## Basic Information - **Project Name**: modbus4j - **Description**: A high-performance and ease-of-use implementation of the Modbus protocol written in Java. Supports ASCII, RTU, TCP, and UDP transports as slave or master, automatic request partitioning and response d - **Primary Language**: Java - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: https://github.com/oliver225/modbus4j - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2025-02-09 - **Last Updated**: 2025-02-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README modbus4j ======== A high-performance and ease-of-use implementation of the Modbus protocol written in Java by Infinite Automation Systems and Serotonin Software. Supports ASCII, RTU, TCP, and UDP transports as slave or master, automatic request partitioning and response data type parsing. For support and general help please see our [Forum](https://forum.infiniteautomation.com/category/11/modbus4j-general-discussion) **Commercial licenses are available by contacting: sales@radixiot.com** A public Maven Repository is now available with the latest builds add this to your pom.xml ```xml false true ias-snapshots Infinite Automation Snapshot Repository https://maven.mangoautomation.net/repository/ias-snapshot/ true false ias-releases Infinite Automation Release Repository https://maven.mangoautomation.net/repository/ias-release/ ``` 根据当前项目结构和代码定义分析,modbus4j 项目架构主要分为以下核心模块: 1. 协议实现层(msg 包) * 完整实现了 Modbus TCP/RTU/ASCII 协议规范 * 包含所有标准功能码的消息处理(01-06,15-17,22-24 等) * 消息结构采用继承体系:ModbusMessage <- ModbusRequest/ModbusResponse 2. 传输层抽象(serial/ip 包) * 支持多种物理传输方式: * 串口通信(RTU/ASCII) * TCP/UDP 网络通信 * XA 事务处理 * 通过 MessageControl 实现消息队列管理 * 使用 EPoll 实现高效 IO 多路复用 3. 主从站实现(ModbusMaster/ModbusSlaveSet) * 主站特性: * 支持批量读取(BatchRead) * 节点自动扫描(NodeScanListener) * 连接池管理(SlaveProfile) * 从站特性: * 可配置过程映像(ProcessImage) * 支持监听寄存器写入事件(ProcessImageListener) 4. 数据建模(locator/value 包) * 提供类型化数据定位器(BaseLocator) * 支持多种数据类型: * 二进制量(BinaryLocator) * 数值量(NumericLocator) * 字符串(StringLocator) * 实现 Modbus 数据类型转换(DataType) 5. 异常体系(exception 包) * 分层异常处理: * 基础异常:ModbusTransportException * 协议异常:ErrorResponseException * 数据异常:IllegalDataAddressException * 初始化异常:ModbusInitException 项目特点: * 采用工厂模式(ModbusFactory)创建协议实例 * 通过 ProcessImage 抽象设备数据模型 * 支持同步/异步通信模式 * 提供扩展点:WaitingRoomKeyFactory、MessagingExceptionHandler * CDC 兼容实现(src_cdc 目录) 待改进点: * 缺乏单元测试覆盖(src_test 目录内容较少) * 依赖管理不明确(pom.xml 未展示依赖项) * 缺少文档注释(从方法列表看注释较少) * 线程模型可优化(MessageControl 的并发处理)