Getting Started
The following section describes the basic operating principle of the TC3 XML server, based on short examples.
The global variable .Var1 of type DINT is defined in the PLC. It should be saved in an XML file as follows:
<dataentry>
<Var1>10</Var1>
</dataentry>
To this end the input variables of the function block FB_XmlSrvWrite have to be set as follows:
fbRead.pSymAddr := ADR(value1);
fbRead.cbSymSize := SIZEOF(value1);
fbRead.sFilePath :='C:\Test.xml'; (*Pfad zur XML-Datei*)
fbRead.sXPath := '/dataentry/Var1';
The root element name of the variables in the XML file is freely selectable. Simply adapt the path in the input variable sXPath. An XML file may contain definitions for several variables:
<dataentry>
<Var1>10</Var1>
<Var2>100</Var2>
<Var3>
<a>100</a>
<b>10</b>
</Var3>
</dataentry>
To access the symbol .Var3.a, for example, sXpath must be set to '/dataentry/Var3.a'.
Structures
XML files have the same hierarchical structure as the PLC. Individual subelements of the XML file may be skipped: The subelements of the structure must have the same names as in the PLC, otherwise they are skipped. If subelements of the XML file cannot be converted to the correct data type, they are also skipped.
Example:
The global variable .Var2 of type ST_MYSTRUCT is defined in the PLC:
TYPE ST_MYSTRUCT:
STRUCT
a: UINT;
b: DINT;
c: LREAL;
d: STRING;
END_STRUCT
END_TYPE
The XML file could then look as follows:
<variables>
<Var1>10</Var1>
<Var2> <!-- sXPath := '/variables/Var2' -->
<a>100</a>
<b>-10</b>
<c>1.2</c>
<d>Hallo</d>
</Var2>
</variables>
In this case all subelements are defined fully and correctly, so that the variable is fully initialized. In the following example, on the other hand, only subelement c is serialized:
<variables>
<Var1>10</Var1>
<Variable2> <!-- sXPath := '/variables/Variable2' -->
<Info>dies ist ein Test</Info>
<a>-100</a>
<c>1.2</c>
</Variable2>
</variables>
Subelement a cannot be converted because it is negative and UINT is required. Subelement b is missing completely. The tag <Info> is skipped, because it is not defined in the PLC file.
Arrays
In order to specify an array index, the attribute "index" has to be used for the individual array elements. Individual array elements can be omitted, in which case they will be skipped.
Example:
A variable .array1 of type ARRAY[1..4] OF DINT is defined in the PLC. The XML file will then look as follows:
<dataentry>
<array1 index="1">10</array1>
<array1 index="2">10</array1>
<array1 index="3">10</array1>
<array1 index="4">10</array1>
</dataentry>
Requirements
Development environment |
Target system type |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.1 Build 4011 |
PC or CX (x86, x64, ARM) |
Tc2_XmlDataSrv |