I don’t have any documentation to give you, but I can assist you in resolving the issue you’ve encountered.
Firstly, the function code 4 stands for “Read Input Registers.” Since you mentioned that you want to read data, this number should be changed to 3. Here’s what the other numbers mean:
1: Read Coils
2: Read Discrete Inputs
3: Read Holding Registers
4: Read Input Registers
Additionally, make sure to set the “data_type” to the required format, as this could also affect reading from registers. If you still are encountering issues, please copy the command you are trying to execute and the error output too.
The Modbus RTU unit that I want to read is a Seneca 24DI and it answers to both function code 3 or function code 4. So the problem is not with the function code. But I tried as you suggested, still get the following:
call:
ubus call modbus_client serial.test ‘{“id”:4,“timeout”:1,“function”:3,“first_reg”:301,“reg_count”:“1”,“data_type”:“32bit INT, Byte order 1,2,3,4”,“no_brackets”:1,“serial_type”:“/dev/rs485”,“baudrate”:9600,“databits”:8,“stopbits”:1,“parity”:“None”,“flowcontrol”:“None”}’
answer:
{
"error": -1,
"result": "Failed to get response: No error information"
}
But if I try it from the WEBUI, it works! I also attached printscreens to show that it works from the WEBUI
Problem solved, instead of “data_type”:“32bit INT, Byte order 1,2,3,4”, “data_type”:“32bit_uint1234” should be used. For anyone that bumps into this problem, here is the solution. The available data types are the following:
If you use any of these data types, the ubus call will work. This can be checked in one of the source files of RUTOS sdk, namely in 03_modbus_serial_request.json.