Integration into TwinCAT (BC9191)

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 BC-based systems (BCxx50 via AMS) and add the libraries TcEnOcean.lbx and TcSystemBCxx50.lbx. Then navigate to Project→Options... →Build and select TreatLREAL as REAL.

Integration into TwinCAT (BC9191) 1:

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

stKL6581Output: Output variable for EnOcean.

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 into TwinCAT (BC9191) 2:

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 into TwinCAT (BC9191) 3:

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 into TwinCAT (BC9191) 4:

Now load the project as a boot project to the BC and save it.

Configuration in the System Manager

Create a new System Manager project, select the BC as the target system, and search for the associated hardware.

Add the PLC program created above under PLC configuration.

Integration into TwinCAT (BC9191) 5:

Now link the global variables of the PLC program with the inputs and outputs of the EnOcean master terminal KL6581 from BC9191, create the allocations, and activate the configuration. Then start the device in run mode.

Your BC 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.