FB_IEC870_5_104Slave

FB_IEC870_5_104Slave 1:

An instance of the FB_IEC870_5_104Slave function block can be used to implement an IEC60870-5-104 substation (slave) in the TwinCAT PLC. An instance of the function block can only establish a connection with a master.

FB_IEC870_5_104Slave 2:

Creating redundant systems

If you want to realize redundant systems with two or more connections use the FB_IEC870_5_104SlaveGrp function block.

VAR_IN_OUT

VAR_IN_OUT
    hServer: T_HSERVER;
END_VAR

hServer : TCP/IP server handle. The internal parameters of the server handle variable first have to be initialized via the F_CreateServerHnd function.

VAR_INPUT

VAR_INPUT
    protPara    : ST_IEC870_5_104ProtocolParams;                           (* IEC60870-5-104 protocol communication params *)
    sysPara     : ST_IEC870_5_101SystemParams;                     (* IEC60870-5-104 slave system params *)
    pAOEntries  : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF ST_IEC870_5_101AODBEntry;    (* Pointer to the first element of application database object array *)
    cbAOEntries : UDINT;  (* Byte size (length) of application database object array *)
    pInputs     : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE;
    cbInputs    : UDINT;
    pOutputs    : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE;
    cbOutputs   : UDINT;
    pMemory     : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE;
    cbMemory    : UDINT;
    pData       : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE;
    cbData      : UDINT;
    bEnable     : BOOL := TRUE;
END_VAR

protPara: IEC60870-5-104 protocol parameter.

sysPara: system parameter.

pAOEntries: address of the application object database variable.

cbAOEntries: byte size of the application object database variable.

pInputs: address of the PLC process data area for the inputs.

cbInputs: byte size of the PLC process data area for the inputs.

pOutputs: address of the PLC process data area for the outputs.

cbOutputs: byte size of the PLC process data area for the outputs.

pMamory: address of the PLC process data area for the flags.

cbMamory: byte size of the PLC process data area for the flags.

pData: address of the PLC data area.

cbData: byte size of the PLC data area.

bEnable :activates/deactivates the function block (communication and connection).

VAR_OUTPUT

VAR_OUTPUT
    system      : ST_IEC870_5_104SystemInterface;
    eConnState  : E_SocketConnectionState      := eSOCKET_DISCONNECTED;  (* TCP/IP connection state *)
    eDTState    : E_IEC870_5_104DataTransferState  := eIEC870_STOPDT;    (* IEC60870-5-104 data transfer state *)
END_VAR

system: system interface. This variable is used by other IEC application functions as a communication interface for the IEC device (here: substation).

eConnState: status of the TCP/IP connection with the master.

eDTState: status of the IEC60870-5-104 data exchange (STARTDT, STOPDT)

Example:

Example projects: IEC60870-5-104 controlled station

Call in FBD:

PROGRAM test
VAR
    AODB            : ARRAY[0..49] OF ST_IEC870_5_101AODBEntry;
    inputs AT%IB0   : ARRAY[0..999] OF BYTE;
    outputs AT%QB0  : ARRAY[0..999] OF BYTE;
    memory AT%MB0   : ARRAY[0..999] OF BYTE;
    data        : ARRAY[0..999] OF BYTE;

    hServer         : T_HSERVER;
    server      : FB_IEC870_5_104Slave;


    bEnable         : BOOL := TRUE;
    protPara    : ST_IEC870_5_104ProtocolParams;
    sysPara         : ST_IEC870_5_101SystemParams := ( asduAddr := 7 );
    eConnState      : E_SocketConnectionState;
    eDTState    : E_IEC870_5_104DataTransferState;
    bError      : BOOL;
    iecError    : ST_IEC870_5_101ErrorFifoEntry;
END_VAR
FB_IEC870_5_104Slave 3:

In the following structured text example the device error FIFO is read cyclically, and the registered errors are written into the Windows Application Log.

REPEAT
    server.system.device.errors.RemoveError( getError=>iecError, bOk=>bError );
    IF bError THEN
        ADSLOGSTR( ADSLOG_MSGTYPE_ERROR OR ADSLOG_MSGTYPE_LOG, 'IEC60870-5-101 slave error: 0x%s', DWORD_TO_HEXSTR( iecError.nErrId, 8, FALSE) );
    END_IF
UNTIL NOT bError
END_REPEAT

Requirements

Development Environment

Target System

PLC libraries to include

TwinCAT v2.9.0 Build >= 1030

PC or CX (x86)

TcIEC870_5_104Slave.Lib
( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcpIp.Lib; TcUtilities.Lib; TcSocketHelper.Lib;
TcIEC870_5_104.Lib, TcIEC870_5_101.Lib
are included automatically )

TwinCAT v2.10.0 Build >= 1301

CX (ARM)