Integration in TwinCAT (CX9020)

This example explains how to write a simple PLC program for LON in TwinCAT and how to link it with the hardware. The task is to change the state of a switching output with a button.

Unpacking the example files

Hardware

Setting up the components

The following hardware is required:

Set up the hardware and the LON components as described in the respective documents.

This example assumes that a Set button was connected to the first KL1002 input and a Reset button to the second.

Software

Creation of the PLC program

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

Next, generate the following global variables:

VAR_GLOBAL
    bSet        AT %I*         : BOOL;
    bReset          AT %I*     : BOOL;
    stParameter_IN      AT %I* : ST_LON_Parameter_IN_36B;
    stParameter_OUT     AT %Q* : ST_LON_Parameter_OUT_36B;
    stLON_Com                  : ST_LON_Communication;
END_VAR

bSwitch: Input variable for the Set button.

bReset: Input variable for the Reset button.

stParameter_IN : Input variable for the LON terminal.

stParameter_OUT : Output variable for the LON terminal.

stLON_Com : Required for communication with LON.

All function blocks with LON must be called in the same task.

Therefore, create a MAIN program (CFC) in which the FB_LON_KL6401() and EIB_SEND_095_SNVT_switch() function blocks are called up. Make sure to link the communication block with stParameter_IN, stParameter_OUT and stLON_Com.

Integration in TwinCAT (CX9020) 1:

Link the local variable bSwitch with the global variables bSet and bReset, then with the input of the selection. Link the local variable stValue with the output of the selection, then with the input stValue of the send block.

Integration in TwinCAT (CX9020) 2:

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

Integration in TwinCAT (CX9020) 3:

Load the project to the CX as 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.

The switching output can be set or reset by pressing the button.