FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

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

Hello,

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

Thanks

2 Answers

0 votes
by anonymous
Hi,

Regarding your question kindly check this link: https://mega.nz/file/OzhlGQbb#knVqT5J9UdDXxxDbP1o9tORjbR7aXiazq5rjLlySjUI

I hope this one will help you :)

Regards,
Jerome
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?

Thanks
0 votes
by anonymous
Hello,

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

Example

modbus_tcp_test 192.168.1.251 502 5 255 3 1 10 hex 1

Modbus TCP device (slave ID 255)

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

In Modbus RTU, after configuration of the gateway

modbus_tcp_test 127.0.0.1 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                                                                                                  

Usage:                                                                                                                                       

        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:                                                                                                                     

        8bit_int                                                                                                                             

        8bit_uint                                                                                                                            

        16bit_int_hi_first                                                                                                                   

        16bit_int_low_first                                                                                                                  

        16bit_uint_hi_first                                                                                                                  

        16bit_uint_low_first                                                                                                                 

        32bit_float1234                                                                                                                      

        32bit_float4321                                                                                                                      

        32bit_float2143                                                                                                                      

        32bit_float3412                                                                                                                      

        32bit_int1234                                                                                                                        

        32bit_int4321                                                                                                                        

        32bit_int2143                                                                                                                        

        32bit_int3412                                                                                                                        

        32bit_uint1234                                                                                                                       

        32bit_uint4321                                                                                                                       

        32bit_uint2143                                                                                                                       

        32bit_uint3412                                                                                                                       

        hex                                                                                                                                  

        ascii
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":"192.168.1.11", "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":"192.168.1.11", "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}'

Bzzzzt

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":"192.168.1.11", "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