Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » User defined function in basic function block(How to factor out common code ?)
User defined function in basic function block [message #1872285] Sun, 27 October 2024 10:37 Go to next message
Guido Piasenza is currently offline Guido PiasenzaFriend
Messages: 17
Registered: October 2024
Junior Member
Hello experts,

I am creating a new basic function block and there's some code which is repeated in algorithms (in some cases within the same algorithm, in other cases in different algorithms).

Is there any way to create a user-defined function ? I need to pass parameters and get a return value.

Thanks,
Guido

[Updated on: Sun, 27 October 2024 10:38]

Report message to a moderator

Re: User defined function in basic function block [message #1872294 is a reply to message #1872285] Sun, 27 October 2024 18:11 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1639
Registered: January 2014
Senior Member

Hi,

you have two options:
1. IEC 61131-3 functions: for methods that you would like to use from different FBs.
2. Methods for FB local methods. You just start with Method methoName : returntype .... END_METHOD. With VAR_INPUT and VAR_OUTPUT you can define your method's interface. Furthermore methods have access to inputs, outputs and internal vars.
Re: User defined function in basic function block [message #1872297 is a reply to message #1872294] Mon, 28 October 2024 05:00 Go to previous messageGo to next message
Guido Piasenza is currently offline Guido PiasenzaFriend
Messages: 17
Registered: October 2024
Junior Member
Hi, thank you for your reply, but... where am I supposed to input code ? The only place I found where I can input ST code is the Basic Function Block algorithm editor, and in there I can only input algorithms. Is there any other place I can create functions and methods ?

I am using the IDE which I found in the download page: Version: 2.0.1, Build id: 2023-10-23_0926. Should I upgrade to a newer version ?
Re: User defined function in basic function block [message #1872312 is a reply to message #1872297] Mon, 28 October 2024 08:19 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1639
Registered: January 2014
Senior Member

The algorithms tab is for entering all textual code of an FB. So there you can enter all algorithms, and methods of a single FB. Given your feedback we may need a better name for that tab. Suggestions are welcome.

In 4diac IDE currently each function is located in an own file. You can create that via New -> Type and then select Function from the template.
Re: User defined function in basic function block [message #1872318 is a reply to message #1872312] Mon, 28 October 2024 09:00 Go to previous messageGo to next message
Guido Piasenza is currently offline Guido PiasenzaFriend
Messages: 17
Registered: October 2024
Junior Member
It would seem the "Function" template is not available, when I select "New -> Type" I have the following options:

Adapter
Basic
Composite
ServiceInterface
Simple
Struct
SubApp
TemplateBasic
TemplateSimple

What I am doing wrong ?
Re: User defined function in basic function block [message #1872321 is a reply to message #1872318] Mon, 28 October 2024 09:20 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1639
Registered: January 2014
Senior Member

A sorry I missed that you are using the last release version. As I wrote in another post for all these features you need the latest RC for the upcoming 3.0.0 release: https://download.eclipse.org/4diac/updates/rc/
Previous Topic:READ data from file
Next Topic:Problem with release built from source
Goto Forum:
  


Current Time: Wed Feb 05 10:50:11 GMT 2025

Powered by FUDForum. Page generated in 0.03184 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top