If I declare a variable like this...
TestVar : INT (-4095..4095);
...then I can use implict checks to limit the value of TestVar to the lower and upper limits.
Is there a way to access the upper and lower limits of a variable? A function I can call or something? How are the lower and upper input variables passed to the CheckRangeSigned implicit check function?
FUNCTION CheckRangeSigned : DINT
value, lower, upper: DINT;
Using constants in déclaration ? Then you may just use thoses constants.
I am also interested in knowing if there is a way to get the lower and upper limit.
Originally created by: scott_cunningham
Brute-force method (assuming you have control of the whole project and can add implicit checks):
Turn on implicit checks for subrange (CheckRangeSigned and CheckRangeUnsigned). These POUs will return the value or the limited version of the value.
SubrangeINT : INT (-4096..4096);
MaxInt : INT := 32767;
MinInt : INT := -32768;
Highest : INT;
Lowest : INT;
SubrangeINT := MaxInt;
Highest := SubrangeINT;
SubrangeINT := MinInt;
Lowest := SubrangeINT;
But really, if you have access to the whole project, then you can see the limits by looking at the var definition. So I don't think this is much help...
That's an interesting idea, and it almost works for what I have in mind. The only problem is that I would actually have to change the value of the variable in question in order to test it.
I set a breakpoint in the CheckRangeSigned function, and it gets the min and max range as inputs to the function, but there's nothing in the call stack to indicate where the inputs come from--the values must be stored in memory somewhere.
Log in to post a comment.