FB_IEC870_SerialLineCtrl

FB_IEC870_SerialLineCtrl 1:

The function block FB_IEC870_SerialLineCtrl deals with the communication between a serial interface (KL60xx, EL60xx or COM interface) and the IEC60870-5-10x PLC function blocks.
If a KL60xx serial terminal is used for the communication, the Bus Terminal is initialized and configured first by the function block (baud rate, parity, etc.). However, the PC-COM interface and the EL60xx terminal must be configured in the TwinCAT System Manager. The data received and to be sent are held in the internal buffers of the hSerial variable. The function block has to be called cyclically in the PLC task.

VAR_IN_OUT

VAR_IN_OUT
    hSerial     : T_HSERIALCTRL;
END_VAR

hSerial : Connection handle to other IEC 60870-5-10x protocol function blocks. Via this variable the data to be sent and received are exchanged with FB_IEC870_SerialLineCtrl.

VAR_INPUT

VAR_INPUT
    Mode         : ComSerialLineMode_t   := SERIALLINEMODE_PC_COM_PORT;
    Baudrate     : UDINT      := 19200;
    NoDatabits   : BYTE       := 8;
    Parity       : ComParity_t:= PARITY_EVEN;
    Stopbits     : BYTE       := 1;
    Handshake    : ComHandshake_t    := HANDSHAKE_NONE;
    ContinousMode: BOOL       := FALSE;
    pComIn       : PVOID      := 0;
    pComOut      : PVOID      := 0;
    SizeComIn    : UINT       := 0;
END_VAR

Mode: The Mode input specifies unambiguously which serial hardware is being used.

Baudrate: The baud rate, as far as it is supported by the serial hardware (only in KL60xx mode: 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200).

NoDatabits: Number of user data bits in one data byte (only in KL60xx mode: 7 or 8).

Parity: Type of the parity bit of a data byte (only in KL60xx mode: PARITY_NONE=0, PARITY_EVEN=1, PARITY_ODD=2).

Stopbits: Number of stop bits per data byte (only in KL60xx mode: 1 or 2).

Handshake: Type of handshake used, as far as it is supported by the serial hardware (only in KL60xx mode: HANDSHAKE_NONE=0, HANDSHAKE_RTSCTS=1, HANDSHAKE_XONXOFF=2).

ContinousMode: Switches on continuous transmission, provided this is supported by the serial hardware.

If ContinousMode is TRUE, transmitted data is not sent out by the serial hardware until the hardware transmit buffer is full. This means that there are no time gaps in the transmission, provided the quantity of data is similar in size to the hardware transmit buffer. Continuous mode is only necessary in special cases in which the end device reacts to time gaps with a time-out.

pComIn: Universal pointer to the input variable of the process data for the serial hardware (data types KL6inData, KL6inData5b, PcComInData, EL6inData22B). The pointer is assigned with the ADR() function.

pComOut: Universal pointer to the output variable of the process data for the serial hardware (data types KL6outData, KL6outData5b, PcComOutData, EL6outData22B). The pointer is assigned with the ADR() function.

SizeComIn: Size of the input process image of the serial hardware being used. The size is determined and assigned with the SIZEOF() function.

Example 1:

The example shows an ST call. Switching between two communication routes can be affected by setting the mode variables.

For mode = SERIALLINEMODE_PC_COM_PORT communication is via a serial COM port of the PC, for mode = SERIALLINEMODE_KL6_5B_STANDARD via a KL6001 Bus Terminal (5-byte mode).

PROGRAM P_SerialComm_HighSpeed
VAR
    fbSerialLineCtrl   : FB_IEC870_SerialLineCtrl;
    Mode               : ComSerialLineMode_t := SERIALLINEMODE_KL6_5B_STANDARD; (* SERIALLINEMODE_PC_COM_PORT *)

    serial_in AT%I*    : PcComInData;
    serial_out AT%Q*   : PcComOutData;
    KL6_in AT%I*       : KL6inData5B;
    KL6_out AT%Q*      : KL6outData5B;

    hSerial            : T_HSERIALCTRL;
END_VAR
fbSerialLineCtrl( Mode := Mode,
        Baudrate := 19200,
        NoDatabits := 8,
        Parity := PARITY_EVEN,
        Stopbits := 1,
        Handshake := HANDSHAKE_NONE,
        ContinousMode := FALSE,
        pComIn := SEL( Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_in ), ADR( KL6_in ) ),
        pComOut := SEL( Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_out ), ADR( KL6_out ) ),
        SizeComIn := SEL( Mode = SERIALLINEMODE_KL6_5B_STANDARD, SIZEOF( serial_in ), SIZEOF( KL6_in ) ),
        hSerial := hSerial );

Example 2:

In this example the communication takes place via an EL6001 (22-byte mode). The configuration of the EL6001 terminal (baud rate, parity etc.) must be carried out in the TwinCAT System Manager.

PROGRAM P_SerialComm_HighSpeed
VAR
    fbSerialLineCtrl   : FB_IEC870_SerialLineCtrl := ( Mode := SERIALLINEMODE_EL6_22B );
    EL6_in AT%I*       : EL6inData22B;
    EL6_out AT%Q*      : EL6outData22B;
    hSerial            : T_HSERIALCTRL;
END_VAR
fbSerialLineCtrl( pComIn := ADR( EL6_in ), pComOut := ADR( EL6_out ), SizeComIn := SIZEOF( EL6_in ), hSerial := hSerial );

Requirements

Development environment

Target system type

PLC libraries to be linked (category group)

TwinCAT v3.1.4012.0

PC oder CX (x86, x64, ARM)

Tc2_IEC60870_5_10x (Communication->IEC60870)
Tc2_SerialCom (Communication->Serial)
Tc2_TcpIp (Communication->TcpIp)
Tc2_Utilities (System)