Equipment - Digital Inputs and Outputs
Zeugwerk Framework provides a high variety of digital and analogue inputs and outputs. These objects can of course be used with Zeugwerk Framework template but also without this template in legacy applications. Here is an overview of all IOs.
- Digital
- DigitalInput
- DigitalOutput
- DebouncedInput
- DigitalArray
- ImpulseOutput
- PulsedOutput
- Light
- Analog
- AnalogInput
- AnalogOutput
- AnalogInput
Some of them can be used without calling them every plc cycle like DigitalInput or AnalogOutput, some of them have cyclic behavior like DebounceInput or PulsedOutput.
Here we will make some small examples on how to initialize and use some of those objects in real day applications. For more details on each feature please refer to the API-documentation here.
All of the following examples start with a prepared solution for testing in a usermode runtime environment and with our logging object to observe whats going on. See how to use the Usermode Runtime in TwinCAT
DigitalInput
A digital input is at easy as it sounds a Boolean which gets connected to a fieldbus digital input from a terminal like EL1004. An additional feature is, that it has methods to
- test for a falling or rising trigger
- directly invert the input (in simulation mode)
- can be set (in simulation mode), which cant be done if you want to write directly to AT%I*
- define a logic, so if a real input changes one only has to change the logic
PROGRAM MAIN
VAR
DateTime : ZAux.DateTimeUM;
Logger : ZAux.LoggerFile7FFUM(datetime:=DateTime, filePath:='C:\temp\logfile.log', target:='');
Step : ZCore.Step(0, 100);
Input : ZEquipment.DigitalInput;
END_VAR
-----------------------------------
DateTime.Cyclic();
Logger.Cyclic();
CASE Step.Index OF
0:
IF Logger.Operational
THEN
Logger.Info('Appliation started');
Step.SetNext(10);
END_IF
10:
Input.SetLogger(Logger);
Input.SetLogic(DigitalLogic.Normal);
Input.SetName('LimitSwitchLeft');
Input.SetSimulation(TRUE);
Input.SetTriggerLogic(DigitalLogic.Normal);
Step.SetNext(20);
20:
IF Input.Enabled THEN
Step.SetNext(30);
END_IF
30:
IF NOT Input.Enabled THEN
Step.SetNext(40);
END_IF
40:
;
END_CASE
Lets discuss what we are doing here. In the first step we wait until the logging object is in operational state, so that something can get logged into our logfile. Next we initialize the digital input. In this case we want the DigitalLogic to be normal which means if the fieldbus input is FALSE -> this input object will also return FALSE and vice versa.
We also set simulation TRUE in order to be able to test a little with this environment without having any hardware. In step = 20 we wait until the input returns TRUE. In this case nothing will happen, until we manually force this input to be TRUE, which is only possible because simulation is turned on. If you are using real hardware and this input is connected to it, just turn off simulation and the input will directly return the value from the fieldbus.
In Twincat we can now manually force this input to be TRUE and in the next step it should be set to FALSE again.
DigitalOutput
The digital output works exactly the same like the input. However testing is easier because we do not need to manually force something.
PROGRAM MAIN
VAR
DateTime : ZAux.DateTimeUM;
Logger : ZAux.LoggerFile7FFUM(datetime:=DateTime, filePath:='C:\temp\logfile.log', target:='');
Step : ZCore.Step(0, 100);
Output : ZEquipment.DigitalOutput;
END_VAR
-----------------------------------
DateTime.Cyclic();
Logger.Cyclic();
CASE Step.Index OF
0:
IF Logger.Operational
THEN
Logger.Info('Appliation started');
Step.SetNext(10);
END_IF
10:
Output.SetLogger(Logger);
Output.SetLogic(DigitalLogic.Normal);
Output.SetName('LimitSwitchLeft');
Output.SetSimulation(TRUE);
Output.SetTriggerLogic(DigitalLogic.Normal);
Step.SetNext(20);
20:
Output.Enable(TRUE);
Step.SetNext(30);
30:
Output.Enable(FALSE);
Step.SetNext(40);
40:
;
END_CASE
IF Output.FallingTrigger()
THEN
Logger.Info('RisingTrigger detected!');
END_IF
In this example first wait until the Logger is initialized and then initialize the output. After that we set the output to TRUE and again in the next step to FALSE. After setting this output to FALSE we use an additional feature which comes with every DigitalInput and DigitalOutput of Zeugwerk Framework, a Rising or Falling Trigger. Testing the output with the method FallingTrigger() will return TRUE once a falling edge is detected. In this case we log the info string 'RisingTrigger detected!' into our logfile.
DigitalArray
One additional, useful object is the Digital Array. Here it is possible to summarize the input/output of one or more digital inputs/outputs into one single digital input or output. The evaluation logic for this can be set as one likes possible methods are defined in ZEquipment.DigitalOperationType as LogicalAnd, LogicalOr, LogicalNot and LogicalXor.
To make this clear how a DigitalArray object works lets make an example with two digital inputs.
Lets assume we have an object detection and this object is so big, that we need to use 2 separate inputs, one on the left and one on the right side of this object. In our software we do not want to evaluate each digital input separately (only in case of an error), we just want one digital input which returns a signal TRUE if the object is detected and FALSE if not.
PROGRAM MAIN
VAR
DateTime : ZAux.DateTimeUM;
Logger : ZAux.LoggerFile7FFUM(datetime:=DateTime, filePath:='C:\temp\logfile.log', target:='');
Step : ZCore.Step(0, 100);
DigAy : ZEquipment.DigitalArray;
DigIn1 : ZEquipment.DigitalInput;
DigIn2 : ZEquipment.DigitalInput;
END_VAR
--------------------------------------
DateTime.Cyclic();
Logger.Cyclic();
CASE Step.Index OF
0:
IF Logger.Operational
THEN
Logger.Info('Appliation started');
Step.SetNext(10);
END_IF
10:
DigAy.SetLogger(Logger);
DigAy.SetLogic(DigitalLogic.Normal);
DigAy.SetName('ObjectDetection');
DigAy.SetOperationType(DigitalOperationType.LogicalAnd);
DigAy.SetSimulation(TRUE);
DigAy.SetTriggerLogic(DigitalLogic.Normal);
DigAy.AddDigital(DigIn1);
DigAy.AddDigital(DigIn2);
Step.SetNext(20);
20:
DigIn1.SetLogger(Logger);
DigIn1.SetLogic(DigitalLogic.Normal);
DigIn1.SetName('ObjectDetectionLeft');
DigIn1.SetSimulation(TRUE);
DigIn1.SetTriggerLogic(DigitalLogic.Normal);
DigIn2.SetLogger(Logger);
DigIn2.SetLogic(DigitalLogic.Normal);
DigIn2.SetName('ObjectDetectionRight');
DigIn2.SetSimulation(TRUE);
DigIn2.SetTriggerLogic(DigitalLogic.Normal);
Step.SetNext(30);
30:
IF DigAy.Enabled THEN
Logger.Info('Both Digital Inputs are now TRUE');
Step.SetNext(40);
END_IF
40:
IF NOT DigAy.Enabled THEN
Logger.Warning('Both Digital Inputs are now FALSE');
Step.SetNext(50);
END_IF
50:
;
END_CASE
The initialization is very simple, for this example we need one digital array and two digital inputs. We have to initialize all three objects and we need to add the digital inputs to the array. Finally we need to choose a proper operation type so that the array knows how to connect each input to one another for evaluation.
In our case we will set LogicalAnd and therefore both digital inputs have to be TRUE so that the digital array also returns TRUE.
Another example could be a safety input where one digital input has to be TRUE and the other FALSE so that finally the digital array returns TRUE.