# formula input

Viewing 12 posts - 1 through 12 (of 12 total)
• Author
Posts
• #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.

Regards

#4983

Judging by the logic you want to get logical OR ?

public double OR(double in1, double in2)
{
bool q = false;
bool i1 = in1 > 0;
bool i2 = in2 > 0;
q = i1||i2;
return Convert.ToDouble(q);
}

Use in channel OR(Val (n), Val(m))

#4985

Hello,

“Add formula to formula table” you mean the formula.dat or the calcengine.cs?

#4986

Hello again, I already managed to edit formula table and it works great.

For a logical AND, is the same?

#4987

Logical 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);
}

#4988

manjev73, thanks!

#5005

Hello,

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.

#5006

Hi,
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.

#5007

Thanks 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

#5008

Divide 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);
}``````
#5009

Like a charm again… thanks Manjey73 and Mikhail.

Have a nice weekend

#5015

Works 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)

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.