Automatic code generation

Automatic code generation 1:

Automatic PLC code generation

The code generated by the TwinCAT Telecontrol Configurator is merely an application example, which can also be adapted from version to version. There are several possible ways of implementing a functional application with the IEC 61850 function blocks.

Automatic PLC code generation from the TwinCAT Telecontrol Configurator is carried out via the TwinCAT Automation Interface.
1. Pressing the button Create PLC Project in the toolbar(a) or in the Tools menu of the configurator(b) opens the Deploy TwinCAT Telecontrol dialog.
Automatic code generation 2:
2. In the Telecontrol tab you have the possibility to choose between client and server configuration ( Project type). If GOOSE Control Blocks are present in the project to be generated, the associated GOOSE type is also automatically selected.
Automatic code generation 3:
3. In the Solution tab, select a path (Solution Path) and assign the names for Solution, XAE Project and PLC Project. You can either create a new solution or integrate the changes into an existing solution using the TwinCAT Project Compare tool. To do this, first select the option Merge to existing Project and then an existing SLN file with the adjacent button "...".
Under Project data structure you can additionally select whether subfolders (Create sub folders) should be generated. By default, these are generated to map the configured data model in the folder hierarchy.
If you use longer names for the components of the data model, it may be necessary not to generate subfolders in order not to exceed the maximum path length.
Automatic code generation 4:
4. In the IDE tab you have the possibility to use a development environment of your choice for PLC code generation (Target IDE Version). The prerequisite for this is an existing TwinCAT integration in the development environment.
In addition, you can set whether the development environment should remain open after PLC code generation is complete ( Keep IDE open) and whether the development environment should be visible during PLC code generation (Show IDE during code generation).
Automatic code generation 5:
5. The last, concluding tab Summary provides a brief overview of the settings made.
The PLC code generation is started as soon as you press the Deploy button.
Automatic code generation 6:
During PLC code generation, the progress is displayed in the automatically opening log window.
6. To get more detailed information about the individual categories, such as IDE or TwinCAT PLC Code Generation, you can click on the respective category.
With the Bring to Front option the log window remains permanently in the foreground.
Automatic code generation 7:
After the generation is completed, a new instance of the selected development environment is opened. The PLC code is completely transparent so that the application can be written in the best possible way.
Automatic code generation 8:
Regardless of whether PLC code is generated for an IEC 61850 client or server, the Global Variable List TcTelecontrol forms the entry point.
VAR_GLOBAL
    ipCreator         : I_AcsiCodeCreatorClass := GVL_AcsiVars.Creator.SetCodeRev(codeRev:=2).SetGuiVer(major:=1, minor:=0, build:=93, revision:=10);
    fb[IEDName]       : FB_IED_[IEDName];
    fb[IEDName]Client : FB_[IEDName]Client := (fbConnection:=(ipIED:=fb[IEDName],settings:=(sRemoteHost:='127.0.0.1')));
    fb[IEDName]Gse    : FB_[IEDName]Gse := (fbAdapter:=(ipIED:=fb[IEDName], settings:=(sMulticastAddr:='01-0C-CD-01-00-00', eDispatchMode:=E_GseDispatchMode.NonPromiscuous)));
END_VAR

In addition to the data model, you will find the FB_[IEDName]Client for the client, for example. This is an application function block that encapsulates the FB_iec61850ClientClass and the complete communication. Here it is particularly important to specify the IP address of the server, which you can also do in the configurator.

If you generate a server, the Global Variable List looks slightly different.

VAR_GLOBAL
    ipCreator                 : I_AcsiCodeCreatorClass := GVL_AcsiVars.Creator.SetCodeRev(codeRev:=2).SetGuiVer(major:=1, minor:=1, build:=94, revision:=1);
    fb[IEDName]               : FB_IED_[IEDName];
    fb[IEDName]Server         : FB_iec61850ServerClass := (ipIED:=fb[IEDName], settings:=(bEnable:=TRUE, sLocalHost:='127.0.0.1'));
    fb[IEDName]ServerSession1 : FB_[IEDName]ServerSession := (fbConnection:=(ipServer:=fb[IEDName]Server, settings:=(bEnable:=TRUE)));
    fb[IEDName]Gse            : FB_[IEDName]Gse := (fbAdapter:=(ipIED:=fb[IEDName], settings:=(sMulticastAddr:='01-0C-CD-01-00-00', eDispatchMode:=E_GseDispatchMode.NonPromiscuous)));
END_VAR

The FB_iec61850ServerClass and the sessions required for communication are not encapsulated in an application function block, since multiple sessions can also be created here in parallel for different clients.