Knowledgebase
* > eze System - Help Desk > Knowledgebase

Search help:


Adding and subtracting input values

Solution

You can easily add inputs together and assign the result to a 'software' input.

First you need to define the input where we will put the result. That input needs to be set to the Special/Software type under Configure->Input->Input Location.

This will allow the script and API functions to control the raw value of this input. To assign a value to the input from your script, use the function SetInputValue( INPUT#, VALUE );

For example:

SetInputValue( 8, 123 );

will set input 8 to the value 123. To read the value from an input, use the function GetInputValue ( INPUT# ); For example:

SetInputValue ( 8, GetInputValue(1) );

will make input 8 show the same value as input 1. To add two inputs together, simply do this:

SetInputValue( 8, GetInputValue(1) + GetInputValue(2) );

This will add the raw value from input 1 and the raw value from input 2 and put the sum in input 8. You can also use a variable to do the calculations separately:

new mysum = 0;
mysum += GetInputValue(1);
mysum += GetInputValue(2);
SetInputValue( 8, mysum );

Finally, to make this update continuously, you want to put the code inside the @Tick function in your script. The @Tick function is called by the system every second, so by placing your code inside that function you will make sure your inputs are always updated. Here's a complete script that assigns calculated values to input 8 and 9:

@Tick(uptime) {
   new mysum = 0;
   mysum += GetInputValue(1);
   mysum += GetInputValue(2);
   SetInputValue( 8, mysum );
   SetInputValue( 9, mysum - GetInputValue(3) );
}

 

 
Was this article helpful? yes / no
Related articles Monitoring run time
Counter value as input value
Input #1 deleteted by accident
Communicating input value to a different ezeio
Measuring 0-50V
Article details
Article ID: 2
Category: ezeio script programming
Rating (Votes): Article rated 3.0/5.0 (4)

 
« Go back