formula input

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #4982
    bragofsky
    Participant

    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

    #4983
    manjey73
    Participant

    Judging 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 = i1||i2;
    return Convert.ToDouble(q);
    }

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

    • This reply was modified 5 years, 2 months ago by manjey73.
    #4985
    bragofsky
    Participant

    Hello,

    Thanks for your reply,

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

    #4986
    bragofsky
    Participant

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

    For a logical AND, is the same?

    #4987
    manjey73
    Participant

    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
    bragofsky
    Participant

    manjev73, thanks!

    #5005
    bragofsky
    Participant

    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
    Mikhail
    Moderator

    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
    bragofsky
    Participant

    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
    manjey73
    Participant

    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
    bragofsky
    Participant

    Like a charm again… thanks Manjey73 and Mikhail.

    Have a nice weekend

    #5015
    Mikhail
    Moderator

    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)

    • This reply was modified 5 years, 2 months ago by Mikhail.
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.