subscribe to our Youtube


14455 questions

17168 answers


0 members

We are migrating to our new platform at Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
1,080 views 2 comments
by anonymous


I'm looking for an example of a bash script line to execute a Modbus RTU read request to a slave.


2 Answers

0 votes
by anonymous

Regarding your question kindly check this link:

I hope this one will help you :)

Best answer
by anonymous
Great, thank you for your answer

I have another question:

I have enabled router as Modbus TCP Slave (Network -> Modbus -> Modbus TCP Slave);

and enabled Custom Register Block in the webUI from (40000 to 41000)

and enabled Router as Modbus serial master to read slaves via RS485.

Can I store the RTU registers in the Custom Register Block and access them via Modbus TCP, or in other words can I forward the RTU registers to the TCP custom registers?

0 votes
by anonymous

For Modbus TCP, I use modbus_tcp_test

For Morbus RTU, I use the same thing after setting the Modbus Gateway function, which allows to translate the Modbus TCP request into Modbus RTU directly


modbus_tcp_test 502 5 255 3 1 10 hex 1

Modbus TCP device (slave ID 255)

Reading from %MW1 to %MW10 on IP, Device ID 255, presentation of the result in hexa

In Modbus RTU, after configuration of the gateway

modbus_tcp_test 502 5 2 3 1 10 hex 1

Execute %MW1 %MW10 on the local address of the gateway, Modbus RTU slave ID 2, result in hex

root@Teltonika-TRB245:~# modbus_tcp_test -h                                                                                                  


        modbus_tcp_test IP PORT TIMEOUT SLAVE_ID FUNCTION REG_ADDRESS REG_COUNT/VALUE(S) DATA_TYPE NO_BRACKETS                               

DATA_TYPE may be one of:                                                                                                                     




















by anonymous

any idea about the function 6 and 16 write register syntax for modbus_tcp_test
which as of 7.03.02 has been supplanted with a hyper-verbose rendition like this:
ubus call modbus_master tcp.test '{"ip":"", "port":502, "id":1, "timeout":1, "function":3, "first_reg":10006, "reg_count":"6", "data_type":"16bit_uint_hi_first", "no_brackets":1}'

It appears that in the new "self-documenting" variant, the parameters are no longer positional
they can appear in any order - and can even be repeated/duplicated without ill effect

To do the write I attempted this:

ubus call modbus_master tcp.test '{"ip":"", "port":502, "id":1, "timeout":1, "function":16, "first_reg":10007, "reg_count":"7", "data_type":"16bit_uint_hi_first", "modbus_write_registers":3,4,5,6,7 "no_brackets":1}'


For a minute I thought I had something because the "failed to parse message data" error went away

ubus call modbus_master tcp.test '{"ip":"", "port":502, "id":1, "timeout":1, "function":16, "first_reg":10007, "reg_count": "7", "data_type":"16bit_uint_hi_first", "no_brackets":1, "garbage":1}'

other weirdnesses: some numerics such as port id timeout function are naked - no " around them

while "reg_count" requires " quoting

IDK... where to get docs for undoc-ed code ?

OK... I figured out that modbus_write_register and modbus_write_regsters are libmodbus library functions