返回列表 发新帖

[科技] iot物联网云平台基于netty的Modbus 协议的Java实现源码免费分享

[复制链接]

24

主题

24

帖子

48

积分

耍耍新手

Rank: 1

积分
48
发表在  2020-1-14 09:59:19 | 显示全部楼层 | 阅读模式
先转发,然后关注“大数据java架构师”,私信“modbus”获取源码

easymodbus4j

easymodbus4j是一个高性能和易用的 Modbus 协议的 Java 实现,基于 Netty 开发,可用于 Modbus协议的Java客户端和服务器开发. easymodbus4j 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 特点: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)#Example Project Code in https://github.com/zengfr/easymodbus4j
Repositories Central Sonatype Mvnrepository easymodbus4j
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:maven:com.github.zengfreasymodbus4j-client0.0.5com.github.zengfreasymodbus4j-server0.0.5com.github.zengfreasymodbus4j-extension0.0.5第二步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, select one master/slave 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:4.1 how to send a request ?Channel  channel =  client.getChannel());Channel  channel =  server.getChannelsBy(...));ChannelSender sender = ChannelSenderFactory.getInstance().get(channel);sender.readCoils(...)sender.readDiscreteInputs(...)sender.writeSingleRegister(...)4.2 how to process request/response?see code in processResponseFrame mothod in  ModbusMasterResponseHandler.java or ModbusMasterResponseProcessor.javapublic 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.javapublic 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 master/easymodbus4j-example/src/main/java/com/github/zengfr/easymodbus4j/example
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 file4、start startup.bat.5、you also can edit *.bat for modbus master/salve mode: .说明:1、解压缩zip文件到文件夹2、java程序 运行不了 则安装jdk8.3、解压后8个bat文件  对应TCP/RTU 服务器master,客户端slave,服务器slave,客户端master 8种模式.4、Master模式 可以设置autosend.txt文件,定时发送读写请求。5、记事本打开bat文件可以编辑相关参数,如定时延时发送时间以及详细日记开关。capture运行效果图截屏:


100204k0g7pc05goggbg24.jpg





100204ohlusgyutbsksqsg.jpg





100205hogkw42oh4t8h5gw.jpg





100205xlrp9phbipl7peog.jpg



物联网平台定制开发请私聊


100205d6zz2imn2p6nlwbn.jpg





100205csvsbvydwkus33q2.jpg





100206s050owd9sgdltyzb.jpg





先转发,然后关注“大数据java架构师”,私信“modbus”获取源码


声明:信息来源于主流新闻平台,如有侵权联系管理员删除(我爱旅游网 www.cysua.com)。
回复

使用道具 举报

13

主题

73

帖子

86

积分

铁牌耍客

Rank: 2

积分
86
发表于 2020-1-14 13:22:27 来自手机  | 显示全部楼层
为保住菊花,这个一定得回复!
回复

使用道具 举报

19

主题

66

帖子

85

积分

铁牌耍客

Rank: 2

积分
85
发表于 4 天前 | 显示全部楼层
顶顶更健康
回复

使用道具 举报

21

主题

84

帖子

105

积分

铁牌耍客

Rank: 2

积分
105
发表于 昨天 08:21 | 显示全部楼层
沙发位出租,有意请联系
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表