FB_KL6821Communication

FB_KL6821Communication 1:

The function blocks for the DALI commands do not directly access the process image of the DALI Bus Terminal, but store the individual DALI commands in three different buffers. The function block FB_KL6821Communication() sequentially reads the DALI commands from these three buffers and passes the DALI commands to the KL6821. This prevents several function block accessing the process image of the Bus Terminal at the same time. Each of these three buffers is processed with a different priority (high, medium or low). The parameter eCommandPriority, which is available for most function blocks, can be used by the PLC library user to influence the priority with which the respective DALI command is processed by the function block FB_KL6821Communication().

All buffers in which the DALI commands are stored are associated with a variable of type ST_DALIV2CommandBuffer. For each KL6821 there is one instance of the function block FB_KL6821Communication() and one variable of type ST_DALIV2CommandBuffer. If possible, the FB_KL6821Communication() function block should be called in a separate, faster task.

The extent to which the buffers are utilized can be determined from the outputs of the function block. Three arrays are output for this in which each element (0, 1 or 2) represents one of the three buffers (high, middle or low). If you find that one of the three buffers overflows on a regular basis, you should consider the following measures:

- How heavily are the individual PLC tasks utilized? The TwinCAT System Manager offers various appropriate utilities for the analysis.

- Try to reduce the cycle time of the task in which the function block FB_KL6821Communication() is called. The value should not exceed 6 ms. Ideally it should be 2 ms.

- Check the cycle time of the PLC task in which the function blocks for the individual DALI commands are called. This value should be between 10 ms and 60 ms.

- If possible avoid polling (regular reading) of values. Only read values when they are actually required.

- Distribute the individual ballasts evenly over several DALI lines. Overall data throughput is increased by the fact that several DALI lines are processed simultaneously during each PLC cycle.

VAR_INPUT

bResetMaximumDemandCounter   : BOOL;
bResetOverflowCounter        : BOOL;
bResetInactiveProcessImage   : BOOL;
nOptions                     : DWORD := 0;

bResetMaximumDemandCounter: a positive edge resets the stored value of the maximum command buffer utilization, arrBufferMaximumDemandMeter (0 - 100%, see VAR_OUTPUT).

bResetOverflowCounter: a positive edge resets the stored value of the number of command buffer overflows, arrBufferOverflowCounter (see VAR_OUTPUT).

bResetInactiveProcessImage: A positive edge cancels the blocking of the process image of the terminal. The bProcessImageInactive, bDigitalInput1Active and bDigitalInput2Active outputs are again set to FALSE. The lock is activated when one of the two digital inputs on the terminal is activated.

nOptions: reserved for future expansions.

VAR_OUTPUT

bBusy                        : BOOL;
bError                       : BOOL;
nErrorId                     : UDINT;
arrBufferDemandMeter         : ARRAY [0..2] OF BYTE;
arrBufferMaximumDemandMeter  : ARRAY [0..2] OF BYTE;
arrBufferOverflowCounter     : ARRAY [0..2] OF UINT;
bLineIsBusy                  : BOOL;
bLineIsInitialized           : BOOL;
bDigitalInput1Active         : BOOL;
bDigitalInput2Active         : BOOL;
bProcessImageInactive        : BOOL;
bCollisionError              : BOOL;
bPowerSupplyError            : BOOL;
bShortCircuit                : BOOL;

bBusy: This output is set as soon as the function block processes a command and remains active until the command has been processed.

bError: This output is switched to TRUE if an error has occurred during execution of the function block. The command-specific error code is contained in nErrorId.

nErrorId: Contains the command-specific error code of the most recently executed command. See Error codes.

arrBufferDemandMeter: Occupancy of the respective buffer (0 - 100%).

arrBufferMaximumDemandMeter: previous maximum occupancy of the respective buffer (0 - 100%).

arrBufferOverflowCounter: Number of buffer overflows to date.

bLineIsBusy: The output is set as long as the function block FB_KL6821Communication() is active.

bLineIsInitialized: if the function block is being called for the first time (e.g. when the controller is starting up) an initialization process is executed. No DALI commands can be processed during this time.

bDigitalInput1Active: The digital input 1 on the terminal was or is actuated (see also terminal documentation). The bProcessImageInactive output is set and no further DALI commands can be processed by the controller.

bDigitalInput2Active: The digital input 2 on the terminal was or is actuated (see also terminal documentation). The bProcessImageInactive output is set and no further DALI commands can be processed by the controller.

bProcessImageInactive: One of the two digital inputs was actuated at the terminal. No further DALI commands can be processed by the controller. The blockage must be released again via the bResetInactiveProcessImage input.

bCollisionError: A data collision on the DALI bus was detected while a command was sent.

bPowerSupplyError: The KL6821 has detected an error in the internal DALI power supply.

bShortCircuit: Short circuit on the DALI bus.

VAR_IN_OUT

stInData             : ST_KL6821InData;
stOutData            : ST_KL6821OutData;
stCommandBuffer      : ST_DALIV2CommandBuffer;

stInData: Structure in the input process image of the KL6821. It is used for communication from the KL6821 to the PLC. When using FB_KL6821Config(), this structure is linked to the parameter stInData.

stOutData: Structure in the output process image of the KL6821. It is used for communication from the KL6821 to the PLC. When using FB_KL6821Config(), this structure is linked to the parameter stOutData.

stCommandBuffer: A reference to the internal structure for communication with the DALI function blocks.

Requirements

Development environment

Target system

Required libraries

TwinCAT 2.11 R3/x64 from build 2260

PC/CX, BX or BC

TcDALIV2 library from V2.12.0