CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Access variable subrange values
https://forum.codesys.com/viewtopic.php?f=11&t=9487
Page 1 of 1

Author:  tvm [ Wed Jan 30, 2019 4:59 am ]
Post subject:  Access variable subrange values

If I declare a variable like this...
Code:
VAR
   TestVar : INT (-4095..4095);
END_VAR

...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?
Code:
FUNCTION CheckRangeSigned : DINT
VAR_INPUT
value, lower, upper: DINT;
END_VAR


thanks
Tim

Author:  dFx [ Wed Jan 30, 2019 8:49 am ]
Post subject:  Re: Access variable subrange values

Using constants in d├ęclaration ? Then you may just use thoses constants.

Author:  Comingback4u [ Wed Jan 30, 2019 6:17 pm ]
Post subject:  Re: Access variable subrange values

I am also interested in knowing if there is a way to get the lower and upper limit.

Author:  scott_cunningham [ Thu Jan 31, 2019 1:39 pm ]
Post subject:  Re: Access variable subrange values

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.

Code:
PROGRAM PLC_PRG
VAR
   SubrangeINT : INT (-4096..4096);
   MaxInt : INT := 32767;
   MinInt : INT := -32768;
   Highest : INT;
   Lowest : INT;
END_VAR

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...

Author:  tvm [ Fri Feb 01, 2019 4:24 am ]
Post subject:  Re: Access variable subrange values

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.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/