FB_IEC870_5_101Slave

FB_IEC870_5_101Slave 1:

The IEC60870-5-101 substation (Slave) can be implemeted in TwinCAT PLC with the instance of FB_IEC870_5_101Slave.

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 send and received are exchanged with FB_IEC870_SerialLineCtrl.

VAR_INPUT

VAR_INPUT
    protPara    : ST_IEC870_5_101ProtocolParams;  (* IEC60870-5-101 serial link protocol communication params *)
    sysPara     : ST_IEC870_5_101SystemParams;  (* IEC60870-5-101 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-101-protocol parameter.

sysPara:    System parameter.

pAOEntries: Address of application database object array..

cbAOEntries: Byte size of application database object array.

pInputs: Address of PLC process data range of the inputs.

cbInputs: Byte size of PLC process data range of the inputs

pOutputs: Address of   PLC process data range of the outputs.

cbOutputs: Byte size of  PLC process data range of the outputs.

pMemory: Address of  PLC process data range of the flags

cbMemory: Byte size of  PLC process data range of the.

pData: Address of  PLC data range .

cbData: Byte size of  PLC data range.

bEnable :    Enables/Disables the function block (Communication and Connection).

VAR_OUTPUT

VAR_OUTPUT
    system      : ST_IEC870_5_101SystemInterface;
    eState      : E_IEC870_5_101SerialLinkState := eSERIALLINK_DISCONNECTED; (* Serial link connection state *)
END_VAR

system:  System interface. This variable is used for communication interface to  IEC device (here: Substation).

eState:  Connetion status to the master.

 

Example:

Projects: IEC60870-5-101 controlled station

Call in ST:

PROGRAM test
VAR
    slave1AODB      : ARRAY[1..50] 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;

    server1         : FB_IEC870_5_101Slave;

    bEnable         : BOOL;
    eState      : E_IEC870_5_101SerialLinkState;

    bError      : BOOL;
    iecError    : ST_IEC870_5_101ErrorFifoEntry;
END_VAR

 

server1.protPara.linkAddr := 220;
server1.protPara.eLinkMode := eIEC870_LinkMode_Unbalanced;
server1.protPara.elinkAddrSize := eIEC870_LinkAddr_TwoOctets;

server1.sysPara.asduFmt.eAsduAddrSize := eIEC870_AsduAddr_TwoOctets;
server1.sysPara.asduFmt.eObjAddrSize := eIEC870_ObjAddr_ThreeOctets;
server1.sysPara.asduFmt.eCOTSize := eIEC870_COT_TwoOctets;
server1.sysPara.asduAddr := 7;
server1.sysPara.bUsePCTime := TRUE;
server1.sysPara.bSyncTime := TRUE;
server1.sysPara.bSyncPCTime := FALSE;
server1.sysPara.bEndOfInit := TRUE;
server1.sysPara.bPerCyclic := FALSE;
server1.sysPara.tPerCyclicBase := T#5s;
server1.sysPara.bBackScan := FALSE;
server1.sysPara.tBackScanCycle := T#30s;
server1.sysPara.bPerFRZ := TRUE;
server1.sysPara.tPerFRZCycle := T#15s;
server1.sysPara.dbgMode := IEC870_DEBUGMODE_LINKLAYER;(* OR IEC870_DEBUGMODE_DEVSTATE OR IEC870_DEBUGMODE_ASDU;*)
server1.sysPara.bTimeCOT3 := FALSE;

server1( pInputs := ADR( inputs ),
    cbInputs := SIZEOF( inputs ),
    pOutputs := ADR( outputs ),
    cbOutputs := SIZEOF( outputs ),
    pMemory := ADR( memory ),
    cbMemory := SIZEOF( memory ),
    pData := ADR( data ),
    cbData := SIZEOF( data ),
    pAOEntries := ADR( slave1AODB ),
    cbAOEntries := SIZEOF( slave1AODB ),
    hSerial := P_SerialComm_HighSpeed.hSerial,
    bEnable := bEnable,
    eState=>eState );

 

The device error Fifo is read cyclically and the registered errors are written in the Application Log.

REPEAT
    server1.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_101Slave.Lib

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

TwinCAT v2.10.0 Build >= 1301

CX (ARM)