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 Fri Jan 24, 2020 7:27 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Oct 17, 2017 1:14 pm 
Offline

Joined: Mon Oct 16, 2017 11:23 am
Posts: 3
Hi,
I am used to functions returning only one data type, depending on how the function itself is declared (for example FUNCTION fName : INT, which returns an INT).
However, I read the follwoing at Beckhoff's webpage in their chapter about functions

"According to the IEC 61131-3 standard, functions can have additional outputs. Those must be assigned in the call of the function, for example in ST according to syntax:
out1 => <output variable 1> | out2 => <output variable 2> | ...further output variables"
[1]

I am familiar with this in Function Blocks where you declare your output variables for example inside a VAR_OUTPUT (...) END_VAR, but I am hoping that someone could show me an example of additional outputs in a Function?



[1]: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/27021597900156043.html&id=


Last edited by ViggoTW on Wed Nov 08, 2017 5:49 pm, edited 1 time in total.

Top
   
PostPosted: Thu Oct 19, 2017 1:51 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 312
Define the outputs the same way as a function block. You can keep the traditional single output and and the second and third and fourth outputs as var outputs or you can delete the traditional output type and put all outputs as var outs.

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


Top
   
PostPosted: Wed Nov 01, 2017 6:06 pm 
Offline

Joined: Mon Oct 16, 2017 11:23 am
Posts: 3
Trying to add VAR_OUTPUT in a function results in compiler error 3820: " 'VAR_OUTPUT' and 'VAR_IN_OUT' not allowed in functions"

The code I tried looked as follow

Declaration:
Code:
(* Declaration *)
FUNCTION F_fun : BOOL
VAR_INPUT
   bIn1 : BOOL;
   bIn2 : BOOL;
END_VAR
VAR_OUTPUT
   bOut1 : BOOL;
   bOut2 : BOOL;
END_VAR
VAR
END_VAR

(* Code *)
bOut1 := bIn1;
bOut2 := NOT bIn2;


Top
   
PostPosted: Wed Nov 01, 2017 9:06 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 312
Looks like it's a limitation with the version you are running. In version 3, it works. A crude workaround would be to create your function as a program instead and define any local variables as VAR_TEMP so they reset at every call.

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


Top
   
PostPosted: Mon Nov 06, 2017 9:45 am 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 987
The link refers to Version 3 Twincat, Here it works, however in 2.3 it is not working, you should have 1 output var returned by a function, however it is still possible to change other outputs within a function.
It all depends on the type of machine and software.
and yes you are correct, please use FB for this.

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