RFID reader connection

All RFID readers supported by this PLC library are connected to the controller via serial communication interfaces (RS 232, RS 422, RS 485 and virtual serial COM ports).

The following Beckhoff products can be used for this:

RFID reader connection 1:
RFID reader connection 2:

A separate connection must be made to a separate terminal for each RFID reader. The TwinCAT RFID library does not support multiple RFID readers on the same RS485 network for the time being.

Setting up serial communication in TwinCAT 3 XAE

Serial data exchange is set up with the function blocks of the TwinCAT PLC library Tc2_SerialCom.

Create a send buffer and a receive buffer of type "ComBuffer". This can take place globally, but does not have to. In addition, you should create two data structures as they are used for serial communication in the TwinCAT System Manager.

If the COM port is used, it looks like this:

gPcComRxBuffer         : ComBuffer;
gPcComTxBuffer         : ComBuffer;
PcComInData     AT %I* : PcComInData;
PcComOutData    AT %Q* : PcComOutData;

When using a serial terminal, EL6inData22B/EL6outData22B as well as KL6inData5B/KL6outData5B, other data types are possible in addition to PcComInData/PcComOutData.

Link the structures in the TwinCAT System Manager to the channels of the serial interface. When using the ComPort, you must additionally activate the SyncMode option on the IO device in the TwinCAT System Manager. The PLC variables must be assigned to the correct (fast) task in the TwinCAT System Manager and linked appropriately from there.

For serial communication, create an instance of the SerialLineControl. This must be called cyclically in a fast task (<= 1 ms). The required task cycle time depends on the application, the data volume, the baud rate and the interface. Depending on the application and interface, it often makes sense to execute this in an additional task that is faster than the application's task.

Example 1: When connecting an RFID device to a COM port and a baud rate of 115,200 baud, a cycle time of 1 ms is required.

Example 2: When connecting an RFID device to an EL6001 and a baud rate of 9,600 baud, a cycle time of 6 ms max. is required.

Further information and explanations on the use of virtual COM ports can be found in the documentation for the PLC library "Serial Communication".

Exemplary display of the COM port settings in the TwinCAT System Manager:

RFID reader connection 3:

The call of the SerialLineControl is represented by way of example below.

Call as StructuredText in the case of use of the COM port:

LineControl(
    Mode      := SERIALLINEMODE_PC_COM_PORT,
    pComIn    := ADR(PcComInData),
    pComOut   := ADR(PcComOutData),
    SizeComIn := SIZEOF(PcComInData),
    TxBuffer  := gPcComTxBuffer,
    RxBuffer  := gPcComRxBuffer
);

Call as StructuredText in the case of use of an EtherCAT terminal:

LineControl(
    Mode      := SERIALLINEMODE_EL6_22B,
    pComIn    := ADR(EL6ComInData),
    pComOut   := ADR(EL6ComOutData),
    SizeComIn := SIZEOF(EL6ComInData),
    TxBuffer  := gEL6ComTxBuffer,
    RxBuffer  := gEL6ComRxBuffer
);

Call as StructuredText in the case of use of a K-bus terminal:

KL6Config3(
    Execute       := bConfig3,
    Mode          := SERIALLINEMODE_KL6_5B_STANDARD,
    Baudrate      := 9600,
    NoDatabits    := 8,
    Parity        := 0,
    Stopbits      := 1,
    Handshake     := RS485_FULLDUPLEX,
    ContinousMode := FALSE,
    pComIn        := ADR(KlComInData3),
    pComOut       := ADR(KlComOutData3),
    SizeComIn     := SIZEOF(KlComInData3),
    Busy  => bConfig3Act,
    Done  => bConfig3Done,
    Error => bConfig3Error
);
IF NOT KL6Config3.Busy THEN
    bConfig3 := FALSE;

    LineControl3(
        Mode      := SERIALLINEMODE_KL6_5B_STANDARD,
        pComIn    := ADR(KlComInData3),
        pComOut   := ADR(KlComOutData3),
        SizeComIn := SIZEOF(KlComInData3),
        TxBuffer  := gKlComTxBuffer3,
        RxBuffer  := gKlComRxBuffer3
    );
END_IF