Digital
- Namespace
- ZEquipment
- Implements
FUNCTION_BLOCK ABSTRACT Digital IMPLEMENTS ZEquipment.IDigital, ZCore.ITrigger
This function block is abstract and most notably extended by
The typical application of either of those function blocks is to represent an I/O of the fieldbus. In contrast to using located variables directly in the PLC, this class offers various methods to interact with said I/O in an OOP way. The key features of this class are
- Simulating an I/O such that all functionality can be used without an actual physical hardware.
- Abstracting the logic
- Logging on state changes (can lead to high logging load)
- Also the class includes common trigger logic and implements the trigger interface
The function block implements behavior that is common between digital inputs and outputs, respectively. Every I/O can be set to a simulation mode. In this mode no physical hardware is required and internally a PLC variable is used to store the state of the fieldbus. In simulation mode digital inputs behave almost identical to digital outputs.
Constructor
FB_init
METHOD FB_init (
[input] bInitRetains : BOOL,
[input] bInCopyCode : BOOL) : BOOL
Construction of a DigitalInput or DigitalOutput does not require any parameter it is basically used to set initially the simulation state of the function block. The default simulation state is TRUE
Inputs
bInitRetainsBOOLif TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCodeBOOLif TRUE, the instance afterwards gets moved into the copy code (online change)
Returns
- BOOL
Properties
Enabled
PROPERTY Enabled : BOOL
This property returns the current state of the digital interface. The property respects the logic configuration.
Property Value
- BOOL
Link
PROPERTY Link : BOOL
This property returns the current state of the digital interface as it is written/read from the terminal, ignoring the logic configuration.
Property Value
- BOOL
Simulation
PROPERTY Simulation : BOOL
By default all digital interfaces that extend from this function block are simulated, to disable simulation mode this can be done by changing this property. Usually, the decision if simulation is used, takes places during initialization phase. However, some applications require to switch between these modes on-the-fly. In the latter case simply call this method at any time.
Property Value
- BOOL
Methods
Enable
METHOD Enable (
[input] on : BOOL)
Depending on the logic configuration, this method is used to manipulate the state of the digital interface.
Note
If simulation mode of this Digital interface is set to on, this method can be used to
change the state of a DigitalInput even if this is not allowed of the PLC target by design. We internally map this
input to a simulated state to get this functionality to work. Please refer to its documentation for more details.
Inputs
EnableImpl
METHOD PROTECTED EnableImpl (
[input] on : BOOL)
This method implements the actual logic behind Enable and may be overloaded by extensions of this function block. Most notable, DigitalInput overloads this method to allow writing to a digital input in simulation mode.
Inputs
FallingTrigger
METHOD FallingTrigger () : BOOL
Consecutive calls to this method returning TRUE once, whenever the state of the digital interface switched from IsEnabled to NOT IsEnabled.
It is the same as using a FallingTrigger instance or using an F_TRIG instance on Enabled.
IF digitalInput.FallingTrigger()
THEN
; // do something ...
END_IF
Returns
- BOOL
HasTriggered
METHOD HasTriggered () : BOOL
Depending on the logic set with SetTriggerLogic this method internally calls RisingTrigger or FallingTrigger and returns its output.
By default this method is the same as calling FallingTrigger.
Returns
- BOOL
Invert
METHOD Invert ()
This method inverts the state of the digital interface. For digital inputs this method can only change the state if the input is set to simulation mode.
| Initial state | Invert |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
It is the same as calling
digitalIO.Enable(NOT digitalIO.IsEnabled);
Name
METHOD FINAL Name () : ZCore.ZString
This method returns the name that has been set with SetName
Returns
RisingTrigger
METHOD RisingTrigger () : BOOL
Consecutive calls to this method returns TRUE once, whenever the state of the digital interface switched from IsEnabled to NOT IsEnabled.
It is the same as using a RisingTrigger instance or using an F_TRIG instance on Enabled.
IF digitalInput.RisingTrigger()
THEN
; // do something ...
END_IF
Returns
- BOOL
SetLogger
METHOD SetLogger (
[input] logger : ZCore.ILogger)
Use this method together with SetName to enable logging for this digital interface. Various methods of this implementation write log messages into the passed logger interface.
Note
Sometimes it is beneficial to disable logging by passing 0 to this method (e.g. for inputs or outputs which are switch very often).
Inputs
loggerILoggerObject which implements the ILogger interface, usually one of the Zeugwerk Logger instances of ZAux library
SetLogic
METHOD SetLogic (
[input] logic : DigitalLogic)
According to the process or the used hardware some signals on the fieldbus are high or low active, but in the PLC it is beneficial to have these states inverted. This method allows to switch the logic that this class is operating with. Note that almost all methods of the digital function block make use of the logic that can be set here. (i.e. RisingTrigger, FallingTrigger, Enable, ...).
Inputs
logicDigitalLogiclogic of the input or output, available types are normal and inverted
SetName
METHOD SetName (
[input] name : ZCore.ZString)
Sets the name of this object as it will show up in any log messages that is created by this object. The name set with this method should be relatable to the name of the input in the electrical plan of your automation project to identify the corresponding input properly. However, please note that logging should not be used for inputs because some of them are switched very often, which then leads to a high logging load.
Inputs
nameZStringname of the input, ideally not longer then 30 to 40 characters
SetSimulation
METHOD SetSimulation (
[input] on : BOOL)
By default all digital interfaces that extend from this function block are simulated, to disable simulation mode this can be done by this method. Usually, the decision if simulation is used, takes places during initialization phase. However, some applications require to switch between these modes on-the-fly. In the latter case simply call this method at any time.
Inputs
SetTriggerLogic
METHOD SetTriggerLogic (
[input] logic : DigitalLogic)
This method controls the logic of the HasTriggered method. By default, the trigger logic is set to Normal.
Inputs
logicDigitalLogiclogic of the input or output, available types are normal and inverted