In this use case, the technicians on the project need to use a Modbus register as a watchdog function. In case the value goes lower than 350, the counter is written back to 500 to reset the counter. The idea is not to let the counter be 0, in which case it would mean that the device is not working properly.
The watchdog here is implemented on register %M1
. The route source and destination is the register %M1
. Make sure to also select the correct Modbus gateway. Once it is configured, open the blockly editor by clicking the small button in the Source Value parameter field (see screenshot below).
Once the blockly editor is opened, it is possible to edit the route function by drag & dropping and combining new function blocks. In this use case it is needed to return the value 500 if the counter %M1
is lower than 350. To do so it is possible to use the filter block combined with the compare block to ignore all values above or equal to 350. The compare block takes the %M1
counter value v and compares it to the constant number 350. The comparator used is < (lower than). So if v is lower than 350, than the compare block returns true and the filter blocks passes. The value returned by the filter is the contant value 500 that will reset the address %M1
to 500. The final function in code format is the following. Refer to the Routes functions manual for more information about the function editor.
filter(500,compare(v,"<",350))
The screenshot below shows in the blockly editor the visual diagram and its corresponding code filter(500,compare(v,"<",350))
.
Note that for programmers an alternative solution is to use the code below (pure javascript function). When the function returns null
, it means that the routing is canceled and does nothing.
function reset500(v){
if ( v < 350 ) {
return 500
}
else {
return null
}
}
It is also possible to use instead this condensed alternative using the Javascript arrow function expression and the ternary operator.
v => v < 350 ? 500 : null
The last step is to check that all the routes parameters are correct, check that the Source Value function is correct, and to save the route.
Once saved the route should appear in the routing table as shown below.