Declaring and calling an instance of the IEC60870-5-101 substation

You can download the complete PLC sources here.

The complete functionality of a substation is encapsulated in the FB_IEC870_5_101Slave function block. An instance can be used to establish a connection to the master. The hSerial connection handle of the fast task must be passed to the substation as VAR_IN_OUT variable.

Insert the following PLC code in the declaration part of P_MAIN_LowSpeed:

PROGRAM P_MAIN_LowSpeed
VAR
    AODB        : ARRAY[0..49] OF ST_IEC870_5_101AODBEntry;

    init        : BOOL := TRUE;
    error       : UDINT;

    inputs AT%IB0   : ARRAY[0..2999] OF BYTE;
    outputs AT%QB0  : ARRAY[0..2999] OF BYTE;
    memory AT%MB0   : ARRAY[0..2999] OF BYTE;
    data        : ARRAY[0..2999] OF BYTE;


     bEnable         : BOOL := TRUE;
    server      : FB_IEC870_5_101Slave;
END_VAR

and the instance is called in the program part:

IF init THEN
    init := FALSE;
...



ELSE
...
 server(     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( AODB ),     cbAOEntries := SIZEOF( AODB ),     hSerial := P_SerialComm_HighSpeed.hSerial, (* serial link interface connection handle from fast task *)     bEnable := bEnable );
...
END_IF