Table of Contents

Digital

Namespace
ZEquipment
Implements

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.

FUNCTION_BLOCK ABSTRACT Digital IMPLEMENTS ZEquipment.IDigital, ZCore.ITrigger

Constructor

FB_init

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

METHOD FB_init (
 bInitRetains : BOOL,
 bInCopyCode : BOOL) : BOOL

Inputs

bInitRetains BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

Returns

BOOL

Properties

Enabled

This property returns the current state of the digital interface. The property respects the logic configuration.

PROPERTY Enabled : BOOL

Property Value

BOOL

This property returns the current state of the digital interface as it is written/read from the terminal, ignoring the logic configuration.

PROPERTY Link : BOOL

Property Value

BOOL

Simulation

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 Simulation : BOOL

Property Value

BOOL

Methods

Enable

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.

METHOD Enable (
 on : BOOL)

Inputs

on BOOL

EnableImpl

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.

METHOD PROTECTED EnableImpl (
 on : BOOL)

Inputs

on BOOL

FallingTrigger

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
METHOD FallingTrigger () : BOOL

Returns

BOOL

HasTriggered

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.

METHOD HasTriggered () : BOOL

Returns

BOOL

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);
METHOD Invert ()

Name

This method returns the name that has been set with SetName

METHOD FINAL Name () : ZCore.ZString

Returns

ZString

RisingTrigger

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
METHOD RisingTrigger () : BOOL

Returns

BOOL

SetLogger

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).

METHOD SetLogger (
 logger : ZCore.ILogger)

Inputs

logger ILogger

Object which implements the ILogger interface, usually one of the Zeugwerk Logger instances of ZAux library

SetLogic

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, ...).

METHOD SetLogic (
 logic : DigitalLogic)

Inputs

logic DigitalLogic

logic of the input or output, available types are normal and inverted

SetName

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.

METHOD SetName (
 name : ZCore.ZString)

Inputs

name ZString

name of the input, ideally not longer then 30 to 40 characters

SetSimulation

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.

METHOD SetSimulation (
 on : BOOL)

Inputs

on BOOL

SetTriggerLogic

This method controls the logic of the HasTriggered method. By default, the trigger logic is set to Normal.

METHOD SetTriggerLogic (
 logic : DigitalLogic)

Inputs

logic DigitalLogic

logic of the input or output, available types are normal and inverted