KL6581 with CX5120
This example describes how a simple PLC program for EnOcean can be written in TwinCAT and how it is linked with the hardware. The task is to receive four probe signals of an EnOcean wireless switch module.
Example: EnOcean_Sample_KL6581_CX5120.zip
Hardware
Setting up the components
The following hardware is required:
- 1x CX5120 Embedded PC
- 1x KL6581 EnOcean master terminal
- 1x KL6583-0000 EnOcean transmitter and receiver
- 1x KL9010 end terminal
Set up the hardware and the EnOcean components as described in the associated documentation.
This example assumes that the ID of the wireless switch module is known.
Software
Creation of the PLC program
Create a new "TwinCAT XAE project" and a "Standard PLC project".
Add the library Tc2_EnOcean in the PLC project under "References".
Generate a global variable list with the name GVL_EnOcean and create the following variables:
VAR_GLOBAL
stKL6581Input AT %I* : KL6581_Input;
stKL6581Output AT %Q* : KL6581_Output;
stKL6581 : STR_KL6581;
END_VAR
stKL6581Input: Input variable for the EnOcean terminal (see KL6581_INPUT).
stKL6581Output: Output variable for the EnOcean terminal (see KL6581_Output).
stKL6581: Required for communication with EnOcean (see str_KL6581).
All EnOcean function blocks must be called in the same task.
Create a MAIN program (CFC) in which the function blocks FB_KL6581 and FB_Rec_RPS_Switch are called. Ensure that the communication block is linked with the structures stKL6581Input, stKL6581Output and stKL6581.

The input dw_ID of the receive block is linked with the local variable dwId (ID from wireless switch module) and str_KL6581 with the global variable stKL6581.

Go to the task configuration and give the task a lower interval time.
Further conditions can be found in the description of the function block FB_KL6581.

I/O configuration
Select the CX as target system and initiate a search for its hardware. In the project instance within the PLC section, you can see that the input and output variables are assigned to the task.
Now link the global variables with the inputs and outputs of the Bus Terminals.
The linking of the EnOcean variables is described in detail below.
Right-click the structure stKL6581Input and select “Change link”.

Under “I/O Configuration” select the terminal, select “All Types” and “Continuous”, then select “Status” to “InputStatus” with the left mouse button and the >SHIFT< key. Then press "OK".

You can now check the connection. To do this go onto the KL6581 and open it. All terminal data should now show an arrow. If that is the case, then proceed in exactly the same way with the outputs.