KL6041 with CX5120
The program illustrates the application of the individual function blocks, based on 5 samples.
The communication runs via a K-bus terminal.
Sample: GeniBus_Sample_KL6041_CX5120.zip
![]() | The TwinCAT project is available for download as *.zip file. This must first be unpacked locally so that the archive (*.tnzip file) is available for import into the TwinCAT project. |
Hardware
Setting up the components
- 1x CX5120 Embedded PC
- 1x KL1408 four-channel digital input terminal for the execution of the individual tests.
- 1x KL6041 serial RS485 terminal
- 1x KL9010 end terminal
Configure the hardware as described in the corresponding documentation.
Software
Creation of the PLC program
The respective test program section can be selected by setting the iTest variable in the MAIN program to values from 1 to 5.

The respective program parts contain pre-configured function blocks, which you can address through the test inputs b1 to b8:
VAR_GLOBAL
b1 AT %I* : BOOL;
b2 AT %I* : BOOL;
b3 AT %I* : BOOL;
b4 AT %I* : BOOL;
b5 AT %I* : BOOL;
b6 AT %I* : BOOL;
b7 AT %I* : BOOL;
b8 AT %I* : BOOL;
stInData AT %I* : ST_GENIbusInData;
stOutData AT %Q* : ST_GENIbusOutData;
stCommandBuffer : ST_GENIbusCommandBuffer;
END_VAR
b1..b8: Switching inputs for the test programs.
stInData: Structure with the input variables (see ST_GENIbusInData) for various terminal types.
stOutData: Structure with the output variables (see ST_GENIbusOutData) for various terminal types.
stCommandBuffer: Reference to the structure for communication (see ST_GENIbusCommandBuffer) with the function block FB_GENIbusCommunication
I/O configuration
The requirement for the linking of the process image is that the terminal is preset to 22 bytes in advance. In contrast to the PC interface, this cannot be configured in the I/O section, but only via the KS2000 software. The communication parameters
- Baud Rate: 9600 bits/s
- Data bits: 8
- Parity: None
- Stop bits: 1
are automatically set by the PLC application, so that following the exchange of a terminal and a subsequent restart, this terminal is correctly set.
The linking of the process image to the PLC input and output variables can be accomplished most simply from the hardware side, since multi-links are possible from there. To this end, the variables must show up in the I/O section on the right:

First of all, just the status is linked with the status variable of the communication input. Note that when doing so the structure for KL communication must be selected.


After that the data bytes can be conveniently linked to the corresponding variables by multi-link. The selection of several variables can be achieved by clicking on “Data1” and pressing the ↓ key with the Shift key pressed.


The output variables must be linked in the same way.