simple Formula that compares an Integer or real and returns Boolean

Forum Home Forums Development and Integration simple Formula that compares an Integer or real and returns Boolean

Tagged: 

  • This topic has 6 replies, 4 voices, and was last updated 1 year ago by TDE.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #6551
    Hennie_Kotze
    Participant

    Good Day,

    Please give me a simple formula that will compare one real value with an Integer, and return the “Calculated Discrete” channel as ON or OFF.

    I read a real value into channel 60. I want to compare this value with the fixed value of 33. If the value in Channel 60 is equal to 33, then the virtual discrete channel must be 1, or true, or on….

    Thank you,

    #6552
    Mikhail
    Moderator

    Hi,

    Try this:

    Val(60) == 33 ? 1 : 0; Stat(60)

    However, it’s a bag practice to compare floating point values by equality operator. It’s better to use <= or >=

    #6554
    manjey73
    Participant

    It is not correct to compare the real number, simply because it can fluctuate within certain limits, for example, 32,999-33, 019, and then you will have the output turned on and off. You need to apply Hysteresis to avoid this. Kind of laid out the formula of Hysteresis on the forum.

    #6555
    manjey73
    Participant

    Hysteresis added to Formula tab

    int[] HysNum = new int[1];
    bool[] Hys = new bool[1];
    public double Hysteresis(double inCnl, double low, double high)
    {
    bool q = Val(CnlNum) > 0;
    
    int res = Array.IndexOf(HysNum, CnlNum);
    if (res == -1)
    {
    res = HysNum.Length;
    Array.Resize(ref HysNum,  res+1);
    Array.Resize(ref Hys,   res+1);
    HysNum[res] = CnlNum;
    Hys[res] = q;
    }
    
    if (inCnl < low) Hys[res] = true;
    if (inCnl > high) Hys[res] = false;
    
    return Convert.ToDouble(Hys[res]);
    }

    In the channel, use the formula Hysteresis(Val(X), 32.5, 33.5))
    Where Val(X) is your measurement channel. Enabling and disabling the output is already configured for the channel in which you use the Hysteresis formula

    #6556
    Hennie_Kotze
    Participant

    Thank You Guys…

    The channel 60 is defined as a REAL, but I’m actually just reading one modbus register. The value in this channel is just the decimal representation of the word, and is actually just an Integer….

    The first code ” Val(60) == 33 ? 1 : 0; ” works like a charm!!

    Thank you!!

    #6558
    Mikhail
    Moderator

    In Rapid SCADA all input channel values have the double type. Double is a 64-bit floating point.

    #12334
    TDE
    Participant

    Hi Henni,

    Can u please show me how you define it in the channels table?

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.