Declaring and calling an instance of the IEC60870-5-101 controlling station
Here you can unpack the complete PLC sources: TutorialSample.zip
The complete functionality of a controlling station is encapsulated in the FB_IEC870_5_101Master function block. An instance can be used to establish a connection to the controlled station. For establishing a further connection a further instance of the function block can be declared.
Add the following PLC code to the declaration part of P_MAIN_LowSpeed:
PROGRAM P_MAIN_LowSpeed
VAR
AODB : ARRAY[0..49] OF ST_IEC870_5_101AODBEntry;
hTable : T_HAODBTable;
init : BOOL := TRUE;
initError : UDINT;
asduAddr : UDINT := 7;
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;
client : FB_IEC870_5_101Master;
ND_VAR
and the instance is called in the program part:
IF init THEN
init := FALSE;
...
ELSE
...
client(
pAOEntries := ADR( AODB ),
cbAOEntries := SIZEOF( AODB ),
pInputs := ADR( inputs ),
cbInputs := SIZEOF( inputs ),
pOutputs := ADR( outputs ),
cbOutputs := SIZEOF( outputs ),
pMemory := ADR( memory ),
cbMemory := SIZEOF( memory ),
pData := ADR( data ),
cbData := SIZEOF( data ),
bEnable := bEnable,
hSerial := P_SerialComm_HighSpeed.hSerial,
hTable := hTable );
...
END_IF