Integration into TwinCAT (BC9191)

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

Integration into TwinCAT (BC9191) 1:

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

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

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