Integration into TwinCAT (BC9191)
This example describes how a simple PLC program for EIB can be written in TwinCAT and how it is linked with the hardware. The task is to change the state of a switching output with a button.
Hardware
Setting up the components
The following hardware is required:
- 1x Bus Terminal Controller BC9191
- 1x potential feed terminal 24V DC
- 1x digital 2-channel input terminal KL1002 (for the set and reset functions)
- 1x EIB terminal KL6301
- 1x end terminal KL9010
Set up the hardware and the EIB components as described in the associated documentation.
This example assumes that a Set button was connected to the first KL1002 input and a Reset button to the second, and that the EIB group address of the switching output is known.
Software
Creation of the PLC program
Create a new PLC project for BC-based systems (BCxx50 via AMS) and add the libraries TcEIB.lbx and TcSystemBCxx50.lbx. Then navigate to Project→Options... →Build and select TreatLREAL as REAL.
Next, generate the following global variables:
VAR_GLOBAL
bSet AT %I* : BOOL;
bReset AT %I* : BOOL;
arrKL6301_in AT %I* : ARRAY[1..24] OF BYTE;
arrKL6301_out AT %Q* : ARRAY[1..24] OF BYTE;
stDataRec : EIB_REC;
END_VAR
bSet : Input variable for the Set button.
bReset: Input variable for the Reset button.
arrKL6301_in : Input variable for the EIB terminal.
arrKL6301_out : Output variable for the EIB terminal.
stDataRec : required for communication with EIB.
Since BC devices can only process one task, communication with EIB cannot run separately.
Therefore, create a MAIN program (CFC) in which the KL6301() and EIB_BIT_SEND() function blocks are called. Make sure to link the communication block with arrKL6301, arrKL6301 and stDataRec.
Link the local variable bData with the global variables bSet and bReset, then with the input bData of the send block. Link the global variable stDataRec with st_Rec.
Go to the task configuration and give the task a lower interval time. More detailed information can be found in the KL6301() block description.
Now load the project as a boot project to the BC and save it.
Configuration in the System Manager
Create a new TwinCAT System Manager project, select the BC as the target system, and search for the associated hardware.
Add the PLC program created above under PLC configuration.
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 BC is now ready for use.
The switching output can be set or reset by pressing the button.