FB_GENIbusCommunication

FB_GENIbusCommunication 1:

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 function block FB_GENIbusCommunication() 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 parameter eCommandPriority, which is available for most function blocks, can be used to specify the priority with which the respective GENIbus command is processed by the function block FB_GENIbusCommunication().

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 function block FB_GENIbusCommunication() and one variable of the type ST_GENIbusCommandBuffer per serial interface. If possible, the function block FB_GENIbusCommunication() 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_GENIbusCommunication 2: Inputs

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

Name

Type

Description

bResetMaximumDemandCounter

BOOL

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

bResetOverflowCounter

BOOL

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

byMasterAddr

BYTE

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

dwOptions

DWORD

Reserved for future applications.

eComMode

E_GENIbusComMode

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:
Baud Rate: 9600

Data Bits: 8

Parity: None

Stop Bits: 1

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

FB_GENIbusCommunication 3: Inputs/outputs

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

Name

Type

Description

stInData

ST_GENIbusInData

Reference to the structure which contains the input process image for communication with the serial interface.

stOutData

ST_GENIbusOutData

Reference to the structure which contains the output process image for communication with the serial interface.

stCommandBuffer

ST_GENIbusCommandBuffer

Reference to the structure for communication (buffer) with the FB_GENIbusCommunication() function block

FB_GENIbusCommunication 4: Outputs

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;
END_VAR

Name

Type

Description

bBusy

BOOL

Starting with the edge at bStart, this output remains TRUE 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.

udiErrorId

UDINT

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

udiErrorArg

UDINT

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

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 UINT

Number of buffer overflows to date.

bLineIsBusy

BOOL

This output is set as long as the serial communication is active.

bLineIsInitialized

BOOL

If the function block is called up for the first time (e.g. when starting the controller), initialization is carried out. No GENIbus commands can be processed during this time.

bLineIsConfigured

BOOL

This output indicates with TRUE that the terminal has been successfully configured with the above-mentioned 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 XAE.

FB_GENIbusCommunication 5:

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.

Requirements

Development environment

PLC library to include

TwinCAT from v3.1.4020.14

Tc2_GENIbus from v3.3.0.0