Integration in TwinCAT (CX9020)
This example describes how a simple PLC program for EIB can be written in TwinCAT and how it is linked with the hardware. The task is to change the state of a switching output with a button.
Hardware
Setting up the components
The following hardware is required:
- 1x Embedded PC CX9020
- 1x digital 2-channel input terminal KL1002 (for the set and reset functions)
- 1x EIB terminal KL6301
- 1x end terminal KL9010
Set up the hardware and the EIB components as described in the associated documentation.
This example assumes that a Set button was connected to the first KL1002 input and a Reset button to the second, and that the EIB group address of the switching output is known.
Software
Creation of the PLC program
Create a new PLC project for PC-based systems (ARM) and add the TcEIB.lib library.
Next, generate the following global variables:
VAR_GLOBAL
bSet AT %I* : BOOL;
bReset AT %I* : BOOL;
arrKL6301_in AT %I* : ARRAY[1..24] OF BYTE;
arrKL6301_out AT %Q* : ARRAY[1..24] OF BYTE;
stDataRec : EIB_REC;
END_VAR
bSet: Input variable for the Set button.
bReset: Input variable for the Reset button.
arrKL6301_in: Input variable for the EIB terminal.
arrKL6301_out: Output variable for the EIB terminal.
stDataRec: Needed for communication with EIB.
All EIB function blocks must be called in the same task.
Therefore, create a MAIN program (CFC) in which the function blocks KL6301() and EIB_BIT_SEND() are called. Make sure to link the communication block with arrKL6301_in, arrKL6301_out and stDataRec.
Sample-PC-Comm
Link the local variable bData with the global variables bSet and bReset, then with the input bData of the send block. Link the global variable stDataRec with st_Rec.
Sample-PC-MAIN
Go to the task configuration and give the task a lower interval time. More detailed information can be found in the KL6301() function block description.
Sample_BC_Task
Load the project to the CX as the boot project and save it.
Configuration in the System Manager
Create a new System Manager project, select the CX as the target system, and search for the associated hardware.
Add the PLC program created above under PLC configuration.
Now link the global variables of the PLC program with the Bus Terminal inputs and outputs, create the allocations, and activate the configuration. Then start the device in run mode.
Your CX is now ready for use.
The switching output can be set or reset by pressing the button.