Sending data to serial modbus using CLI on TRB145

Hi

This is a follow up on

Basically i need to send data and request data from a connected serial modbus device, but i am having some issues. Summary of the previous post is that the devices requires triggering to take a reading, but this causes occasional collisions when using the UI services to do this.

I was reccomended to write a script, but i am unable to get it to work in the cli.

There are several modbus devices (sensors) connected to the trb145. I have set it up in the user interface and it works fine (details below)
image

device created


device details
image
slave devices (there are more, but these are the ones being tested)

Trigger slave details


This works fine when tested

read slave details (using ConductivityTemperature as example)


All of these works fine when testing here

I have tried to follow the instructions i have found (primarily here: TRB245 Modbus RTU registers)

I ended up with the following command for triggering a measurement
ubus call modbus_master serial.test "{'serial_type': '/dev/rs485', 'baudrate': 9600, 'databits': 8, 'stopbits': 1, 'parity': 'None', 'flowctrl': 'None', 'timeout': 5, 'id': 30, 'function': 6, 'first_reg': 2, 'reg_count': '31', 'data_type': '16bit_int_hi_first', 'no_brackets': 1}"

and the following command for reading
ubus call modbus_master serial.test "{‘serial_type’: ‘/dev/rs485’, ‘baudrate’: 9600, ‘databits’: 8, ‘stopbits’: 1, 'parity': 'None', 'flowctrl': 'None', 'timeout': 5, 'id': 30, 'function': 3, 'first_reg': 83, 'reg_count': '2', 'data_type': '32bit_float4321', 'no_brackets': 1}"

a couple of important notes

when i run the commands i get failed to create mb context

Other things done to check that everything is running
result of ubus list command (note modbus_master doesn’t show up unless a modbus slave device has been set in the UI)
image

Checking if the rs485 in /dev/ is there

What could be wrong in this instance?

Best wishes
Larks

Hello Larks
Could you try with this syntax instead ,

ubus call modbus_master serial.test '{"id":1,"timeout":10,"function":3,"first_reg":1,"reg_count":"2","data_type":"32bit UINT, Byte order 1,2,3,4","no_brackets":0,"serial_type":"rs485","baudrate":9600,"databits":8,"stopbits":1,"parity":"None","flowcontrol":"None"}'

the syntax being

{“id”:“Integer”,“timeout”:“Integer”,“function”:“Integer”,“first_reg”:“Integer”,“reg_count”:“String”,“data_type”:“String”,“no_brackets”:“Integer”,“ip”:“String”,“port”:“String”,“delay”:“Integer”}

Could you please try with the above syntax, also let us run a test on the similar setup as your’s and get back to you

Thanks

I did this command (serial_type: “rs485”, first_reg:83)
ubus call modbus_master serial.test '{"id":30,"timeout":10,"function":3,"first_reg":83,"reg_count":"2","data_type":"32bit UINT, Byte order 1,2,3,4","no_brackets":0,"serial_type":"rs485","baudrate":9600,"databits":8,"stopbits":1,"parity":"None","flowcontrol":"None"}'
But got could not find serial device

I also tried changing the serial_type to “/dev/rs485” and got the same error as before.

Hi
I was able to get the command working now. I just updated the firmware to the latest one. The service changed name from modbus_master to modbus_client though.

I do face another issue now however. I am unable to install jq which is mentioned in the guides linked to me using opkg.
Running opkg update and then opkg install jq gives me

Unknown package 'jq'.
Package installation encountered an error, removing previously installed packages.

It seems like the list of available packages (http://opkg.teltonika-networks.com/958358e447f9ce69b8da6bc53078dec7d3fe23c03a3978d26e0634420a08c337/Packages.gz) doesn’t contain it. It also doesn’t have nano.

Hello

Sorry for the delayed answer

The Way to install opkg has a small update in our newest firmware, could you try to install with the following way

opkg update
opkg -e /etc/opkg/openwrt/distfeeds.conf update
opkg -e /etc/opkg/openwrt/distfeeds.conf install jq

Let us know if this works for you .

Thanks

Hi

Thanks this is good to know. Is this install method documented anywhere?

I ended up using Python for the handling of the string parsing, but this will be good for devices that don’t support Python like RUT241 that i have a few of as well. I haven’t been able to test the device that had this issue (FW TRB1_R_00.07.06.2) as it is in the field now and the other devices i have have slightly different FW (TRB1_R_00.07.05.4).

This topic was automatically closed after 15 days. New replies are no longer allowed.