FB_IEC870_SerialLineCtrl

FB_IEC870_SerialLineCtrl 1:

The function block FB_IEC870_SerialLineCtrl handles communication between a serial interface (KL60xx, EL60xx or COM port) and the IEC60870-5-101 PLC blocks.
If a serial KL60xx bus terminal is used for the communication, the bus terminal is initialised and configured first (baud rate, parity etc). The PC COM port and the serial EL60xx bus terminal has to 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;
ND_VAR

hSerial :

VAR_INPUT

VAR_INPUT
    Mode            : ComSerialLineMode_  := SERIALLINEMODE_PC_COM_PORT; (* or SERIALLINEMODE_PC_COM_PORT *)
    Baudrate        : UDINT             := 19200;       (* KL60xx only: 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200 *)
 NoDatabits         : BYTE      := 8;       (* KL60xx only: 7 or 8 *)
    Parity          : ComParity_t  := PARITY_EVEN;     (* KL60xx only: PARITY_NONE=0, PARITY_EVEN=1, PARITY_ODD=2 *)
    Stopbits        : BYTE          := 1;       (* KL60xx only: 1 or 2 *)
    Handshake       : ComHandshake_t       := HANDSHAKE_NONE; (* KL60xx only: HANDSHAKE_NONE=0, HANDSHAKE_RTSCTS=1, HANDSHAKE_XONXOFF=2 *)
    ContinousMode   : BOOL;                 (* KL60xx only: Don't start transmission before transmit buffer is filled *)
    pComIn      : POINTER TO BYTE;
    pComOut         : POINTER TO BYTE;
    SizeComIn       : UINT;
END_VAR

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

Baudrate: The baud rate, provided it is supported by the serial hardware.

NoDatabits: The number of user data bits in one data byte.

Parity: The type of the parity bit in a data byte.

Stopbits: The number of stop bits per data byte.

Handshake: The type of handshake used, provided it is supported by the serial hardware.

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%IB0  : PcComInData;
    serial_out AT%QB0 : PcComOutData;
    KL6_in AT%IB100   : KL6inData5B;
    KL6_out AT%QB100  : 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:

The example shows communication via a EL6001 bus terminal (22-byte mode). The serial EL6001 bus terminal must be configured in the TwinCAT System Manager (baud rate, parity etc).

PROGRAM P_SerialComm_HighSpeed
VAR
    fbSerialLineCtrl    : FB_IEC870_SerialLineCtrl := ( Mode := SERIALLINEMODE_EL6_22B );
    EL6_in      AT%IB4100  : EL6inData22B;
    EL6_out     AT%QB4100  : 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

PLC libraries to include

TwinCAT v2.9.0 Build >= 1030

PC or CX (x86)

TcIEC870_5_101Link.Lib

( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib; TcIEC870_5_101.Lib; COMlibV2.Lib; are included automatically )

TwinCAT v2.10.0 Build >= 1301

CX (ARM)