Open a TwinCAT 2 PLC project

Use of TwinCAT 3.1: Build 4026

The TwinCAT Package Manager with a current TwinCAT 3.1 4026 build is already installed.
1. Add the Outdated Feed.
2. Install the following workloads/packages from this feed:
TwinCAT 3.1.4024 Remote Manager Version: e.g. TwinCAT.StandardRM.XAE 4024.71.2
TwinCAT 2 Converter: TwinCAT.XAE.PLC.Tc2ProjectConverter
3. Open the TcXaeShell (32 bit).
4. Download the previously installed TwinCAT 3.1.4024 Remote Manager version.
Proceed as for TwinCAT 3.1 Build 4024.

Use of TwinCAT 3.1: Build 4024

TwinCAT XAE is started.
A TwinCAT project is opened.
Read the restrictions described below the following guide.
1. Select the PLC object in the Solution Explorer view.
2. In the Project menu or the context menu, select the Add Existing Item command.
3. In the dialog Open, select the desired Plc 2.x project or library from the file system. To search, you can set the file filter in the bottom right-hand corner of the dialog.
After that, the TwinCAT 2.x converter starts automatically.
4. The TwinCAT 2.x converter checks whether the project can be compiled error-free. If so, the converter processes the project automatically.
If the project contains visualization objects with placeholder variables that the converter cannot resolve, the respective visualizations are integrated directly as a grouping in place of the visualization references.
Library conversion: If a library for which no conversion rule has been defined yet is referenced in the project to be opened, the dialog Converting a library reference appears.
5. Define here whether and how the converter should replace the previous library reference by an up-to-date one.
If in doing so you select a library for which the project information is missing, the dialog Project information appears, which you have to fill out.
The converter loads the adapted project.

Restrictions when reusing a TwinCAT 2.x project in TwinCAT 3.1

Open a TwinCAT 2 PLC project 1:

Automatic syntax adjustments only with previous compilability

The syntax differs between TwinCAT 2 (TC2) and TwinCAT 3 (TC3) in certain respects (e.g. when initializing arrays). Please note that the converter only adapts the syntax at these code positions if the TwinCAT 2 project to be converted can be compiled on the TwinCAT 2 side.

Specifically, this means:

During the conversion process, the converter contained in TwinCAT 3 first compiles the selected TwinCAT 2 project with a TwinCAT 2 compiler. Syntax adjustments of the TwinCAT 2 code are only made during the creation of the TwinCAT 3 PLC project if this TwinCAT 2-side compilation is successful. The requirement for a successful TwinCAT 2-side compilation is that all necessary TwinCAT 2 libraries are made available to the converter. You can achieve this, for example, by inserting the libraries referenced in the TwinCAT 2 project into the folder C:\TwinCAT\3.1\Components\Plc\Converter\Lib. Alternatively, you can tell the converter the locations of the TwinCAT 2 libraries via the displayed conversion dialogs.

Compilation

It must be possible to compile the project in TwinCAT 2.x PLC Control without compilation errors. Nevertheless, TwinCAT issues warnings during the compilation. These are caused by implicit conversions that can lead to the loss of information (for example due to the change of a sign).

TwinCAT 3.1 checks case statements against the switch variable: CASE USINT OF INT is not checked in TwinCAT 2.x, but there is an error message when importing into TwinCAT 3.1.

Libraries

All variables and constants used in a library also have to be declared in this library. It must be possible to compile the library in TwinCAT 2.x error-free.

Syntactic and semantic restrictions

  • FUNCTIONBLOCK is no longer a valid keyword in place of FUNCTION_BLOCK
  • A ":" must follow after TYPE (declaration of a structure).
  • ARRAY initialization must be enclosed in parentheses.
  • A local declaration of an enumeration is no longer possible, except within TYPE: in the case of a TwinCAT 2.x import a local enumeration declaration is automatically converted into an explicit type definition.
  • INI is no more supported (you have to replace this in the code by the Init method).
  • In function calls, it is no longer possible to mix explicit parameter assignments with implicit assignments. Therefore, the order of the parameter input assignments can be changed:
    fun(formal1 := actual1, actual2); // → Fehlermeldung
    fun(formal2 := actual2, formal1 := actual1); // gleiche Semantik wie folgende Zeile:
    fun(formal1 := actual1, formal2 := actual2);
  • TwinCAT 2.x pragmas are not converted. They generate a warning in TwinCAT 3.1.
  • The TRUNC operator now converts to the data type DINT instead of INT; in the case of a TwinCAT 2.x import, TwinCAT 3.1 automatically adds an appropriate type conversion.

Memory

  • In contrast to TwinCAT 2, TwinCAT 3.1 has an 8-byte alignment. For further details and samples, see Reference Programming > Alignment.
  • Instances of the data type STRING are pre-initialized in TwinCAT 2 by zeroing the entire memory area. In TwinCAT 3.1, however, only the first byte of such an instance is zeroed. Due to the null termination, the instance is also empty.

Visualization

Placeholders and their replacement

Placeholder

VAR_INPUT

Use

Replacement

 

MAIN.$LocalVar$.aArr[0]

localVar: MyStruct;

localVar.aArr[0]

localVar := MAIN.myStructVar

 

$Var$.aArr[0]

Var : MyStruct;

Var.aArr[0]

Var := MAIN.myStructVar

 

MAIN.myStructVar.aArr[$Index$]

Index : INT;

MAIN.myStructVar.aArr[Index]

Index := 0

Problematic placeholders

  • Placeholder within a text:
    Text: $axle$-Axis
    Correction:
    localVar : STRING;
    Text: %s-Axis
    TextVariable : localVar
  • Placeholder describes only a part of a variable name:
    axis$axis$track$track$.fActPosition
    Correction:
    Define only one placeholder for the placeholder axis$axis$track$track$.
    axis_spur : MyFunctionBlock;
    Then pass the corresponding instance of the function block directly.
    axis_spur := MAIN.axis1spur2;
  • Placeholder is replaced by an expression:
    $Expression$ → MAIN.var1 + MAIN.var2
    Correction:
    You must pass the expression to an auxiliary variable and then pass this auxiliary variable as an instance.
  • Placeholder describes a program name: $Program$.bToggle → MAIN.bToggle D
    The converter cannot transfer this form of placeholder replacement to TwinCAT 3.1. However, they are rarely used in practice.
  • Placeholder is replaced by different types:
    $Var$
    → Replacement 1 : MAIN.n (INT)
    → Replacement 2 : MAIN.st (STRING)
    Solution:
    Define two different placeholders in the interface.
  • The visualization is located in a library. You only replace the placeholders later from any project when you use the visualization there.
    Correction:
    Here you must manually replace the TYPE_NONE data types. However, there is a possibility for you to integrate the library in a project and for the placeholder to be replaced properly. If you now import this project, the data type will also be determined correctly in the library.

Non-importable items

Trend, ActiveX – the import is not possible because the implementation is very different. In TwinCAT 3.1 a corresponding warning is given and a corresponding manual reconstruction is necessary.

Programming languages

ST, IL, FBD

No restrictions

 

LD

TwinCAT 3.1 imports function blocks with parallel branches so that the part before the branch is repeated for each branch. This corresponds to the generated code that TwinCAT 2.x generates for parallel branches.

Open a TwinCAT 2 PLC project 2:

 

SFC

  • Step variables explicitly declared by the user must be declared locally in the SFC editor. You must not declare them as VAR_INPUT, VAR_OUTPUT or VAR_INOUT, because TwinCAT 3.1 cannot automatically adapt the calls. Explanation: Steps no more use boolean variables for the management of the internal states in TwinCAT 3.1, but also structures of the type SFCStepType.
  • Identifier: The following identifiers may not begin with an underscore:
    • Names of IEC actions in the tree
    • Variables that are called in an IEC association list
    • Names of programmed-out transitions

Explanation: Implicit variables that TwinCAT 3.1 creates for actions are given an underscore as a prefix in TwinCAT 3.1. An invalid identifier with a double underscore would result.

 

CFC

  • Large function blocks: The layout of large function blocks may suffer a loss of quality as a result of the import; the function block box modules may overlap significantly.
  • Macros: Macros cannot be imported.

See also: