FB_KL6831KL6841Communication

FB_KL6831KL6841Communication 1:

The function blocks for the SMI commands do not directly access the process image of the KL6831/KL6841; instead, they place the individual SMI commands into three different buffers. The function block FB_KL6831KL6841Communication() sequentially reads the SMI commands from these three buffers and forwards the SMI commands to the KL6831/KL6841. This prevents multiple function blocks accessing the KL6831/KL6841 process image simultaneously. 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 to influence the priority with which the respective SMI command is processed by the function block FB_KL6831KL6841Communication().

The buffers in which the SMI commands are stored are all contained in a variable of the type ST_SMICommandBuffer. For each KL6831/KL6841 there is an instance of the function block FB_KL6831KL6841Communication() and a variable of the type ST_SMICommandBuffer. If possible, the function block FB_KL6831KL6841Communication() 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 detect regular overflow for one of the three buffers, you should consider the following:

FB_KL6831KL6841Communication 2: Inputs

VAR_INPUT
  bResetMaximumDemandCounter : BOOL;
  bResetOverflowCounter      : BOOL;
  bResetInactiveProcessImage : BOOL;
  bResetDataFrameError       : BOOL;
  dwOptions                  : DWORD := 0;
END_VAR

Name

Type

Description

bResetMaximumDemandCounter

BOOL

A positive edge resets the stored value of the maximum command buffer demand (arrBufferMaximumDemandMeter).

bResetOverflowCounter

BOOL

A positive edge resets the stored value of the number of command buffer overflows (arrBufferOverflowCounter).

bResetInactiveProcessImage

BOOL

A positive edge cancels the blocking of the process image of the terminal. The outputs bProcessImageInactive, bDigitalInput1Active and bDigitalInput2Active are again set to FALSE. The blocking is activated as soon as one of the digital inputs Input1 or Input2 on the terminal is actuated.

bResetDataFrameError

BOOL

A positive edge resets the message for a telegram error. The output bDataFrameError is set again to FALSE. The blocking is activated as soon as the terminal detects a telegram error.

dwOptions

DWORD

Reserved for future extensions

FB_KL6831KL6841Communication 3: Inputs/outputs

VAR_IN_OUT
  stInData        : ST_KL6831KL6841InData;
  stOutData       : ST_KL6831KL6841OutData;
  stCommandBuffer : ST_SMICommandBuffer;
END_VAR

Name

Type

Description

stInData

ST_KL6831KL6841InData

Reference to the structure for communication with the KL6831/KL6841

stOutData

ST_KL6831KL6841OutData

Reference to the structure for communication with the KL6831/KL6841

stCommandBuffer

ST_SMICommandBuffer

Reference to the structure for communication with the SMI function blocks

FB_KL6831KL6841Communication 4: Outputs

VAR_OUTPUT
  bBusy                       : BOOL;
  bError                      : BOOL;
  udiErrorId                  : UDINT;
  arrBufferDemandMeter        : ARRAY [0..2] OF BYTE;
  arrBufferMaximumDemandMeter : ARRAY [0..2] OF BYTE;
  arrBufferOverflowCounter    : ARRAY [0..2] OF UINT;
  bLineIsInitialized          : BOOL;
  b24VPowerSupplySwitchedOn   : BOOL;
  bDigitalInput1Active        : BOOL;
  bDigitalInput2Active        : BOOL;
  bProcessImageInactive       : BOOL;
  bDataFrameError             : BOOL;
  bChecksumError              : BOOL;
END_VAR

Name

Type

Description

bBusy

BOOL

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

bError

BOOL

This output is switched to TRUE as soon as an error occurs during the execution of a command. The command-specific error code is contained in udiErrorId. The output is reset to FALSE by the reactivation of the function block via the input bStart.

udiErrorId

UDINT

Contains the command-specific error code of the most recently executed command. It is reset to 0 by the reactivation of the function block via the input bStart (see error codes).

arrBufferDemandMeter

ARRAY OF BYTE

Demand of the respective buffer (0 - 100%)

arrBufferMaximumDemandMeter

ARRAY OF BYTE

Previous maximum demand of the respective buffer (0 - 100%)

arrBufferOverflowCounter

ARRAY OF BYTE

Number of buffer overflows to date

bLineIsInitialized

BOOL

If the function block is called for the first time (e.g. when starting the controller), initialization is carried out. No SMI commands can be processed during this time. This output is set to TRUE once the initialization has been completed.

b24VPowerSupplySwitchedOn

BOOL

The KL6831/KL6841 must be supplied with 24 V DC via two connections. The output is set as soon as 24 V DC is detected. If there is no 24 V DC the output goes FALSE and no SMI commands can be processed by the controller as long as there is no 24 V DC.

bDigitalInput1Active

BOOL

The digital input Input1 on the terminal has been or is actuated (see also the terminal documentation). The output bProcessImageInactive is set and no further SMI commands can be processed by the controller.

bDigitalInput2Active

BOOL

The digital input Input2 on the terminal has been or is actuated (see also the terminal documentation). The output bProcessImageInactive is set and no further SMI commands can be processed by the controller.

bProcessImageInactive

BOOL

One of the digital inputs Input1 or Input2 has been actuated on the terminal. No further SMI commands can be processed by the controller. The blockage must be released again via the input bResetInactiveProcessImage.

bDataFrameError

BOOL

The terminal has detected a telegram error on the SMI bus. The error must be reset via the input bResetDataFrameError.

bChecksumError

BOOL

The terminal has detected a checksum error on the SMI bus. The message is automatically reset as soon as a telegram is transmitted without error once again.

Requirements

Development Environment

PLC library to include

TwinCAT from v3.1.4020.14

Tc2_SMI from 3.3.5.0