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 Oct 21, 2018 8:15 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed May 23, 2018 4:50 pm 
Offline

Joined: Thu Sep 21, 2017 1:02 pm
Posts: 8
I have a problem with types when passing arguments involving direct numerical value.

The function definition:
FUNCTION myFunc: BOOL
VAR_IN_OUT
i : INT;
r1: REAL;
r2: REAL;
...


If in PLC_PRG I call the function like this:
myFunc(i:=2, r1:=11.1, r2:=800);

It gives me a compile error because 2 is seen as a SINT and not an INT, 11.1 is seen as LREAL, while 800 is seen as REAL (OK for compiler).

But if I declare variables in PLC_PRG and then call the function myFunc it works. Like this:

VAR
i : INT;
r1: REAL;
r2: REAL;
END_VAR

i:=2;
r1:=11.1;
r2:=800;
myFunc(i,r1,r2);

I would really like to have the one-liner written above working for compactness in big programs. Can you please help me figure out how to do that? The idea is to be able to set many parameters to constants with one line.


Top
   
PostPosted: Wed May 23, 2018 5:28 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 290
Have you tried:

MyFunc(I:=(TO_INT)2, r1:=(TO_REAL)11.1, r2:=(TO_REAL)20);

Also, in the project settings there may be a setting to treat LREAL as a REAL.

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


Top
   
PostPosted: Wed May 23, 2018 5:36 pm 
Offline

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 90
Isn't using VAR_IN_OUT referencing the memory location of the variable being passed in? If you pass direct values in there is no memory location to reference. VAR_INPUT should be used if you don't want to use variables.


Top
   
PostPosted: Mon May 28, 2018 4:54 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 290
Good catch, Comingback4u, using VAR_IN_OUT is not helping and is probably why the poster saw this problem!

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


Top
   
PostPosted: Mon Jul 16, 2018 12:28 pm 
Offline

Joined: Thu Sep 21, 2017 1:02 pm
Posts: 8
Thanks Comingback4u. Using VAR_IN_OUT + constant value input was indeed the problem.

Thanks scott_cunningham for the tip with
(TO_INT)2, r1:=(TO_REAL)11.1, r2:=(TO_REAL)20
I didn't know it and it might be useful in the future.


Top
   
PostPosted: Fri Jul 20, 2018 6:54 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Tue Jun 06, 2006 9:03 am
Posts: 406
You can also use:
REAL#2
instead of
TO_REAL(2)


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