Integration into TwinCAT (CX9020)
This example explains how to write a simple PLC program for DMX in TwinCAT and how to link it with the hardware. Search for DMX devices.
Hardware
Setting up the components
The following hardware is required:
- 1x Embedded PC CX9020
- 1x DMX master terminal EL6851
- 1x end cap EL9111
Set up the hardware and the DMX components as described in the respective documents.
Software
Creation of the PLC program
Create a new PLC project for PC-based systems (ARM) and add the TcDMX.lib library.
Next, generate the following global variables:
VAR_GLOBAL
stEL6851InData AT %I* : ST_EL6851InDataEx;
stEL6851OutData AT %Q* : ST_EL6851OutData;
stCommandBuffer : ST_DMXCommandBuffer;
END_VAR
stEL6851InData : Input variable for the DMX terminal.
stEL6851OutData : Output variable for the DMX terminal.
stCommandBuffer : required for communication with DMX.
Then create a program (CFC) for background communication with DMX. The FB_EL6851CommunicationEx() block is called in this program. Make sure to link the communication block with stEL6851InData, stEL6851OutData and stCommandBuffer.

Create a MAIN program (CFC) in which the block FB_DMXDiscovery() is called up. Connect the input stCommandBuffer of the block with the global variable stCommandBuffer.

Under Task Configuration create a new task for the background communication. Add the communication program to this task. Assign a higher priority (lower number) and shorter interval time to this task than for the standard task. More precise information on this can be found in the description of the FB_EL6851CommunicationEx() function block.

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.
Make the DMX inputs 1 to 64 available by opening the Process data tab of the EL6851 and selecting the option 0x1A01 under Inputs.

Add the PLC program created above under PLC configuration. The two tasks are listed when the PLC project is expanded in the tree view. Expand the tasks – the global input and output variables stEL6851InData and stEL6851OutData should be allocated to the background communication task since the variables are to be processed faster. Move them via drag & drop.

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.
Start the search of DMX devices by switching the variable bStart to TRUE. The number of found devices is stored in variable iFoundedDevices and additional information in arrDMXDeviceInfoList.