Vai al contenuto

Functions

IntroductionFor the purposes of programmable controller programming languages, a function is defined as a program organization unit (POU) which, when executed, yields exactly one data element, which is considered to be the function result.Functions contain no internal state information, i.e., invocation of a function with the same arguments (input variables VAR_INPUT and in-out variables VAR_IN_OUT) always yields the same values (output variables VAR_OUTPUT, in-out variables VAR_IN_OUT and function result).Declaration SyntaxThe declaration of a function must be performed as follows:FUNCTION FunctionName : RetDataTypeVAR_INPUTdeclaration of input variables (see the relevant section)END_VARVARdeclaration of local variables (see the relevant section)END_VARFunction bodyEND_FUNCTION
KeywordDescription
FunctionNameName of the function being declared.
RetDataTypeData type of the value to be returned by the function.
VAR_EXTERNAL ..END_VARA function can access global variables only if they are listed in a VAR_EXTERNAL structuring element. Variables passed to the FB via a VAR_EXTERNAL construct can be modified from within the FB.
Function bodySpecifies the operations to be performed upon the input variables in order to assign values dependent on the function’s semantics to a variable with the same name as the function, which represents the function result. It can be written in any of the languages supported by GF_ProjectVX code.
Declaring Functions in GF_ProjectVX CodeWhatever the PLC language you are using, GF_ProjectVX code allows you to disregard the syntax above, as it supplies a friendly interface for using functions.