Hi,
I would like to create a simple function to compare if a value is like Value in between or equal to two limits, similar to the standard comparism functions LE or GE
In principal the function look like:
OUT := (nIN >= nLo) And (nIN <= nHi)
All input parameters nIN, nLo, nHi are declared as ANY_NUM
FUNCTION BTWEQ
VAR_INPUT
nIN : ANY_NUM;
nLO : ANY_NUM;
nHI : ANY_NUM;
END_VAR
BTWEQ := (nIN >= nLO) AND (nIN <= nHI);
In Library Util is a FB LIMIT_ALARM which do that what I want, but is limited to Integer values. I would like to have the function generic for any numeric data type.
I get always a failure like 'Cannot convert type SYSTEM.AnyType to type Any
I don't get it what is wrong here.
I tried to do a step between and wrote the Inputs explicit to local variables
VAR
rIN : REAL;
rLO : REAL;
rHI : REAL;
END_VAR
rIN := nIN;
rLO := nLO;
rHI := nHI;
BTWEQ := (rIN >= rLO) AND (rIN <= rHI);
even forced type conversion did not work
rIN := TO_REAL(nIN);
rLO := TO_REAL(nLO);
rHI := TO_REAL(nHI);
BTWEQ := (rIN >= rLO) AND (rIN <= rHI);
It always end with the compiler error of fail to convert the type
Does anyone have an idea what is wrong?
Thank You and Best Regards
Michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi i-campbell, thanks for your answer. I had checked that description of ANY, but it does not help me further.
I thought when I write does anyone have an idea what is wrong do implicate that I look also for a solution.
So, I will precise my question: How can I get the required function with any even combined number type (INT,WORD,REAL) to compare if a value is in between a range.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
thank you very much for your help. I think I understand now how that works with the pointer .
I'm wondering only because I have used ANY at other parts without any problem.
Where I run now into a compiler error , I will implement the pointer solution, but is not a quick short code anymore :-(
Best Regards
Michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I would like to create a simple function to compare if a value is like Value in between or equal to two limits, similar to the standard comparism functions LE or GE
In principal the function look like:
OUT := (nIN >= nLo) And (nIN <= nHi)
All input parameters nIN, nLo, nHi are declared as ANY_NUM
FUNCTION BTWEQ
VAR_INPUT
nIN : ANY_NUM;
nLO : ANY_NUM;
nHI : ANY_NUM;
END_VAR
BTWEQ := (nIN >= nLO) AND (nIN <= nHI);
In Library Util is a FB LIMIT_ALARM which do that what I want, but is limited to Integer values. I would like to have the function generic for any numeric data type.
I get always a failure like 'Cannot convert type SYSTEM.AnyType to type Any
I don't get it what is wrong here.
I tried to do a step between and wrote the Inputs explicit to local variables
VAR
rIN : REAL;
rLO : REAL;
rHI : REAL;
END_VAR
rIN := nIN;
rLO := nLO;
rHI := nHI;
BTWEQ := (rIN >= rLO) AND (rIN <= rHI);
even forced type conversion did not work
rIN := TO_REAL(nIN);
rLO := TO_REAL(nLO);
rHI := TO_REAL(nHI);
BTWEQ := (rIN >= rLO) AND (rIN <= rHI);
It always end with the compiler error of fail to convert the type
Does anyone have an idea what is wrong?
Thank You and Best Regards
Michael
more posts ...
So ANY_* gives you a special struct, see more here
Hi i-campbell, thanks for your answer. I had checked that description of ANY, but it does not help me further.
I thought when I write does anyone have an idea what is wrong do implicate that I look also for a solution.
So, I will precise my question: How can I get the required function with any even combined number type (INT,WORD,REAL) to compare if a value is in between a range.
Hi,
You can use CfUnit for that (ANY).
It is open source so you take a look at the code too.
Regards
Last edit: aliazzz 2020-04-14
Hey, the struct have a pointer and a value == >> see attachment
Hi All,
thank you very much for your help. I think I understand now how that works with the pointer .
I'm wondering only because I have used ANY at other parts without any problem.
Where I run now into a compiler error , I will implement the pointer solution, but is not a quick short code anymore :-(
Best Regards
Michael