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
195 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 ] 

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

0 votes
by anonymous

Get your result without brackets and evaluate result with doublequote as number

Small example with modbus_tcp_test

if [[ "$(modbus_tcp_test 192.168.1.251 502 5 255 3 3000 1 16bit_uint_hi_first 1)" -gt "10" ]]; then

echo true;

fi

0 votes
by anonymous

The most common and widely used statement is the if statement. It will compute if a statement is true or false. If it's true, it will execute the code. If it's false, it won't execute the code. MyFiosGateway Verizon