Call and declaration of the substation
The complete functionality of a substation is encapsulated in the FB_IEC870_5_104Slave function block. An instance can be used to establish a connection to the master. For a further connection, declare a further instance and transmit the same server handle (hServer variable) to this second instance, or use the FB_IEC870_5-104SlaveGrp function block (recommended). You must set the IP address to match the IP address of your target system
Insert the following PLC code in the declaration part of MAIN:
PROGRAM MAIN
VAR
AODB : ARRAY[0..49] OF ST_IEC870_5_101AODBEntry;
init : BOOL := TRUE;
initError : 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;
hServer : T_HSERVER;
server : FB_IEC870_5_104Slave;
END_VAR
and the instance is called in the program part:
IF init THEN
init := FALSE;
...
F_CreateServerHnd( '', '127.0.0.1'(* change this! *), 2404, nMode := LISTEN_MODE_CLOSEALL OR CONNECT_MODE_ENABLEDBG, bEnable, hServer );
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 ),
hServer := hServer,
bEnable := bEnable );
END_IF
The associated PLC example tutorial can be downloaded here.