FB_RFIDReader

The TwinCAT RFID library consists of only one function block.

Its interface is to a large extent self-descriptive. For a fast introduction to the handling of the library, there now follows a description of the interface variables.
You are also referred to the Tutorial and the examples.

The uniform handling of all RFID reader models and the associated prepared interface declarations are particularly user-friendly.

However, it should be pointed out that the function block of the RFID library possesses a slight overheat due to the differences between some RFID readers models. This indispensable characteristic is, however, strongly outweighed by the advantages that the available flexibility offers.

FB_RFIDReader 1:

Input variables

VAR_INPUT
    bExecute            : BOOL;
    eCommand            : E_RFID_Command;
    stAccessData        : ST_RFID_AccessData;
    stCtrl              : ST_RFID_Control;
    stCfg               : ST_RFID_ConfigIn;
    eManufacturer       : E_RFID_ReaderManufacturer;
    tTimeOut            : TIME := T#5s;
END_VAR

bExecute

In order to receive messages from the RFID reader, the function block is called with a FALSE on this input.
The function block reacts to a rising edge on bExecute by executing the selected command eCommand or querying it at the RFID reader.

eCommand

The eCommand input offers a choice of commands, such as reading from or writing to a transponder, in the form of an enumeration. See description of the command set. A command is executed by setting the bExecute input.

stAccessData

If a write or read command is to be executed, then parameters must be transferred with this input structure. Details for this structure: ST_RFID_AccessData

stCtrl

Various control parameters can be transferred at the input with stCtrl. This includes the possibility to specify delay times. Details for this structure: ST_RFID_Control

stCfg

An RFID reader has an internal configuration. This can be read out and changed on some devices. Configuration parameters to be transmitted to the RFID reader are transferred at the stCfg input. See description of the configuration options.
Details for this structure: ST_RFID_ConfigIn

eManufacturer

The manufacturer of the RFID reader model in use is specified at this input. Details for this enumeration: E_RFID_ReaderManufacturer

tTimeOut

Specifies a maximum length of time for the execution of the function block. The default value is 5 seconds.

FB_RFIDReader 2:

The condition 'tTimeOut > tPreSendDelay + tPostSendDelay' applies. Otherwise an error is generated at the output. See details of the delay times in ST_RFID_Control.

Input/output variables

VAR_IN_OUT
    RxBuffer            : ComBuffer;
    TxBuffer            : ComBuffer;
END_VAR

RxBuffer

Specifies the receive buffer that was declared as an input variable and linked to the serial terminal in the TwinCAT system manager.
See the description of the serial connection of an RFID reader regarding this.

TxBuffer

Specifies the transmit buffer that was declared as an output variable and linked to the serial terminal in the TwinCAT system manager.
See the description of the serial connection of an RFID reader regarding this.

Output variables

VAR_OUTPUT
    bBusy           : BOOL;
    bResponseRcv    : BOOL;
    eResponse       : E_RFID_Response;

    bError          : BOOL;
    iErrorID        : UINT;     (* general RFID error *)
    iErrCodeRcv     : UINT;     (* error received by reader *)

    stReaderCfg     : ST_RFID_Config;
    stReaderInfo    : ST_RFID_ReaderInfo;
    stTranspInfo    : ST_RFID_TranspInfo;
    stRawData       : ST_RFID_RawData;
END_VAR

bBusy

If the command call is valid, the bBusy output goes to TRUE for at least one cycle. The function block may only be called again for a new command with bExecute = TRUE if bBusy has changed to FALSE and the function block is thus no longer in the active transmission state. Hence, if bBusy = FALSE is recognized, all further output variables bResponseRcv, eResponse, bError, iErrCodeRcv, etc. and stRawData can in turn be evaluated. If a response to an executed command call is expected, then the function block remains at bBusy = TRUE until a telegram is received or until the timeout tTimeOut is reached.
If the delay times tPreSendDelay and/or tPostSendDelay have been given to the function block, bBusy remains TRUE for at least if the sum of these times. See ST_RFID_Control regarding this configuration setting.

bResponseRcv

As soon as a response from the RFID reader has arrived at the controller, this flag is set for at least one cycle. The arrival of a telegram is generally indicated by a rising edge to bResponseRcv = TRUE. Hence, if this flag is recognized, unexpected telegrams and its output variables eResponse, bError, iErrCodeRcv, etc. and stRawData can in turn be evaluated.
If a response to an executed command call is expected, then the function block remains at bBusy = TRUE until a telegram is received. Depending on the executed command call, more than one response can be received before the action is terminated and bBusy is FALSE.
Depending on the configuration setting of the delay times in ST_RFID_Control, bResponseRcv can go to TRUE even before bBusy changes to FALSE.

eResponse

As soon as bResponseRcv shows TRUE, this enumeration indicates the type of message received. The appropriate evaluation can follow, for example, depending on the type.
Details for this enumeration: E_RFID_Response

bError

The bError output becomes TRUE as soon as an error occurs. This can be due to incorrect input parameters, transmission errors, errors on the part of the RFID reader or a timeout.
The type of error that has occurred is indicated by the following output variable iErrorID. Details of error representation are given in the chapter Error codes.

iErrorID

If an error occurs, the type of this error is indicated at the iErrorID output.
Details of the possible ErrorIDs are given in the chapter Error codes.

iErrCodeRcv

The error code indicated at the iErrCodeRcv output corresponds to the error code sent by the RFID reader to the controller.
Details of error representation are given in the chapter Error codes.

stReaderCfg

An RFID reader has an internal configuration. This can be read out and changed on some devices. These read-out configuration parameters are made available at the stReaderCfg output. Details for this structure: ST_RFID_Config

stReaderInfo

Each RFID reader has its own characteristic data, such as designation, hardware version etc. These values, which can be queried among other things using the 'GetReaderVersion' command, are indicated in the output structure stReaderInfo. Details for this structure: ST_RFID_ReaderInfo

stTranspInfo

The structure stTranspInfo contains information on the last read transponder. Among other things, the serial number of the transponder is output here. Details for this structure: ST_RFID_TranspInfo

stRawData

The output structure stRawData outputs both the sent and the received raw data. Details for this structure: ST_RFID_RawData