FB_IEC870_PartyLineCtrl

FB_IEC870_PartyLineCtrl 1:

The function block FB_IEC870_PartyLineCtrl can be used for the data exchange with the central station in line mode (party line). The function block has to be called cyclically in the PLC task. The eMode input can be used to activate/deactivate line mode. Line mode is not used if you do not use the function block (default setting).

The hSerial variable is a structure and is used for internal data exchange between the fast and slow communication task. Every time the IEC slave wants to transmit, the bRTS output (request to send) is first set to TRUE. Once transmit mode has been switched on the IEC slave is notified by setting the bCTS input (clear to send) to TRUE. The IEC slave then starts transmitting. Once the data have been sent (internal hardware buffers are empty) the IEC slave resets the bRTS output to FALSE. The send line can now be released for another device. Once this has occurred the IEC slave must be notified by setting the bCTS input to FALSE. In other words, the state of the bCTS input always follows the state of the bRTS output.

In the serial PC interface, the bRTS output is not set to FALSE (data sent) until the query of the internal hardware send buffer returns zero bytes in the buffer.

VAR_IN_OUT

VAR_IN_OUT
    hSerial     : T_HSERIALCTRL;
END_VAR

hSerial: Connection handle to FB_IEC870_SerialLineCtrl. Via this variable the data to be sent and received are exchanged with FB_IEC870_SerialLineCtrl.

VAR_INPUT

VAR_INPUT
    eMode    : E_IEC870_5_101PartylineMode := eIEC870_PartylineMode_Off;
    deviceID : UDINT := 0;
    bCTS     : BOOL := FALSE;
END_VAR

eMode: Party line activation mode.

deviceID: This parameter is not used in TwinCAT 3.1 and does not have to be set.

bCTS: Clear to send (for the IEC link layer).

VAR_OUTPUT

VAR_IN_OUT
    bError  : BOOL;
    nErrID  : UDINT;
    bRTS    : BOOL := FALSE;
END_VAR

bError: Becomes TRUE as soon as an error has occurred.

nErrID: Returns the error code, if the bError output is set.

bRTS: Request to send (from the IEC link layer).

Example for line mode configuration:

The RTS line can be mapped directly as an IO output in the PLC. In the TwinCAT System Manager the option "Extended Ctrl/Status" must be activated. The eMode parameter at the function block must be set to eMode := eIEC870_PartylineMode_Ext_On.

FB_IEC870_PartyLineCtrl 2:

The "serial_ExtCtrl" variable must be linked with "ExtCtrl" (RTS output) and the "serial_ExtStatus" variable with "ExtStatus".

FB_IEC870_PartyLineCtrl 3: FB_IEC870_PartyLineCtrl 4:

PROGRAM P_SerialComm_HighSpeed
VAR
    serial_In         AT%I*   : PcComInData;
    serial_Out        AT%Q*   : PcComOutData;
    KL6_In            AT%I*   : KL6inData5B;
    KL6_Out           AT%Q*   : KL6outData5B;
    serial_ExtStatus  AT%I*   : WORD;
    serial_ExtCtrl    AT%Q*   : WORD;

    hSerial          : T_HSERIALCTRL;(* Serial connection control handle *)
    fbSerialLineCtrl : FB_IEC870_SerialLineCtrl := ( Mode := SERIALLINEMODE_PC_COM_PORT(*SERIALLINEMODE_KL6_5B_STANDARD *),
                        Baudrate := 19200,
                        NoDatabits := 8,
                        Parity := PARITY_EVEN,
                        Stopbits := 1,
                        Handshake := HANDSHAKE_NONE,
                        ContinousMode := FALSE );

    fbPartyLineCtrl  : FB_IEC870_PartyLineCtrl := ( eMode := eIEC870_PartylineMode_Ext_On );
    delay            : TON;
    tRTS_DEALY_ON    : TIME := T#100ms;
    tRTS_DELAY_OFF   : TIME := T#100MS;
END_VAR
fbSerialLineCtrl(  pComIn := SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_In ), ADR( KL6_In ) ),
        pComOut := SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_Out ), ADR( KL6_Out ) ),
        SizeComIn :=  SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, SIZEOF( serial_In ), SIZEOF( KL6_In ) ),
        hSerial  := hSerial );

fbPartyLineCtrl( hSerial:= hSerial );
IF fbPartyLineCtrl.bRTS <> fbPartyLineCtrl.bCTS THEN
    IF fbPartyLineCtrl.bRTS THEN
        serial_ExtCtrl.1  := TRUE;(* Switch RTS line ON *)
        delay( in := TRUE, PT := tRTS_DEALY_ON );(* Wait until line enabled *)
     IF delay.Q THEN
            delay( in := FALSE );
            fbPartyLineCtrl.bCTS := TRUE;(* Set clear to send *)
        END_IF
    ELSE
        IF serial_ExtStatus.15  THEN
            delay( in := TRUE, PT := tRTS_DELAY_OFF );(* Wait until all data send *)
            IF delay.Q THEN
                delay( in := FALSE );
                serial_ExtCtrl.1  := FALSE;(* Switch RTS line OFF *)
                fbPartyLineCtrl.bCTS := FALSE;(* Reset clear to send *)
            END_IF
        END_IF
    END_IF
END_IF

Implementation of line mode in the fast communication task: The RTS_SWITCH variable (serial_ExtCtrl.1) is used to switch the line for transmit mode ON and OFF. The tRTS_DEALY_ON delay time (lead time) ensures that activation of the line for the IEC slave was complete, the tRTS_DELAY_OFF delay time (overrun time) ensures that all data bytes sent were received by the central station, including the last one (serial_ExtStatus.15).

FB_IEC870_PartyLineCtrl 5:

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)