FB_IEC870_5_104SlaveGrp
Product Version: TwinCAT PLC Library: IEC60870-5-104 controlled station (slave) v2.0.2 and higher.
An instance of the FB_IEC870_5_104SlaveGrp function block can be used to implement an IEC60870-5-104 substation (slave) in the TwinCAT PLC. An instance of the function block can establish one connection with a master or more connections with a master ( redundant systems)
The maximum number of connections can be defined by the number of ST_IEC870_5_104ServerConnection array elements. The address and byte size of the array variables must be passed to the instance of FB_IEC870_5_104SlaveGrp function block.
VAR_IN_OUT
VAR_IN_OUT
hServer : T_HSERVER;
ND_VAR
hServer : TCP/IP Server-Handle. The internal parameter of the Server-Handle variable has to be initialized with the function F_CreateServerHnd.
VAR_INPUT
VAR_INPUT
protPara : ST_IEC870_5_104ProtocolParams; (* IEC60870-5-104 protocol communication params *)
sysPara : ST_IEC870_5_101SystemParams; (* IEC60870-5-104 slave system params *)
pAOEntries : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF ST_IEC870_5_101AODBEntry := 0; (* Pointer to the first element of application database object array *)
cbAOEntries : UDINT := 0; (* Byte size (length) of application database object array *)
pInputs : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE := 0;
cbInputs : UDINT := 0;
pOutputs : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE := 0;
cbOutputs : UDINT := 0;
pMemory : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE := 0;
cbMemory : UDINT := 0;
pData : POINTER TO ARRAY[0..IEC870_ANYSIZE_ARRAY] OF BYTE := 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: IEC60870-5-104 protocol parameter.
sysPara: system parameter.
pAOEntries: address of the application object database variable.
cbAOEntries: byte size of the application object database variable.
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.
pMemory: address of the PLC process data area for the flags.
cbMemory: 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 connection).
The addresses can found out with the ADR operator, resp. the byte sizes can be found 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 analyse registered errors.
status: Connection and data transfer status information.
Example:
Example projects: IEC60870-5-104 controlled station
Call in FBD with maximum of 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 structured text example the device error FIFO is read cyclically, and the registered errors are written into the Windows Application Log.
REPEAT
server.system.device.errors.RemoveError( getError=>iecError, bOk=>bError );
IF bError THEN
ADSLOGSTR( ADSLOG_MSGTYPE_ERROR OR ADSLOG_MSGTYPE_LOG, 'IEC60870-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 | PLC libraries to include |
---|---|---|
TwinCAT v2.9.0 Build >= 1030 | PC or CX (x86) | TcIEC870_5_104Slave.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcpIp.Lib; TcUtilities.Lib; TcSocketHelper.Lib; TcIEC870_5_104.Lib, TcIEC870_5_101.Lib are included automatically) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |