Using the function block

You can achieve a more effective evaluation of the received data with the following instructions:

Declarations:

fbRFIDReader        : FB_RFIDReader := (eManufacturer := eRFRM_Balluff);
sTranspSerialNumber : STRING;

bBusy       : BOOL;
bError      : BOOL;
iErrorID    : UINT;
iErrCodeRcv : UINT;

stTranspInfo : ST_RFID_TranspInfo;

eErrorID    : E_RFID_ErrID;
eErrCodeRcv : E_RFID_ErrCodeRcv_Balluff;

fbTriggerResponse : R_TRIG;
arrRspRcv         : ARRAY[0..99] OF BYTE;

Program sequence:

fbRFIDReader(
    bExecute    := FALSE,

    RxBuffer    := RxBuffer,
    TxBuffer    := TxBuffer,

    bBusy       => bBusy,
    bError      => bError,
    iErrorID    => iErrorID,
    iErrCodeRcv => iErrCodeRcv
);
(* convert Error Codes *)
eErrorID := UINT_TO_INT(iErrorID);
eErrCodeRcv := UINT_TO_INT(iErrCodeRcv);

fbTriggerResponse(CLK := fbRFIDReader.bResponseRcv);
IF (fbTriggerResponse.Q) THEN
    stTranspInfo := fbRFIDReader.stTranspInfo;
    sTranspSerialNumber := stTranspInfo.sSerialNumber;     (* detected RFID Tag Serial Number *)

    MEMSET(ADR(arrRspRcv), 0 , SIZEOF(arrRspRcv) );
    MEMCPY(ADR(arrRspRcv), fbRFIDReader.stRawData.pReceivedRsp, MIN(fbRFIDReader.stRawData.iReceivedRspLen, SIZEOF(arrRspRcv)) );
END_IF

Received error codes can be represented online as enumeration values by directly assigning the integer variables iErrorID and iErrCodeRcv.

Using a trigger, additional data is only evaluated when a new message is received.

The string variable sTranspSerialNumber now always returns the serial number of the last detected transponder. In this case this can also be seen at the function block output fbRFIDReader.stTranspInfo.sSerialNumber.

Depending on the application, further information can be taken from the outputs of the function block.

In order to display a received message as a complete byte sequence, use the MEMCPY function, for example, and copy the raw data into your declared byte array.

Each message from your RFID reader is now received and evaluated in the above manner.

See: Test