This script reads the value of the given input Data Item, make some mathematical operations ( sqrt, round ), and than compare it with the max value saved as global variable. If this max value is exceeded, a warning text is shown, and new max value is set.
First, new global variable called g_max is created, to store the max value:
|
Second, a new Script Item called Watch is created. Than add new JS variable, set name to input, and set Item Path to the data item, that we want to watch.
|
And the script :
// watch given input, modify it, and if it is higher than
|
// max value, show message, and set new max value
|
function OnItemRead_Watch(input)
|
{
|
var RetVal;
|
|
// examples of mathematical operations
|
var v = Math.sqrt(input);
|
var r = Math.round(v);
|
|
// compare with max value
|
if ( r > g_max )
|
{
|
// if max value exceeded, show warning, and set new max
|
RetVal = "MAX VALUE EXCEEDED";
|
g_max = r;
|
} else {
|
// else everything OK
|
RetVal = "VALUE IN RANGE";
|
}
|
|
return RetVal;
|
}
|
Send feedback on this topic.
Copyright © 2004-2013, SAE - Automation, s.r.o. (Ltd.), All rights reserved.