FB_RFIDReader

The TwinCAT RFID library only consists of one function block.

This section explains the interface variables of the function block for a quick introduction to the handling of the library. See also 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 noted that the function block of the TwinCAT RFID library has a slight overheat due to the differences of some RFID reader models. This indispensable characteristic is, however, strongly outweighed by the advantages that the available flexibility offers.

FB_RFIDReader 1:

Syntax

FUNCTION_BLOCK FB_RFIDREADER
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
VAR_IN_OUT
    RxBuffer      : ComBuffer;
    TxBuffer      : ComBuffer;
END_VAR
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

FB_RFIDReader 2: Inputs

Name

Type

Description

bExecute

BOOL

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

E_RFID_Command

The eCommand input offers a choice of commands, such as reading from or writing to a transponder, in the form of an enumeration.

A command is executed by setting the bExecute input.

stAccessData

ST_RFID_AccessData

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

stCtrl

ST_RFID_Control

Various control parameters can be transferred at the input with stCtrl. This includes the possibility to specify delay times.

stCfg

ST_RFID_ConfigIn

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 also: Configuration

eManufacturer

E_RFID_ReaderManufacturer

The manufacturer of the RFID reader model in use is specified at this input.

tTimeOut

TIME

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

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

FB_RFIDReader 3:/FB_RFIDReader 4: Inputs/outputs

Name

Type

Description

RxBuffer

ComBuffer

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 in section RFID reader connection.

TxBuffer

ComBuffer

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 in section RFID reader connection.

FB_RFIDReader 5: Outputs

Name

Type

Description

bBusy

BOOL

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. Thus, if bBusy = FALSE is detected, all other output variables bResponseRcv, eResponse, bError, iErrCodeRcv,... and stRawData can 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 as long as the sum of these times.

See also: ST_RFID_Control.

bResponseRcv

BOOL

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 signaled with a rising edge to bResponseRcv = TRUE. Thus, if this flag is detected, unexpected telegrams and the corresponding output variables eResponse, bErr, iErrCodeRcv,... and stRawData can be evaluated.

If a response is expected for an executed command call, the function block remains bBusy = TRUE until a telegram is received. Depending on the command call, more than one response can arrive before the action is completed and bBusy = 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

E_RFID_Response

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.

bError

BOOL

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 output variable iErrorID. Details about the error display can be found in the Error codes section.

iErrorID

UNIT

If an error occurs, the type of error at output iErrorID is displayed. Details of the possible error IDs are given in the Error codes section.

iErrCodeRcv

UINT

The error code indicated at the iErrCodeRcv output corresponds to the error code sent by the RFID reader to the controller. Details about the error display can be found in the Error codes section.

stReaderCfg

ST_RFID_Config

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.

stReaderInfo

ST_RFID_ReaderInfo

Each RFID reader has its own identification data such as designation, hardware version, etc. These values, which can be queried with the command GetReaderVersion among others, are specified in the output structure stReaderInfo.

stTranspInfo

ST_RFID_TranspInfo

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

stRawData

ST_RFID_RawData

The output structure stRawData outputs both the sent and the received raw data.

Requirements

Development Environment

Target Platform

PLC Libraries to include

TC3.1.4013

PC or CX (x86, x64)

Tc2_RFID