Forum Home › Forums › Development and Integration › simple Formula that compares an Integer or real and returns Boolean
Tagged: formula
- This topic has 6 replies, 4 voices, and was last updated 3 years ago by
TDE.
-
AuthorPosts
-
February 25, 2020 at 4:30 am #6551
Hennie_KotzeParticipantGood 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,
February 25, 2020 at 5:55 am #6552
MikhailModeratorHi,
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 >=
February 25, 2020 at 6:13 am #6554
manjey73ParticipantIt 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.
February 25, 2020 at 6:17 am #6555
manjey73ParticipantHysteresis 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 formulaFebruary 25, 2020 at 6:45 am #6556
Hennie_KotzeParticipantThank 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!!
February 25, 2020 at 4:06 pm #6558
MikhailModeratorIn Rapid SCADA all input channel values have the double type. Double is a 64-bit floating point.
March 30, 2023 at 4:04 pm #12334TDE
ParticipantHi Henni,
Can u please show me how you define it in the channels table?
-
AuthorPosts
- You must be logged in to reply to this topic.