Integration in TwinCAT (CX9020)

This example describes how a simple PLC program for MP-Bus can be written in TwinCAT and how it is linked with the hardware. The task is to control an individual flap drive and change it with a button.

Unpacking the example files

Hardware

Setting up the components

The following hardware is required:

Set up the hardware and the MP-Bus components as described in the associated documentation.

This example assumes that the address of the flap drive is known.

Software

Creation of the PLC program

Create a new PLC project for PC-based systems (ARM) and add the TcMPBus.lib library.

Next, generate the following global variables:

VAR_GLOBAL
    bOpen       AT %I*     : BOOL;
    bClose      AT %I*     : BOOL;
    arrKL6771_IN    AT %I* : ARRAY[0..11] OF BYTE;
    arrKL6771_OUT   AT %Q* : ARRAY[0..11] OF BYTE;
    stDataKL6771           : DataKL6771;
END_VAR

bOpen: input variable for the Open button.

bClose: input variable for the Close button.

arrKL6771_IN: input variable for the MP-Bus terminal.

arrKL6771_OUT: output variable for the MP-Bus terminal.

stDataKL6771: required for communication with MP-Bus (see DataKL6771).

All function blocks with MP-Bus must be called in the same task.

Therefore, create a MAIN program (CFC) in which the KL6771() and MP_DamperLinearActuator() function blocks are called. Make sure to link the communication block with arrKL6771_IN, arrKL6771_OUT and stDataKL6771.

Integration in TwinCAT (CX9020) 1:

The input SetPoint is set depending on the selected function. Link the global variables bOpen and bClose with an auxiliary variable.

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 KL6771() function 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 TwinCAT 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 the flap drive can be moved. The current position is stored in variable wActValue.