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:
- 1x CX5120 Embedded PC
- 1x EL6851 DMX Master terminal
- 1x EL9011 end cap
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 | Input variable for the DMX terminal. | |
stEL6851OutData | Output variable for the DMX terminal. | |
stCommandBuffer | 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.

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.

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.

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.

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.

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.

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.

Create the Solution and enable the configuration.