• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

easymodbus4j是一个高性能和易用的 Modbus 协议的 Java 实现,基于 Netty 开发,可用于 Modbus协议的Java客户端和服务器开发, A high-performance and ease-of-use implementation of the Modbus protocol written in Java netty support for modbus 4 mode..

easymodbus4j运行效果图截屏

easymodbus4j [chs]

easymodbus4j是一个高性能和易用的 Modbus 协议的 Java 实现,基于 Netty 开发,可用于 Modbus协议的Java客户端和服务器开发.

easymodbus4j [en]

A high-performance and ease-of-use implementation of the Modbus protocol written in Java netty support for modbus 8 mode client/server and master/slave.

easymodbus4j features 特点:

  • 1、Netty NIO high performance高性能.
  • 2、Modbus Function sync/aync 同步/异步非阻塞。
  • 3、Modbus IoT Data Connector Supports工业物联网平台IoT支持。
  • 4、支持Modbus TCP\Modbus RTU protocol两种通信协议.
  • 5、灵活架构,支持8种生产部署模式,自由组合,满足不同生产要求.
  • 6、通用组件包,支持高度自定义接口.
  • 7、完全支持Modbus TCP 4种部署模式: TCP服务器master,TCP客户端slave,TCP服务器slave,TCP客户端master。
  • 8、完全支持Modbus RTU 4种部署模式: RTU服务器master,RTU客户端slave,RTU服务器slave,RTU客户端master。
  • 9、友好的调试以及日志支持bit\bitset\byte\short\int\float\double。
  • 10、Supports Function Codes:
    • Read Coils (FC1)
    • Read Discrete Inputs (FC2)
    • Read Holding Registers (FC3)
    • Read Input Registers (FC4)
    • Write Single Coil (FC5)
    • Write Single Register (FC6)
    • Write Multiple Coils (FC15)
    • Write Multiple Registers (FC16)
    • Read/Write Multiple Registers (FC23)

repositories

artifactId/jar:
easymodbus4j-core.jar   	Modbus protocol协议
easymodbus4j-codec.jar  	Modbus 通用编码器解码器
easymodbus4j.jar        	Modbus General/Common公共通用包
easymodbus4j-client.jar 	Modbus client客户端
easymodbus4j-server.jar 	Modbus server服务器端
easymodbus4j-extension.jar  Modbus extension扩展包 ModbusMasterResponseProcessor/ModbusSlaveRequestProcessor interface

quick Start快速开发:

第一步step1 ,import jar:

  • 1.1 maven:
     <dependency>
     <groupId>com.github.zengfr</groupId>
     <artifactId>easymodbus4j-client</artifactId>
     <version>0.0.5</version>
     </dependency>
     <dependency>
     <groupId>com.github.zengfr</groupId>
     <artifactId>easymodbus4j-server</artifactId>
     <version>0.0.5</version>
     </dependency>
     <dependency>
     <groupId>com.github.zengfr</groupId>
     <artifactId>easymodbus4j-extension</artifactId>
     <version>0.0.5</version>
     </dependency>
    

第二步step2,implement handler:

  • 2.1 if master
    • 实现implement ResponseHandler接口 see easymodbus4j-example:ModbusMasterResponseHandler.java
    • or 实现implement ModbusMasterResponseProcessor 接口 use new ModbusMasterResponseHandler(responseProcessor);
  • 2.2 if slave
    • 实现implement RequestHandler接口 see easymodbus4j-example:ModbusSlaveRequestHandler.java
    • or 实现implement ModbusSlaveRequestProcessor 接口 use new ModbusSlaveRequestHandler(reqProcessor);

第三步step3,

  • 3.1 select one master/slave and client/server mode:
     modbusServer = ModbusServerTcpFactory.getInstance().createServer4Master(port, responseHandler);
     modbusClient = ModbusClientTcpFactory.getInstance().createClient4Slave(host,port, requestHandler);
    
     modbusClient = ModbusClientTcpFactory.getInstance().createClient4Master(host, port, responseHandler);
     modbusServer = ModbusServerTcpFactory.getInstance().createServer4Slave(port, requestHandler);
    
     modbusServer = ModbusServerRtuFactory.getInstance().createServer4Master(port, responseHandler);
     modbusClient = ModbusClientRtuFactory.getInstance().createClient4Slave(host,port, requestHandler);
    
     modbusClient = ModbusClientRtuFactory.getInstance().createClient4Master(host, port, responseHandler);
     modbusServer = ModbusServerRtuFactory.getInstance().createServer4Slave(port, requestHandler);

第四步step4 ,FAQs and advanced extensions:

  • 4.1 how to send a request ? to send data

     Thread.sleep(3*1000);// sleep 3s before,when client or server open connection is async;
     Channel  channel =  client.getChannel());
     Channel  channel =  server.getChannelsBy(...));
     ChannelSender sender = ChannelSenderFactory.getInstance().get(channel);
     ChannelSender sender2 = new ChannelSender(channel,unitId,protocolIdentifier);
     sender.readCoils(...)
     sender.readDiscreteInputs(...)
     sender.writeSingleRegister(...)
  • 4.2 how to process request/response? to receive data see code in processResponseFrame mothod in ModbusMasterResponseHandler.java or ModbusMasterResponseProcessor.java

     public void processResponseFrame(Channel channel, int unitId, AbstractFunction reqFunc, ModbusFunction respFunc) {
     		if (respFunc instanceof ReadCoilsResponse) {
     			ReadCoilsResponse resp = (ReadCoilsResponse) respFunc;
     			ReadCoilsRequest req = (ReadCoilsRequest) reqFunc;
     			//process business logic for req/resp
     		}
     };
  • 4.3 how to get response to byteArray for custom decode by yourself? see code in processResponseFrame mothod in ModbusMasterResponseHandler.java or ModbusMasterResponseProcessor.java

    public void processResponseFrame(Channel channel, int unitId, AbstractFunction reqFunc, ModbusFunction respFunc) {
    		if (respFunc instanceof ReadDiscreteInputsResponse) {
    			ReadDiscreteInputsResponse resp = (ReadDiscreteInputsResponse) respFunc;
    			byte[] resutArray = resp.getInputStatus().toByteArray();
    		}
    };	
  • 4.4 how to show log? see ModbusMasterResponseHandler.java in example project.

     ModbusFrameUtil.showFrameLog(logger, channel, frame);
  • 4.5 how to custom a client/server advance by yourself?

     ModbusChannelInitializer modbusChannelInitializer=...;
     ModbusServerTcpFactory.getInstance().createServer4Master(port,modbusChannelInitializer);

Example Project Code

Example run startup:

  • 1、unzip file easymodbus4j-example-0.0.5-release.zip.
  • 2、for modbus master mode:open autosend.txt file in dir or autosend.txt rsourcefile in easymodbus4j-example-0.0.5.jar
  • 3、for modbus master mode:edit autosend.txt file
  • 4、start startup.bat.
  • 5、you also can edit *.bat for modbus master/salve mode: .

Example实例说明:

  • 1、解压缩zip文件到文件夹
  • 2、java程序 运行不了 则安装jdk8.
  • 3、解压后8个bat文件 对应TCP/RTU 服务器master,客户端slave,服务器slave,客户端master 8种模式.
  • 4、Master模式 可以设置autosend.txt文件,定时发送读写请求。
  • 5、记事本打开bat文件可以编辑相关参数,如定时延时发送时间以及详细日志开关。

开发实例系列教程Develop a series of tutorial examples

easymodbus4j 开发实例系列教程之1----客户端master模式
easymodbus4j 开发实例系列教程之2----服务端master模式

capture demo 运行效果图截屏:

easymodbus4j运行效果图截屏1 easymodbus4j运行效果图截屏2 easymodbus4j运行效果图截屏3 easymodbus4j运行效果图截屏4

capture demo 运行效果图截屏2:

easymodbus4j运行效果图截屏1 easymodbus4j运行效果图截屏2 easymodbus4j运行效果图截屏3 easymodbus4j运行效果图截屏4

More Repositories

1

stepchain

stepchain 通用业务流程流水线处理框架。 类似于Commons Chain和Commons Pipeline这样的Java Pipeline Step Chain用于组织复杂处理流程执行的流行技术. Java Pipeline Step Chain like Apache Commons Chain and Commons Pipeline.A popular technique for organizing the execution of complex processing flows is the "Chain of Responsibility" pattern
Java
64
star
2

romhack

rom hack for Arcade mame mess sfc snes sega md neogeo romhacking
JavaScript
36
star
3

easymqtt4j

easymqtt4j , netty +mqtt +subscriber+ publisher +broker+cluster server for java
Java
11
star
4

SVM-Neuro-Matching

SVM Neuro Matching C#机器学习 LibSVM支持向量机 神经网络 匹配 中文文本分词分类聚类
C#
9
star
5

arcade_game_romhacking_sourcecode_top_secret_data

arcade_game_romhacking_sourcecode_top_secret_datafor mess sfc snes sega md geoneo data asm mame m68k m68000 cps1 capcom rom assember
Assembly
9
star
6

conuniframework-util

conuniframework-util Super Commons-Integration commons and utils all in one.最强工具util集合集成,只有最强,没有更强.
Java
7
star
7

ida-pro-idb-database

many of ida pro idb database for game hacking and reverse analysis engineering.good luck.
Python
6
star
8

datasource-spring-boot-starter

datasource-spring-boot-starter. AbstractRoutingDataSource dynamic datasource for springboot,Multiple &Routing&Sharding&RW&Master Slave
Java
5
star
9

free-vpn-subscribe

free-vpn-subscribe.Shadowsocks, ShadowsocksR, Trojan, Vmess, Vless
4
star
10

frida-codeshare-scripts

frida-codeshare-scripts.collection of useful FRIDA scripts.A curated list of Frida resources.
JavaScript
4
star
11

HttpRpcServer

httpRpcServer is a java httpServer for Rpc use via Netty always use remote control in crawler or spider send command le pppoestart pppoestop 。
Java
4
star
12

HexRaysCodeXplorer_plugin_for_ida_pro

Hex-Rays Decompiler plugin for better code navigation. plugin for IDA Pro.
C++
3
star
13

ArmBian_AMLOGIC_DESKTOP

FORK_Amlogic_S9XXX_ARMBIAN
Shell
3
star
14

arcade-romhacking-framework

arcade-romhacking-framework for cps1 neogeo pgm 68k 68000
Assembly
3
star
15

short-video-to-attract-customers

short video to attract customers 短视频平台获客引流系统 youtube&instagram&snapchat&houseparty&vimeo&tiktok&more
2
star
16

home

home
JavaScript
2
star
17

winhex_diff_viewer-plugin-for-ida-pro

winhex_diff_viewer plugin for ida pro .IDA Plugin.
2
star
18

ida_all_xrefs_to_viewer-plugin-for-ida-pro

ida_all_xrefs_to_viewer-plugin-for-ida-pro,ida plugin
2
star
19

flutter-sample-by-zengfr

flutter sample by zengfr
Dart
1
star
20

spring-navel

Spring Navel
1
star
21

zengfr

1
star
22

conuniframework-cloud

conuniframework-cloud
Java
1
star
23

Apache-Commons-.NET

Apache Commons .NET using IKVM http://commons.apache.org/
C#
1
star
24

conuniframework-iot

conuniframework-iot
1
star
25

conuniframework-flutter

conuniframework-flutter
1
star
26

conuniframework-Ionic

conuniframework-android
1
star
27

NextFramework

NextFramework
1
star
28

zengfr.github.io

zengfr blog
TypeScript
1
star
29

armbian-ubuntu-scripts

armbian-ubuntu-scripts.Support for Armbian in Amlogic, Rockchip and Allwinner boxes.
Shell
1
star
30

ProtocolX

ProtocolX
1
star
31

ida_all_xrefs_from_viewer-plugin-for-ida-pro

ida_all_xrefs_from_viewer-plugin-for-ida-pro , ida plugin.
1
star
32

union-openplatform-sdk

整合淘宝、拼多多、京东、唯品会、抖音、快手等开放平台的SDK,抹除各个平台间的差异,提供了统一的API
1
star
33

LinkedIn-Bulk-Connect-BatchAddFriend

LinkedIn-Bulk-Connect-BatchAddFriend www.linkedin.com linkedin批量自动添加好友联系人工具
JavaScript
1
star