Client - GOOSE Subscriber (without Client-Server communication)

In a Client project, the TwinCAT Telecontrol Configurator also generates a Client block by default (see: "General Client project structure"). The Client block can then be used, for example, to activate/deactivate the GOOSE Publisher on the Server side via Client-Server services such as "GetGoCBDataValues" or "SetGoCBDataValues" or to configure the GoCBs. In some cases, however, Client-Server communication with the device should be dispensed with and only a "pure" GOOSE Subscriber implemented. Such a Subscriber can automatically start receiving GOOSE messages after the PLC program start. This example shows the implementation of a Subscriber, but without the Client-Server communication part. The parts of the Client project that are not needed have been deliberately removed in this example.

Download TwinCAT XAE Project (*.zip): Sample13.zip

In the Global Variable List, an IED data model function block instance ("fbIED") and one or more GSE function block instances for GOOSE communication and GSE management ("fbIEDGse") are required. This sample uses only one network adapter for GOOSE communication and three GoCBs in the IED data model.

Namespace: TcTelecontrol

Type: Global Variable List (GVL)

VAR_GLOBAL
    ipCreator  : I_AcsiCodeCreatorClass := GVL_AcsiVars.Creator.SetCodeRev(codeRev:=2).SetGuiVer(major:=1, minor:=0, build:=93, revision:=10);
    fbIED      : FB_IED_IED;
    fbIEDGse   : FB_IEDGse := (fbAdapter:=(ipIED:=fbIED, settings:=(sMulticastAddr:='01-0C-CD-01-00-01', eDispatchMode:=E_GseDispatchMode.NonPromiscuous)));
END_VAR

The "MAIN" program is called cyclically by a TwinCAT task and only needs to call the "P_IEC61850MAIN" program. "P_IEC61850MAIN" in turn calls the GSE function block that is responsible for receiving the GOOSE messages and mapping the received GOOSE data into the IED data model.

PROGRAM MAIN
VAR
END_VAR
P_IEC61850MAIN();
PROGRAM P_IEC61850MAIN
VAR
END_VAR
fbIEDGse();

In the sample implementation of the GSE function block, the Subscriber process is automatically activated for all three GoCBs after PLC startup. A rising edge at the "bUnsubscribe" variable disables the Subscriber process of the GoCBs.

FUNCTION_BLOCK FB_IEDGse IMPLEMENTS I_GseLinkStatusEventSink
VAR_INPUT
    fbAdapter    : FB_GseAdapterClass := (ipLinkStatus:=THIS^);
END_VAR
VAR
    eLinkStatus  : E_GseLinkStatus;
    bSuccess     : BOOL;
    ipError      : I_ServiceErrorClass;
    bSubscribe   : BOOL := TRUE;
    bUnsubscribe : BOOL;
END_VAR
bSuccess:= fbAdapter.Execute(ipError=>ipError);

IF bSubscribe THEN
    bSubscribe:= FALSE;
    bSuccess:= fbIED.IEDLD1.LLN0.gocb01.Subscriber.Enable(ipAdapter:=fbAdapter, ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb02.Subscriber.Enable(ipAdapter:=fbAdapter, ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb03.Subscriber.Enable(ipAdapter:=fbAdapter, ipError=>ipError);
ELSIF bUnsubscribe THEN
    bUnsubscribe:= FALSE;
    bSuccess:= fbIED.IEDLD1.LLN0.gocb01.Subscriber.Disable(ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb02.Subscriber.Disable(ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb03.Subscriber.Disable(ipError=>ipError);
ELSE
    bSuccess:= fbIED.IEDLD1.LLN0.gocb01.Subscriber.Execute(ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb02.Subscriber.Execute(ipError=>ipError);
    bSuccess:= fbIED.IEDLD1.LLN0.gocb03.Subscriber.Execute(ipError=>ipError);
END_IF

The GSE block implements the "I_GseLinkStatusEventSink" interface. The method: "OnLinkStatusChange" belongs to this interface implementation and is called whenever the status of the network connection (at the network adapter) changes. The PLC application can, for example, query or check the network connection status via "eLinkStatus" variable.

METHOD OnLinkStatusChange
VAR_INPUT
    ipAdapter : I_GseAdapterClass;
    eStatus   : E_GseLinkStatus;
END_VAR
VAR
END_VAR
eLinkStatus:= eStatus;

In the project tree under the I/O-Device branch you will find a network adapter instance named "GSE (RT Ethernet adapter)". This adapter instance must be configured accordingly, i.e. the I/O configuration must be adapted to the existing hardware and to the target platform on which the project is to run.
A new I/O configuration is also necessary if you change the target platform. This configuration must be done manually in TwinCAT XAE. In addition to the I/O configuration of the network adapter, a link must be established between the network adapter and the PLC function blocks for Goose communication. The link can be used to forward the data received from the network adapter to the instance of the function block: "FB_[IEDName]Gse". In the opposite direction the instance of the function block "FB_[IEDName]Gse" can forward the data to be sent to the network adapter.

Here you can find more information: RT Ethernet adapter Configuration.