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

Here you can unpack the complete PLC sources: TcPlcLibIEC870_5_101Slave_TutorialSample.zip

 

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. Assign the connection handle hSerial from the fast task to the substation function block instance.

 

Add the following PLC code to the declaration part of P_MAIN_LowSpeed program:

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