FB_IEC870_5_101Master

FB_IEC870_5_101Master 1:

An instance of the FB_IEC870_5_101Master function block can be used to implement an IEC60870-5-101 central station (master, High-Level) in the TwinCAT PLC. A connection to the slave is established for each instance of the function block. Normally the data exchange is started automatically once the connection is established. This is the default configuration of the function block.

VAR_IN_OUT

VAR_IN_OUT
    hSerial : T_HSERIALCTRL;
    hTable  : T_HAODBTable;
END_VAR

hSerial: Connection handle to the FB_IEC870_SerialLineCtrl function block. This variable is used to exchange the data to be sent and received via the FB_IEC870_SerialLineCtrl function block.

hTable: Application object database handle (hash table handle). The table handle must be initialized once with the function F_iecCreateTableHnd before it can be used.

VAR_INPUT

VAR_INPUT
    protPara        : ST_IEC870_5_101ProtocolParams :=  := ( eType := eIEC870_101_MASTER );
    sysPara         : ST_IEC870_5_101SystemParams := ( bEndOfInit := FALSE );
    acqPara         : ST_IEC870_5_101AcquisitionParams;
    pAOEntries      : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF ST_IEC870_5_101AODBEntry := 0;
    cbAOEntries     : UDINT := 0;
    pInputs         : PVOID := 0;
    cbInputs        : UDINT := 0;
    pOutputs        : PVOID := 0;
    cbOutputs       : UDINT := 0;
    pMemory         : PVOID := 0;
    cbMemory        : UDINT := 0;
    pData           : PVOID := 0;
    cbData          : UDINT := 0;
    bEnable         : BOOL := TRUE;
END_VAR

protPara: IEC 60870-5-101 protocol parameter.

sysPara: System parameter.

acqPara: Parameter for cyclic data acquisition.

pAOEntries: Address of the first application object database variable.

cbAOEntries: Byte size of the application object database variables.

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 connections).

The addresses can be determined with the ADR operator and the byte sizes with the SIZEOF operator.

VAR_OUTPUT

VAR_OUTPUT
    system  : ST_IEC870_5_101ExSystemInterface;
    eState  : E_IEC870_5_101SerialLinkState := eSERIALLINK_DISCONNECTED;
END_VAR

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

eState: Connection status to the slave.

Examples (High-Level interface):

Further examples:

The device error Fifo is read cyclically and the registered errors are written in the TwinCAT XAE->"Error List" window.

...
fbClient : FB_IEC870_5_101Master; (* IEC 60870-5-101 control station function block instance *)
...
...
REPEAT
    fbClient.system.device.errors.RemoveError();
    IF fbClient.system.device.errors.bOk THEN
        ADSLOGSTR( ADSLOG_MSGTYPE_ERROR OR ADSLOG_MSGTYPE_LOG, 'IEC 60870-5-101 master communication error: 0x%s',
                DWORD_TO_HEXSTR( fbClient.system.device.errors.getError.nErrId, 8, FALSE) );
    END_IF
UNTIL NOT fbClient.system.device.errors.bOk
END_REPEAT
...

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)