亚洲日韩中文字幕A∨,亚洲成a人v欧美综合天堂下载 ,日本亚洲欧洲无免费码在线 ,亲子乱子伦视频一区二区

iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享

2022年10月17日上午4:16

先轉(zhuǎn)發(fā),然后關(guān)注“大數(shù)據(jù)java架構(gòu)師”,私信“modbus”獲取源碼

easymodbus4j

easymodbus4j是一個(gè)高性能和易用的 Modbus 協(xié)議的 Java 實(shí)現(xiàn),基于 Netty 開發(fā),可用于 Modbus協(xié)議的Java客戶端和服務(wù)器開發(fā). 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 特點(diǎn):
1、Netty NIO high performance高性能.
2、Modbus Function sync/aync 同步/異步非阻塞。
3、Modbus IoT Data Connector Supports工業(yè)物聯(lián)網(wǎng)平臺(tái)IoT支持。
4、支持Modbus TCP\Modbus RTU protocol兩種通信協(xié)議.
5、靈活架構(gòu),支持8種生產(chǎn)部署模式,自由組合,滿足不同生產(chǎn)要求.
6、通用組件包,支持高度自定義接口.
7、完全支持Modbus TCP 4種部署模式: TCP服務(wù)器master,TCP客戶端slave,TCP服務(wù)器slave,TCP客戶端master。
8、完全支持Modbus RTU 4種部署模式: RTU服務(wù)器master,RTU客戶端slave,RTU服務(wù)器slave,RTU客戶端master。
9、友好的調(diào)試以及日志支持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協(xié)議
easymodbus4j-codec.jar  	Modbus 通用編碼器解碼器
easymodbus4j.jar        	Modbus General/Common公共通用包
easymodbus4j-client.jar 	Modbus client客戶端
easymodbus4j-server.jar 	Modbus server服務(wù)器端
easymodbus4j-extension.jar  Modbus extension擴(kuò)展包 ModbusMasterResponseProcessor/ModbusSlaveRequestProcessor interface
快速開發(fā)Quick Start:
步step1 ,import jar:
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 
      實(shí)現(xiàn)implement ResponseHandler接口 see easymodbus4j-example:ModbusMasterResponseHandler.java 
  or 實(shí)現(xiàn)implement ModbusMasterResponseProcessor 接口 use new ModbusMasterResponseHandler(responseProcessor); 
  
2.2 if slave 
    實(shí)現(xiàn)implement RequestHandler接口 see easymodbus4j-example:ModbusSlaveRequestHandler.java 
 or 實(shí)現(xiàn)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.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 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 file
4、start startup.bat.
5、you also can edit *.bat for modbus master/salve mode: .
說明:
1、解壓縮zip文件到文件夾
2java程序 運(yùn)行不了 則安裝jdk8.
3、解壓后8個(gè)bat文件  對(duì)應(yīng)TCP/RTU 服務(wù)器master,客戶端slave,服務(wù)器slave,客戶端master 8種模式.
4Master模式 可以設(shè)置autosend.txt文件,定時(shí)發(fā)送讀寫請(qǐng)求。
5、記事本打開bat文件可以編輯相關(guān)參數(shù),如定時(shí)延時(shí)發(fā)送時(shí)間以及詳細(xì)日志開關(guān)。

capture運(yùn)行效果圖截屏:


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享

物聯(lián)網(wǎng)平臺(tái)定制開發(fā)請(qǐng)私聊


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


iot物聯(lián)網(wǎng)云平臺(tái)基于netty的Modbus 協(xié)議的Java實(shí)現(xiàn)源碼免費(fèi)分享


先轉(zhuǎn)發(fā),然后關(guān)注“大數(shù)據(jù)java架構(gòu)師”,私信“modbus”獲取源碼

文章標(biāo)簽:
? ? 上一篇: ? ? ? 下一篇:

最新資訊