Declaration of a class in ST
Syntax |
---|
|
Meaning |
---|
declaration of a →class a feature of the →object-oriented programming), Observe that a class is similar to a →function block that is using the features of the object-oriented programming. According to the →IEC-standard, there are the following differences:
For details on the optional keywords
The |
Example 1: Class with methods |
---|
Class CCounter VAR m_iCurrentValue : DINT; (* Default = 0 *) m_bCountUp : BOOL:=TRUE; END_VAR VAR PUBLIC m_iUpperLimit : DINT:=+40; m_iLowerLimit : DINT:=-40; END_VAR METHOD PUBLIC Count : DINT IF (m_bCountUp AND m_iCurrentValue<m_iUpperLimit) THEN m_iCurrentValue:= m_iCurrentValue+1; END_IF; IF (NOT m_bCountUp AND m_iCurrentValue>m_iLowerLimit) THEN m_iCurrentValue:= m_iCurrentValue-1; END_IF; Count := m_iCurrentValue; END_METHOD METHOD public SetDirection VAR_INPUT bCountUp : BOOL; END_VAR m_bCountUp:=bCountUp; END_METHOD END_CLASS |
You are able to use the following language elements for ST within a class:
Blanks, tabs or new lines in ST
Declaration of external variables in ST
Declaration of function block instances or class instances in ST
Declaration of internal variables in ST
Declaration of variables based on an interface
The usage of these language elements makes it possible to use other elements (e.g. declaration of STRING
variables within the section VAR ... END_VAR
) as well. Such elements are not listed here.