easymodbus4j 0.0.5 發布,修復更新

←手機掃碼閱讀     admin @ 2019-10-21 , reply:0

easymodbus4j 0.0.5 發布,修復更新

0.0.4 rtu協議模式下 有多處bug,建議全部升級至0.0.5版本。

更新如下:

1、日誌統一調整。

2、rtu 修復 req resp同步更新bug。

3、新增debug調試多處關鍵性日誌。

4、正負數bug修復。

5、rtu協議模式下 讀寫鎖bug修復 以及性能優化。

 

 

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:
<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, 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文件到文件夾
2、java程序 運行不了 則安裝jdk8.
3、解壓后8個bat文件  對應TCP/RTU 伺服器master,客戶端slave,伺服器slave,客戶端master 8種模式.
4、Master模式 可以設置autosend.txt文件,定時發送讀寫請求。
5、記事本打開bat文件可以編輯相關參數,如定時延時發送時間以及詳細日誌開關。

capture運行效果圖截屏: easymodbus4j運行效果圖截屏1 easymodbus4j運行效果圖截屏2 easymodbus4j運行效果圖截屏3 easymodbus4j運行效果圖截屏4

 





[admin ]

來源:OsChina
連結:https://www.oschina.net/news/110727/easymodbus4j-0-0-5-released
easymodbus4j 0.0.5 發布,修復更新已經有32次圍觀

http://coctec.com/news/soft/show-post-217336.html