EL6851 with CX5120

This sample explains how to write a simple PLC program for DMX in TwinCAT and how to link it with the hardware. Search for DMX devices.

Sample: DMX_Sample_EL6851_CX5120.zip

Hardware

Setting up the components

The following hardware is required:

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

Software

Creation of the PLC program

Create a new "TwinCAT XAE Project" and a "Standard PLC Project".

Add the library Tc2_DMX in the PLC project under "References".

Generate a global variable list with the name GVL_EIB and create the following variables:

VAR_GLOBAL
    stEL6851InData      AT %I* : ST_EL6851InDataEx;
    stKL6851OutData     AT %Q* : ST_EL6851OutData;
    stCommandBuffer            : ST_DMXCommandBuffer;
    arrDMXProcessData          : ARRAY [1..512] OF BYTE;
END_VAR

Name

Type

Description

stEL6851InData

ST_EL6851InDataEx

Input variable for the DMX terminal.

stEL6851OutData

ST_EL6851OutData

Output variable for the DMX terminal.

stCommandBuffer

ST_DMXCommandBuffer

Required for communication with DMX.

arrDMXProcessData

BYTE

The data that are to be transmitted cyclically to the DMX devices are transferred to the function block via this variable. For this the CycleMode must be active (see also input bSetCycleMode).

Then create a program (CFC) for background communication with DMX. In this program the function block FB_EL6851CommunicationEx is called. Make sure to link the communication block with stEL6851InData, stEL6851OutData and stCommandBuffer.

EL6851 with CX5120 1:

Create a MAIN program (CFC) in which the function block FB_DMXDiscovery512 is called. The input stCommandBuffer of the function block is linked with the global variable stCommandBuffer. If the variable bStart is TRUE, the search for DMX devices is started. The number of found devices is stored in variable iFoundDevices and additional information in aDMXDeviceInfoList.

EL6851 with CX5120 2:

Navigate to the task configuration section and configure the PlcTask. By way of example, the task is assigned priority 16 and a cycle time of 6 ms.

EL6851 with CX5120 3:

Create a further task for the background communication. Assign a higher priority (smaller number) and a lower interval time to this task than the PlcTask.

EL6851 with CX5120 4:

Add the program for the communication to this task. More precise information on the task configuration can be found in the description of the function block FB_EL6851CommunicationEx.

EL6851 with CX5120 5:

I/O configuration

Select the CX as target system and initiate a search for its hardware.

Make the DMX inputs 1 to 64 available by opening the Process data tab of the EL6851 and selecting the option 0x1A01 under Inputs.

EL6851 with CX5120 6:

In the project instance within the PLC section, you can see that the input and output variables are assigned to the corresponding tasks.

Link the global variables of the PLC program with the inputs and outputs of the EtherCAT Terminal.

EL6851 with CX5120 7:

Create the Solution and enable the configuration.