FB_IEC870_5_104SlaveGrp
An instance of the function block FB_IEC870_5_104SlaveGrp can be used to implement an IEC 60870-5-104 substation (slave, high-level) in the TwinCAT PLC. An instance can be used to implement simple systems with one connection or systems with several connections to the master (redundant system).
The maximum number of connections can be specified through the number of ST_IEC870_5_104ServerConnection array elements. The address of the array variables and the byte size of the array variables must be transferred to the instance of the FB_IEC870_5_104SlaveGrp function block.
VAR_IN_OUT
VAR_IN_OUT
hServer : T_HSERVER;
END_VAR
hServer: TCP/IP Server-Handle. The internal parameter of the Server-Handle variable has to be initialised with the function F_CreateServerHnd.
VAR_INPUT
VAR_INPUT
protPara : ST_IEC870_5_104ProtocolParams;
sysPara : ST_IEC870_5_101SystemParams;
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;
pConnections : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF ST_IEC870_5_104ServerConnection := 0;
cbConnections : UDINT := 0;
bEnable : BOOL := TRUE;
END_VAR
protPara: IEC 60870-5-104 protocol parameters.
sysPara: System parameter.
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.
pConnections: Address of the ST_IEC870_5_104ServerConnection array variables.
cbConnections: Byte size of the ST_IEC870_5_104ServerConnection array variables.
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_104SystemInterface;
status : ST_IEC870_5_104GrpStatus;
END_VAR
system: System interface. This variable is used by other IEC application functions as a communication interface for the IEC device (here: substation).
- Member variable system.device is expected by the F_iecSetAOQuality function as VAR_IN_OUT parameter, for example.
- Member variable system.device.errors is a device error FIFO. The PLC application can read and analyses registered errors.
status: Connection and data transfer status information.
Example (high-level interface):
Further examples:
Call in FBD with up to 2 master connections:
PROGRAM test
VAR
AODB : ARRAY[0..49] OF ST_IEC870_5_101AODBEntry;
inputs AT%IB0 : ARRAY[0..999] OF BYTE;
outputs AT%QB0 : ARRAY[0..999] OF BYTE;
memory AT%MB0 : ARRAY[0..999] OF BYTE;
data : ARRAY[0..999] OF BYTE;
hServer : T_HSERVER;
server : FB_IEC870_5_104SlaveGrp;
connections : ARRAY[0..1] OF ST_IEC870_5_104ServerConnection; (* Two master connections *)
bEnable : BOOL := TRUE;
protPara : ST_IEC870_5_104ProtocolParams;
sysPara : ST_IEC870_5_101SystemParams := ( asduAddr := 7 );
status : ST_IEC870_5_104GrpStatus;
bError : BOOL;
iecError : ST_IEC870_5_101ErrorFifoEntry;
END_VAR
In the following ST example, the device error FIFO is read cyclically, and the registered errors are written to the TwinCAT XAE->"Error List" window.
REPEAT
server.system.device.errors.RemoveError( getError=>iecError, bOk=>bError );
IF bError THEN
ADSLOGSTR( ADSLOG_MSGTYPE_ERROR OR ADSLOG_MSGTYPE_LOG, 'IEC 60870-5-104 slave error: 0x%s',
DWORD_TO_HEXSTR( iecError.nErrId, 8, FALSE) );
END_IF
UNTIL NOT bError
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) |