CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Sep 17, 2019 9:31 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jan 30, 2019 4:59 am 
Offline

Joined: Fri Mar 10, 2017 4:45 am
Posts: 43
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


Top
   
PostPosted: Wed Jan 30, 2019 8:49 am 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 151
Using constants in d├ęclaration ? Then you may just use thoses constants.


Top
   
PostPosted: Wed Jan 30, 2019 6:17 pm 
Offline
Frequent User
Frequent User

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 120
I am also interested in knowing if there is a way to get the lower and upper limit.


Top
   
PostPosted: Thu Jan 31, 2019 1:39 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
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...


You do not have the required permissions to view the files attached to this post.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
PostPosted: Fri Feb 01, 2019 4:24 am 
Offline

Joined: Fri Mar 10, 2017 4:45 am
Posts: 43
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited