Integration in TwinCAT (CX9020)

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 the four probe signals of an EnOcean wireless switch module.

Unpacking the example files

Hardware

Setting up the components

The following hardware is required:

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 PLC project for PC-based systems (ARM) and add the TcEnOcean.lib library.

Next, generate the following global 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.

stKL6581Output : Output variable for the EnOcean terminal.

stKL6581 : Required for the communication with EnOcean.

All blocks with EnOcean must be executed in one task.

Therefore, create a MAIN program (CFC) in which the FB_KL6581() and FB_Rec_RPS_Switch() function blocks are called. Make sure to link the communication block with stKL6581Input, stKL6581Output and stKL6581.

Integration in TwinCAT (CX9020) 1:

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.

Integration in TwinCAT (CX9020) 2:

Go to the task configuration and give the task a lower interval time. More detailed information can be found in the FB_KL6581() block description.

Integration in TwinCAT (CX9020) 3:

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.

Integration in TwinCAT (CX9020) 4:

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.

After pressing the button on the wireless switch module, the received radio signals can be viewed in the structure stEnOceanSwitch.