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
209 views 0 comments
by anonymous

I create a custom script to read Modbus slaves and then control them with this script:

------------------------------------------------------------------

#!/bin/ash

Temp=3

GSt=1

 while true

 do

Temp=$(modbus_serial_request_test rs485 1 1 4 8 1 16bit_int_hi_first 0)

GSt=$(modbus_serial_request_test rs485 1 1 4 1 1 16bit_uint_hi_first 0)

 if [ $GSt -gt 10 ] #wenn die Strahlung gro..er als 10

then

modbus_serial_request_test rs485 1 2 5 1281 65280 16bit_uint_hi_first 0

 else

modbus_serial_request_test rs485 1 2 5 1283 65280 16bit_uint_hi_first 0

fi


 sleep 2

 done

---------------------------------------------------------------------------------

But when I retrieve a value from the Modbus slave and store it in a variable, it is stored in the form [20]. So the If statement could not read this value and the result was " [20] is out of range".

it should be only 20, without [ ].

Is there any solution for this problem?

2 Answers

+1 vote
by anonymous

Hello,

Please note that "modbus_serial_request_test rs485 1 1 4 8 1 16bit_int_hi_first 0", Here "0 or 1" is used for "Brackets or No Brackets" respectively. So it will have to be "modbus_serial_request_test rs485 1 1 4 8 1 16bit_int_hi_first 1".

The required script is given below.

------------------------------------------------------------------

#!/bin/ash

Temp=3

GSt=1

 while true

 do

Temp=$(modbus_serial_request_test rs485 1 1 4 8 1 16bit_int_hi_first 1)

GSt=$(modbus_serial_request_test rs485 1 1 4 1 1 16bit_uint_hi_first 1)

 if [ $GSt -gt 10 ] #wenn die Strahlung gro..er als 10

then

modbus_serial_request_test rs485 1 2 5 1281 65280 16bit_uint_hi_first 1

 else

modbus_serial_request_test rs485 1 2 5 1283 65280 16bit_uint_hi_first 1

fi


 sleep 2

 done

---------------------------------------------------------------------------------

Regards,

Clive Pinto

Best answer
0 votes
by anonymous
Hello,

have you tried to enable "No Brackets" on the Modbus TCP Master page? You can find this setting if you update your device to the latest firmware.