MangoAutomation / modbus4j

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 data type parsing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

modbus tcp writeHoldingRegister offset over nine will occur exception

meitf opened this issue · comments

commented

I use modbus4j to create a tcp modbus slave, and want to write some datas into HoldingRegister, I use
/* com.serotonin.modbus4j.code.DataType
public static void writeHoldingRegister(int slaveId, int offset, Number value, int dataType)
throws ModbusTransportException, ErrorResponseException, ModbusInitException {
// 类型
BaseLocator locator = BaseLocator.holdingRegister(slaveId, offset, dataType);
tcpMaster.setValue(locator, value);
}*/

to write some float data, 1 float =2 registers=4 bytes , when the offset greater than nine, will occur exception,data cant not write into HoldingRegister,and response 01 90 02 CD C1,debug logs like below:

[17:46:55:113] [DEBUG] - com.serotonin.modbus4j.ip.tcp.TcpMaster.sendImpl(TcpMaster.java:156) - Response: 01 06 00 08 00 22 88 11
[17:46:55:115] [DEBUG] - com.serotonin.modbus4j.ip.tcp.TcpMaster.sendImpl(TcpMaster.java:137) - Encap Request: 01 10 00 09 00 02 04 42 3C 00 00 E7 B1
[17:46:55:115] [DEBUG] - com.serotonin.modbus4j.ip.tcp.TcpMaster.sendImpl(TcpMaster.java:142) - Sending on port: 502
HoldRrgister at 9 was set from 16956 to 16956

I don,t know why ,need help.

Hi meitf,

We prefer to provide support via our forum, https://forum.infiniteautomation.com

If you put the response bytes you have provided into an RTU decoder, you would see that it is an IllegalDataAddress response. This means the device is unwilling to provide that information, or that there is no register defined there in its schema.