Integration into TwinCAT (BC9191)
This example explains how to write a simple PLC program for LON in TwinCAT and how to link it 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 LON terminal KL6401
- 1x end terminal KL9010
Set up the hardware and the LON components as described in the respective documents.
This example assumes that a Set button was connected to the first KL1002 input and a Reset button to the second.
Software
Creation of the PLC program
Create a new PLC project for BC-based systems (BCxx50 via AMS) and add the libraries TcLON.lbx and TcSystemBCxx50.lbx. Then navigate to Project→Options... →Build and select TreatLREAL as REAL.

Under Controller settings then change the controller to BC9191 and increase the maximum number of POUs to 1296.

Next, generate the following global variables:
VAR_GLOBAL
bSet AT %I* : BOOL;
bReset AT %I* : BOOL;
stParameter_IN AT %I* : ST_LON_Parameter_IN_36B;
stParameter_OUT AT %Q* : ST_LON_Parameter_OUT_36B;
stLON_Com : ST_LON_Communication;
END_VAR
bSwitch: Input variable for the Set button.
bReset: Input variable for the Reset button.
stParameter_IN : Input variable for the LON terminal.
stParameter_OUT : Output variable for the LON terminal.
stLON_Com : Required for communication with LON.
Since BC devices can only process one task, communication with LON cannot run separately.
Therefore, create a MAIN program (CFC) in which the FB_LON_KL6401() and FB_SEND_095_SNVT_switch() function blocks are called. Make sure to link the communication block with stParameter_IN, stParameter_OUT and stLON_Com.

Link the local variable bSwitch with the global variables bSet and bReset, then with the selected input. Link the local variable stValue with the selected output, then with the input stValue of the send block.

Go to the task configuration and give the task a lower interval time. More detailed information can be found in the FB_LON_KL6401() 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.