Function parameters Calling a function (FC) Function parameters Function call example:

Publisher:心想的45号Latest update time:2023-04-27 Source: 机器人及PLC自动化应用Author: Lemontree Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Call Function (FC)

A function is called by specifying the function name (FC, SFC identifier) ​​and the parameter list. The function name that identifies the return value can be specified in absolute or symbolic form:

FC31 (X1:=5, Q1:=Checksum); // Absolute form

DISTANCE (X1:=5, Q1=:Checksum); // Symbolic form

After calling, the result of the function is available as return value or as output and input/output parameters (actual arguments).

In contrast to function blocks, functions provide a result as a return value. For this reason, functions can be treated as addresses (except for functions of type VOID).

A function computes a return value with the same name as the function, and returns it to the block that called it. There, the value replaces the function call.

For example, in the following assignment, the DISTANCE function is called and the result is assigned to the LENGTH variable.

LENGTH:= DISTANCE (X1:=-3, Y1:=2);

Return values ​​can be used in the following function or function block elements:

  • In an assignment statement,

  • In a logical, arithmetic, or comparison expression or

  • As parameter for further function blocks or function calls.

Function Parameters

In contrast to function blocks, functions do not have any memory in which they store parameter values. Local data is only temporarily stored when the function is activated. For this reason, when calling a function, all formal input, in/out and output parameters defined in the function declaration must be assigned actual parameters.

Example

The call with assignments for input, output and in/out parameters is as follows:

FC32 (E_Pa1:=5,D_Param1:=LENGTH,

A_Param1:=Checksum)

Function call example:

Function to be called

The function DISTANCE that calculates the distance between two points (X1, Y1) and (X2, Y2) in the same plane using a Cartesian coordinate system can be of the following form (this example assumes that the symbol DISTANCE has been declared in the symbol table as FC37).

FUNCTION DISTANCE: REAL // 符号
VAR_INPUT
X1 : REAL;
X2 : REAL;
Y1 : REAL;
Y2 : REAL;
END_VAR
VAR_OUTPUT
Q2 : REAL;
END_VAR
BEGIN
开始
DISTANCE := SQRT( (X2-X1)**2 + (Y2-Y1)**2 );
Q2 := X1+X2+Y1+Y2;
END_FUNCTION

Calling Block

The following example shows some alternative forms of using function values:

FUNCTION_BLOCK CALL
VAR
LENGTH : REAL ;
CHECKSUM : REAL ;
RADIUS : REAL;
Y : REAL;
END_VAR
BEGIN
. . .

// Call in an assignment statement:
LENGTH := DISTANCE (X1:=3, Y1:=2, X2:=8.9, Y2:= 7.4, Q2:=CHECKSUM) ;
// Call in an arithmetic or logical expression, e.g.:
Y := RADIUS + DISTANCE (X1:=-3, Y1:=2, X2:=8.9, Y2:=7.4, Q2:=Checksum)
// For parameterizing further called blocks
FB32.DB32 (DIST:= DISTANCE (X1:=-3, Y1:=2, X2:=8.9, Y2:=7.4), Q2:=Checksum)
. . .
END_FUNCTION_BLOCK

Reviewing Editor: Li Qian


Reference address:Function parameters Calling a function (FC) Function parameters Function call example:

Previous article:What are the capabilities of the 25kg large-load collaborative robot that was first put into mass production?
Next article:Kasite 4060 ER-S丨Industrial Robot Automotive Parts Cutting Processing Spindle One Axis Universal

Latest robot Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号