FB_GENIbusCommunication

The function blocks for the GENIbus commands do not directly access the process image of the selected serial interface; instead, they place the individual GENIbus commands into three different buffers. The FB_GENIbusCommunication() function block sequentially reads the GENIbus commands from these three buffers and forwards the GENIbus commands to the serial interface. This prevents multiple function blocks accessing the process image of the serial interface at the same time. Each of these three buffers is processed with a different priority (high, medium or low). The user of the PLC library can use the eCommandPriority parameter, which is available in most function blocks, to determine the priority with which the FB_GENIbusCommunication() function block processes the respective GENIbus command.

The buffers in which the GENIbus commands are placed are all contained in a variable of the type ST_GENIbusCommandBuffer. There is one instance of the FB_GENIbusCommunication() function block and one variable of the type ST_GENIbusCommandBuffer per serial interface. If possible, the FB_GENIbusCommunication() 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 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:

VAR_INPUT

bResetMaximumDemandCounter  : BOOL;
bResetOverflowCounter       : BOOL;
byMasterAddr                : BYTE;
dwOptions                   : DWORD := 0;
eComMode                    : E_GENIbusComMode;

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

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

byMasterAddr: Specifies the address that the TwinCAT controller should have within the GENIbus line. Possible input range: 0 - 31.

dwOptions: Reserved for future applications.

eComMode: The selection of the serial communication interface must be entered at this parameter. If a KL terminal or an EtherCAT Terminal is in use, then a configuration of the connection parameters is internally and automatically started:

Unfortunately this is not possible for PC-based interfaces; in this case the parameters must be directly entered in the TwinCAT System Manager.

VAR_OUTPUT

bBusy                        : BOOL;
bError                       : BOOL;
udiErrorId                   : UDINT;
udiErrorArg                  : UDINT;
arrBufferDemandMeter         : ARRAY[0..2] OF BYTE;
arrBufferMaximumDemandMeter  : ARRAY[0..2] OF BYTE;
arrBufferOverflowCounter     : ARRAY[0..2] OF UINT;
bLineIsBusy                  : BOOL;
bLineIsInitialized           : BOOL;
bLineIsConfigured            : BOOL;

bBusy: A GENIbus command is converted into a serial telegram and transmitted. This flag is reset again following a successful response or following an abort after an error.

bError: 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.

udiErrorId: Contains the command-specific error code of the most recently executed command. It is set back to 0 by the reactivation of the function block via the bStart input. See Error codes.

udiErrorArg: If applicable, contains an extended description of the error code.

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

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

arrBufferOverflowCounter: Number of buffer overflows to date.

bLineIsBusy: This output is set if the serial communication is active.

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

bLineIsConfigured: This output indicates with TRUE that the terminal has been successfully configured with the above serial parameters. This output is automatically set if the interface is a PC interface since the user has to enter the parameters himself in the TwinCAT System Manager.

 

FB_GENIbusCommunication 1:

Since an error may not interrupt the execution of the function block, bError, udiErrorId and udiErrorArg are initially reset in every PLC cycle and then re-evaluated.

VAR_IN_OUT

stInData              : ST_GENIbusInData;
stOutData             : ST_GENIbusOutData;
stCommandBuffer       : ST_GENIbusCommandBuffer;

stInData: Reference to the structure containing the input process image for communication with the serial interface.

stOutData: Reference to the structure containing the output process image for communication with the serial interface.

stCommandBuffer: Reference to the structure for communication (buffer) with the GENIbus function blocks.

Requirements

Development environment

Target platform

Required libraries

TwinCAT v2.11 R3/x64 from Build 2253

PC / CX

TcGENIbus library from V1.0.0