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 Sun Dec 08, 2019 4:30 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Variable Type detection?
PostPosted: Sat Feb 16, 2019 8:11 pm 
Offline

Joined: Tue Mar 28, 2017 3:43 pm
Posts: 5
Can CoDeSys do conditional variable type identification?

Example:
I have a scale function that takes in a REAL value and scales it to some new range, then outputs a REAL. But, sometimes I’m trying to scale an INT, or a DINT, or a BYTE or SINT, etc. how can I make this function automatically recognize the input type, do a xxx_TO_REAL, run my scale function, then do a REAL_TO_xxx, then output the result as an xxx instead of a REAL?

Any solution besides “make a different function for each variable type” would be awesome.

Thanks!


Top
   
PostPosted: Wed Feb 20, 2019 4:10 pm 
Offline

Joined: Tue Mar 11, 2014 2:43 am
Posts: 16
In this case I would use; INT_TO_REAL(your_var) or WORD_TO_REAL(your_var) etc.


Top
   
PostPosted: Thu Feb 21, 2019 4:19 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 309
Codesys V3 now supports the ANY_TYPE, which would work, but I don’t believe this is available on Codesys V2.3.

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


Top
   
PostPosted: Tue Nov 05, 2019 7:40 pm 
Offline

Joined: Tue Mar 28, 2017 3:43 pm
Posts: 5
So, it works this way for using different inputs. That's good.
But, I also want it to output into the same type as whatever is connected.
Is this possible? (Example: I'd like to modify this function to work regardless if dd is a REAL, INT, BYTE, ...)

*******************************************************************
FUNCTION anyTestFunction : REAL
VAR_INPUT
in1: REAL := ANY_TO_REAL(in1);
in2: REAL := ANY_TO_REAL(in2);
in3: REAL := ANY_TO_REAL(in3);
END_VAR
-----------------------------------------------------
anyTestFunction := in1 + in2 + in3;
*******************************************************************


*******************************************************************
PROGRAM PLC_PRG
VAR
aa: INT := 2;
bb: REAL := 2.1;
cc: BYTE := 3;
dd: REAL;
END_VAR
----------------------------------------------------
dd := anyTestFunction(aa, bb, cc);
*******************************************************************


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


Top
   
PostPosted: Tue Nov 12, 2019 1:50 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 309
You could return the ANY type, but then you would have to determine which type within the ANY type.

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


Top
   
PostPosted: Tue Nov 26, 2019 11:37 am 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 987
i do it by paralleling inputs and outputs in ver 2 so input is real and int same as output.

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 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