Forum Home › Forums › Understanding the Software › Using Formulas › formula input
This topic contains 11 replies, has 3 voices, and was last updated by Mikhail 9 months, 2 weeks ago.

AuthorPosts

February 11, 2019 at 3:25 pm #4982
Hello, with this formula Val(n) + Val(n), where n is the input channel, I managed to get my item working in 75%. All the conditions are working 0+0=0, 0+1=1 and 1+0=1, The only state that is missing is the 1+1=undefined. It’s supose to be 1 but I get nothing.
Help please
Regards
February 12, 2019 at 9:54 am #4983Judging by the logic you want to get logical OR ?
Add formula to formula table
public double OR(double in1, double in2)
{
bool q = false;
bool i1 = in1 > 0;
bool i2 = in2 > 0;
q = i1i2;
return Convert.ToDouble(q);
}Use in channel OR(Val (n), Val(m))
 This reply was modified 9 months, 3 weeks ago by manjey73.
February 12, 2019 at 10:37 am #4985Hello,
Thanks for your reply,
“Add formula to formula table” you mean the formula.dat or the calcengine.cs?
February 12, 2019 at 11:20 am #4986Hello again, I already managed to edit formula table and it works great.
For a logical AND, is the same?
February 12, 2019 at 11:33 am #4987Logical And
public double AND(double in1, double in2)
{
bool q = false;
bool i1 = in1 > 0;
bool i2 = in2 > 0;
q = i1&&i2;
return Convert.ToDouble(q);
}February 12, 2019 at 4:33 pm #4988manjev73, thanks!
February 15, 2019 at 12:34 pm #5005Hello,
I have another issue
I need to create a input to Station status to be showed in map, this input should behave like a or gate, my problem is with a OR formula in input channel, I can only put 2 inputs, when I put the third webstation stop’s working. I need to monitor 22 input’s to get the station status.
The formula i’m using is “OR(Val(1001), Val(1002), Val(1003))” but server returns a error saying that OR cannot deal with 3 variables.
February 15, 2019 at 1:43 pm #5006Hi,
Try the formula like that:public double OR(params double[] inputs) { foreach (double input in inputs) { if (input > 0) return 1; } return 0; }
Note: I don’t test formulas on the forum. In case of error, please provide error message from the Server log.
February 15, 2019 at 3:45 pm #5007Thanks Mikhail,
Works like a charm but I’m limited to 100 symbols in formula input. Is there a way to add a range of input channels inside the OR gate formula?
Another question, how can I change the value of an input? with a NOR?
Regards
February 15, 2019 at 6:32 pm #5008Divide formulas into several channels. If the formula returns double, you can use one formula inside another.
for example
NOT(OR(Val(100), Val(101)))
public double NOT(double val) { bool boolVal = val > 0; return Convert.ToDouble(!boolVal); }
February 16, 2019 at 12:31 am #5009Like a charm again… thanks Manjey73 and Mikhail.
Have a nice weekend
February 18, 2019 at 6:10 am #5015Works like a charm but I’m limited to 100 symbols in formula input.
To shorten, try this:
public double OR(params int[] cnlNums) { foreach (int cnlNum in cnlNums) { if (Val(cnlNum) > 0 && Stat(cnlNum) > 0) return 1; } return 0; }
Example of formula using is OR(1,2,3,4,5)
 This reply was modified 9 months, 2 weeks ago by Mikhail.

AuthorPosts
You must be logged in to reply to this topic.