Exporting TIA Portal Blocks and Tags for OPC UA Development

David Krause16 min read
SiemensTIA PortalTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Problem Overview: Exporting TIA Portal Data for OPC UA Development

Engineers building OPC UA clients or server-side Address Space models need a complete inventory of every block, tag, and data type defined in a Siemens TIA Portal project. Manual transcription of hundreds of tags is error-prone, and OPC UA Information Models require consistent naming, data type mapping, and structural fidelity. TIA Portal provides several built-in export paths plus a programmable automation interface (TIA Openness) that together cover everything from one-off inspection of a single data block to bulk extraction of an entire multi-PLC project.

The export pipelines documented here apply to S7-1200, S7-1500, ET 200SP, and WinCC Runtime stations configured inside a single TIA Portal project. Output formats covered include Siemens XML (the de facto interchange format for SCL sources and tag tables), CSV (suitable for direct loading into OPC UA Address Space design tools), and the TIA Openness object model for fully scripted extraction.

Compatibility: Examples are validated against TIA Portal V16, V17, and V18. Where V16 differs from V17/V18 in the export API surface, the differences are noted inline. TIA Openness V16 ships a different DLL signature than V17/V18; always target the Openness version that matches the TIA Portal build you compile against.

Prerequisites

Before starting any export procedure, confirm the following prerequisites are in place:

  • TIA Portal installation with a license that activates the Openness API. The standard TIA Portal STEP 7 Basic/Professional license is sufficient for the right-click source generation and tag-table export paths. TIA Openness requires either the public Openness license bundled with TIA Portal Professional or a separately purchased Openness SDK package.
  • Project state: the TIA Portal project must compile cleanly. Open the project, compile the S7 program (PLC → Compile → Software (rebuild all)), and resolve any compiler errors before exporting. Blocks with compilation errors will not be readable through the Openness API and may produce empty XML exports.
  • Administrative rights: TIA Openness automation runs against a TIA Portal instance and requires read/write access to both the TIA Portal installation directory and the project directory. Run Visual Studio or your build host as Administrator on locked-down workstations.
  • Visual Studio / .NET Framework 4.8: when building C# or VB.NET automation scripts, install the .NET Framework 4.8 runtime. The Openness API is built on the .NET Framework 4.8 surface even when consumed from newer .NET hosts.
  • TIA Portal Gateway service: confirm the "TIA Portal Vxx Gateway" Windows service is running. Openness automation requires the Gateway service to be active even when launching TIA Portal in WithoutUserInterface mode.
  • OPC UA design tool: a downstream tool to consume the exported data. Examples include Unified Automation UaModeler, the OPC Foundation NodeSet2 XML schema, Prosys OPC UA Browser, or a custom Python/Node-RED OPC UA builder.

Method 1: Generate Source from a Single Data Block

The fastest path for inspecting a single DB is the right-click Generate source feature. The export produces a re-importable SCL source file that lists every tag with its data type, initial value, structural offset, and comment.

  1. In the project tree, expand PLC_x → Program blocks.
  2. Right-click the target DB (for example DB_MotorData).
  3. Select Generate source from blocks from the context menu.
  4. In the Generate source dialog, choose a destination folder inside the project (typically the Sources folder) and assign a source name (for example DB_MotorData_Source).
  5. Tick the block(s) you wish to export. The dialog supports multi-select, so you can pick an entire folder of DBs in one pass.
  6. Confirm with OK.
  7. Open the generated source by double-clicking it under PLC_x → External source files. The SCL editor shows the full declaration including nested STRUCTs, ARRAY bounds, initial values, and comments.

The generated source file is plain text and can be copied into any external editor. It is also re-importable: right-click on a source file and choose Generate blocks from source to recreate the DB in another project.

The same right-click path works for the following elements:

  • FB / FC / OB blocks in SCL, STL, and LAD/FBD representation. Generated source captures the interface and code section.
  • User-defined types (UDTs): choose Generate source from PLC data types to dump the full UDT declaration including nested STRUCTs.
  • Tag tables: covered in Method 2.
Watch out: "Generate source" only exports the block shell and declaration. It does not include the runtime instance DB values nor the program code logic in a fully executable form. For FB program logic, generate source from the FB (which includes its code section), not from its instance DB.

Method 2: Export PLC Tags to Excel and CSV

PLC tag tables (the central HMI/OPC tag database in TIA Portal) can be exported as Excel-compatible files. The export path goes through the clipboard or through the dedicated Export → Tags (CSV) menu.

  1. Open PLC_x → Watch tables and force tables or PLC_x → PLC tags → Show all tags.
  2. Select the tag table (default name: Default tag table) or a custom tag table.
  3. Press Ctrl+A to select all rows, then Ctrl+C to copy to the clipboard.
  4. Paste into Excel. Columns come pre-ordered as: Name | Path | Data type | Address | Comment.
  5. Use File → Save As → CSV (Comma delimited) (*.csv) to persist the file.

For batch export of every tag table in the project, use the TIA Portal Export function:

  1. Right-click the PLC station (for example PLC_1500 [CPU 1515-2 PN]) in the project tree.
  2. Choose Export → Tags (CSV). In TIA Portal V17/V18 the menu path is Tools → Export tags in the tag table toolbar.
  3. Select the destination CSV file. The first row is a header row containing the language-specific tag attributes.

The CSV column layout follows the column order configured in the tag table. The exported columns typically include:

Column Description OPC UA Mapping
Name Symbolic tag name inside the PLC tag table. BrowsePath segment.
Path Fully qualified name including any tag group prefix. BrowsePath full chain.
Data type S7 data type (Bool, Int, Real, String, WString, DTL, etc.). NodeId data type (Boolean, Int16, Float, String, DateTime).
Address Absolute address (for example %DB10.DBX0.0, %MW100). Optional NodeId namespace URI.
Comment Multi-language description. OPC UA Description localizedText.
HMI visible Whether the tag is reachable from HMI/OPC. Filter; only export where visible = true.
HMI accessible Whether the HMI/OPC UA server can read/write the tag. Maps to OPC UA AccessLevel.

Refer to the Siemens Exporting PLC tags entry in the TIA Portal V16 system manual for the canonical column order reference: Exporting PLC tags — TIA Portal Help.

Method 3: XML Export of Code Blocks

The native interchange format for code blocks in TIA Portal is XML. XML export is the preferred path for downstream OPC UA tools that build structured Address Spaces because XML preserves nested type information, ARRAY bounds, and UDT references exactly.

  1. Select one or more blocks in the project tree.
  2. Choose File → Export → Export blocks (XML).
  3. Pick a target XML file. TIA Portal writes the entire selection into a single XML document using the Siemens internal schema.
  4. Inspect the XML with any text editor. Every tag is encoded with its <Name>, <DataType>, <StartValue>, <Comment>, and STRUCT member path.

The official Siemens TIA Portal Help entry that documents the export formats (PLC blocks) is here: Overview of export formats (PLC blocks).

The XML schema is verbose but stable across TIA Portal V15.1 through V18. Key element families in the exported XML:

  • <Document> — root node.
  • <Engineering> — version metadata (TIA Portal build, schema version).
  • <SW.Blocks.GlobalDB>, <SW.Blocks.InstanceDB>, <SW.Blocks.FB>, <SW.Blocks.FC>, <SW.Blocks.OB> — block type discriminators.
  • <Interface> — block interface (input, output, in-out, static, temp sections).
  • <Member> — every individual tag including nested STRUCT members.
  • <Attribute> — block attributes (Author, Family, Title, Version).

A typical Member element looks like:

<Member Name="MotorSpeed" DataType="Real" StartValue="0.0" Comment="Measured motor RPM"/>

When transforming the XML into OPC UA Nodeset2 XML, map the Siemens types with the lookup table below.

S7 Type OPC UA Built-in Type Notes
Bool Boolean Bit-packed.
Byte, Word, DWord, LWord Byte, UInt16, UInt32, UInt64 OPC UA UInt counters; map signed S7 types to OPC UA Int counterparts.
SInt, Int, DInt, LInt SByte, Int16, Int32, Int64 Two's complement.
USInt, UInt, UDInt, ULInt Byte, UInt16, UInt32, UInt64 Unsigned.
Real, LReal Float, Double IEEE-754 32/64-bit.
String, WString String S7 max 254 chars; OPC UA no fixed limit.
Char, WChar Byte / UInt16 Often mapped to String when the field is character-oriented.
DTL DateTime 12-byte S7 DTL maps directly to OPC UA DateTime (Int64 Unix epoch ms).
TOD (Time_of_Day) DateTime Encode time-of-day as DateTime with epoch = today's date.
Time, LTIME Int32 / Int64 S7 Time is DInt milliseconds; map to Int32.
Date, Date_And_Time DateTime Convert legacy date formats to OPC UA DateTime.
ARRAY[..] OF T ExtensionObject / T array Build OPC UA Variable with ValueRank=1 and array dimensions.
STRUCT Structured DataType (custom) Define a custom OPC UA DataType node under Types/Structured.
UDT (PLC data type) Custom DataType Each UDT becomes one custom OPC UA DataType.

Method 4: TIA Openness Automation

For projects with hundreds of blocks and dozens of tag tables, manual export does not scale. The TIA Openness API exposes the project tree as a .NET object model that you traverse programmatically to dump every block, every tag, and every interface member into CSV, JSON, or OPC UA Nodeset2 XML.

Openness DLL Reference

TIA Openness exposes the following primary assemblies, located in the TIA Portal installation directory (default C:\Program Files\Siemens\Automation\Portal V18\PublicAPI\V18):

Assembly Purpose
Siemens.Engineering.dll Core project tree (Project, Device, PlcSoftware, etc.).
Siemens.Engineering.Hmi.dll HMI Runtime tag access.
Siemens.Engineering.AddIn.dll Openness Add-In lifecycle (TiaPortal, ProjectOpenness).
Siemens.Engineering.SW.Blocks.dll Program block object model (FB, FC, OB, DB, InstanceDB, GlobalDB).
Siemens.Engineering.SW.Types.dll PLC data type (UDT) object model.
Siemens.Engineering.Tags.dll PLC tag table object model.

Openness C# Snippet — Dump Every Tag in a Project

The following console snippet (C#, .NET Framework 4.8, TIA Portal V18) opens a project from disk, walks every PLC, every tag table, and every tag, and writes the result to a CSV file.

using System; using System.IO; using System.Linq; using System.Text; using System.Globalization; using Siemens.Engineering; using Siemens.Engineering.HW; using Siemens.Engineering.SW; using Siemens.Engineering.SW.Tags; class TiaExporter { static int Main(string[] args) { if (args.Length < 2) { Console.Error.WriteLine("Usage: TiaExporter.exe <projectPath> <outputCsv>"); return 2; } var projectPath = args[0]; var outCsv = args[1]; using var portal = new TiaPortal(TiaPortalMode.WithUserInterface); var project = portal.Projects.Open(new FileInfo(projectPath)); using var writer = new StreamWriter(outCsv, false, Encoding.UTF8); writer.WriteLine("PLC,TagTable,Name,Path,DataType,Address,Comment,Visible,Accessible"); foreach (Device device in project.Devices) { var sw = device.GetService<PlcSoftware>(); if (sw == null) continue; foreach (PlcTagTable table in sw.TagTables) { foreach (PlcTag tag in table.Tags) { var address = tag.Addresses?.FirstOrDefault()?.ToString() ?? ""; var visible = tag.VisibleInHmi ? "TRUE" : "FALSE"; var accessible = tag.AccessibleFromHmi ? "TRUE" : "FALSE"; writer.WriteLine(string.Join(",", Csv(device.Name), Csv(table.Name), Csv(tag.Name), Csv(tag.Path), Csv(tag.DataTypeName), Csv(address), Csv(tag.Comment?.GetText(CultureInfo.GetCultureInfo("en-US")) ?? ""), visible, accessible)); } } } return 0; } static string Csv(string s) => "\"" + (s ?? "").Replace("\"", "\"\"") + "\""; }

The snippet compiles against Siemens.Engineering.dll V18. To retarget for V17, swap the assembly references to the V17 path and verify the TiaPortalMode enum is still valid in your referenced assembly.

Openness C# Snippet — Walk Every Block Interface Member

DBs and FB instance interfaces carry nested members; the Openness API exposes them through the PlcBlock → BlockInterface → Member chain.

using Siemens.Engineering.SW.Blocks; static void WalkBlock(PlcBlock block, TextWriter w, int depth = 0) { string pad = new string(' ', depth * 2); w.WriteLine($"{pad}BLOCK {block.Name} ({block.Type})"); if (block is GlobalDB gdb) { foreach (var member in gdb.Interface.Members) WriteMember(member, w, depth + 1); } else if (block is InstanceDB idb) { foreach (var section in idb.Interface.Sections) foreach (var member in section.Members) WriteMember(member, w, depth + 1); } // FB, FC, OB share the same Sections pattern } static void WriteMember(PlcBlockInterfaceMember m, TextWriter w, int depth) { string pad = new string(' ', depth * 2); w.WriteLine($"{pad}{m.Name} : {m.DataTypeName}"); if (m is PlcBlockInterfaceStructMember sm) foreach (var child in sm.Members) WriteMember(child, w, depth + 1); }
Openness V16 vs V17/V18: In V16 the class names use SW.Blocks.PlcBlock with a different namespace tree. In V17 the namespace was reorganized and many members moved to Siemens.Engineering.SW.Blocks. Code targeting V16 will not compile against V18 without modification. Use the Openness reference assemblies that ship with the matching TIA Portal version.

Openness C# Snippet — Emit OPC UA Nodeset2 XML

Combine the previous two snippets with a simple XML writer to emit OPC UA Nodeset2 XML directly from the project. The minimal stub below emits one UAVariable per exported DB tag.

using System.Xml; static void WriteNodeset(IEnumerable<PlcTag> tags, string nodesetPath, string namespaceUri) { var settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 }; using var xw = XmlWriter.Create(nodesetPath, settings); xw.WriteStartDocument(); xw.WriteStartElement("UANodeSet"); xw.WriteAttributeString("xmlns", "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"); xw.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); foreach (var t in tags) { xw.WriteStartElement("UAVariable"); xw.WriteAttributeString("NodeId", $"ns=1;s={namespaceUri}/{t.Path}"); xw.WriteAttributeString("BrowseName", t.Name); xw.WriteAttributeString("DataType", MapS7ToOpcUa(t.DataTypeName)); xw.WriteElementString("Description", t.Comment?.Text ?? ""); xw.WriteEndElement(); // UAVariable } xw.WriteEndElement(); // UANodeSet xw.WriteEndDocument(); } static string MapS7ToOpcUa(string s7) => s7 switch { "Bool" => "Boolean", "Int" => "Int16", "DInt" => "Int32", "LInt" => "Int64", "Real" => "Float", "LReal" => "Double", "String" => "String", "DTL" => "DateTime", "Time" => "Int32", _ => "BaseDataType" };

Preparing the Export for OPC UA Consumption

Once tags and blocks are dumped to CSV or XML, the OPC UA Information Model is built in three steps:

  1. Generate a Nodeset2 XML. The OPC Foundation's Nodeset2 schema (http://opcfoundation.org/UA/2011/03/UANodeSet.xsd) is the canonical Address Space exchange format. Write one <UAVariable> per exported tag, one <UAObjectType> per exported UDT, and one <UAMethod> per exported FB.
  2. Choose a namespace URI. The OPC UA namespace URI must be globally unique; derive it from your company domain (for example urn:company:plc:projectname:v1). Avoid versioned hostnames; reserve the right to renumber namespace indices when the project is recompiled.
  3. Map the data types. Use the lookup table in Method 3 for the S7 → OPC UA conversion. For STRUCT members, define a custom DataType in Nodeset2 and reference it from the parent Variable via DataType="ns=1;i=<StructuredTypeId>".

For projects targeting the SIMATIC S7-1500 OPC UA Server (built into every S7-1500 CPU firmware V2.0+), the server exposes only those tags marked "HMI visible" and "HMI accessible". Verify those flags are set on every tag intended for OPC UA consumption before commissioning.

Verification Steps

After the export, run these checks before declaring the OPC UA Address Space ready for production:

Check Procedure Expected
Tag count parity Compare total tags in the CSV/XML to Project.Devices[*].Software.TagTables[*].Tags.Count. Counts match exactly.
Type coverage For each unique DataType in the export, ensure the OPC UA Nodeset2 contains a matching DataType node. No unknown types.
Initial values Sample 10 tags across 3 DBs; load values from CSV and compare to TIA Portal offline view. Exact match.
Compile cleanliness Re-compile the TIA Portal project post-export. Zero errors, zero warnings.
OPC UA browse Use UA Expert to connect to the S7-1500 OPC UA server and browse the tag path. Every exported tag appears with correct data type.
Read/Write test Read each exported tag, compare value to Watch Table online value. Match within one scan.
Round-trip Import the generated Nodeset2 XML into UaModeler or Prosys OPC UA Browser. No parse errors; structure renders correctly.

Troubleshooting Matrix

Symptom Likely Cause Remedy
Generate Source menu greyed out on a DB. The project is not compiled, or the DB has compilation errors. Right-click the PLC station → Compile → Software (rebuild all). Resolve all errors before re-attempting export.
XML export produces an empty file. The selected blocks are password-protected with no password supplied. Open the block properties, supply the know-how-protection password, retry export.
Openness script throws EngineeringException at startup. Mismatch between Openness DLL version and TIA Portal install. Reference the DLLs from the PublicAPI folder of the installed TIA Portal version.
CSV export missing some tags. Tags with "HMI visible = false" are filtered out by the OPC UA server filter. Either enable HMI visibility in TIA Portal or strip the filter in the export script.
UDT nested members missing in XML. The XML export does not flatten nested STRUCTs. Use the Openness API (Method 4) to recursively walk Members; the XML export is flat.
Openness script cannot find any PLC. The project was opened with TiaPortalMode.WithoutUserInterface in a session where the TIA Portal Gateway service is not running. Start the "TIA Portal Vxx Gateway" Windows service and retry.
STRING tags truncated at 254 chars in CSV. S7 STRING is fixed-length 254 chars; CSV column shows the declared length, not the value. Export value at runtime via the Openness API or via the OPC UA server live read.
Exported file path contains non-ASCII characters. TIA Portal cannot open projects whose paths contain Unicode characters outside the system code page. Move the project to a path with ASCII-only characters.
OPC UA NodeId collisions across multiple PLCs. Tag names are not unique project-wide. Prepend the PLC station name (for example PLC1.Motor.Speed) before generating NodeId.
Openness PlcSoftware returns null. The Device is not an S7 PLC (could be an HMI, drive, or third-party device). Filter devices by Device.TypeIdentifier or by checking PlcSoftware null before dereferencing.
Exported CSV shows wrong data type for ARRAY of UDT. CSV cell flattens nested UDT name to its top-level reference only. Use XML export (Method 3) or Openness (Method 4) to retain nested type information.
OPC UA server rejects tag with "Bad_AttributeIdInvalid". The tag's access level is set to read-only on the OPC UA server side but the client requests write. Adjust "HMI accessible" in TIA Portal tag properties or change client request.

Field-Proven Tips

  • Tag name length: TIA Portal permits up to 125 characters per tag name, but OPC UA namespace URIs add prefix characters; reserve ≤ 80 characters per tag name for clean BrowsePaths.
  • Reserved characters: Avoid dots, slashes, and hash marks in tag names; they collide with OPC UA BrowsePath delimiters. Replace dots with underscores in the export transformation.
  • Multi-language comments: The CSV export contains only one language column. If your project supports multiple runtime languages, iterate over Comment.GetText(CultureInfo) for each configured culture.
  • UDT versioning: If a UDT changes between firmware revisions, version the OPC UA DataType (for example MotorState_v1, MotorState_v2) so clients can detect schema drift.
  • Bulk operations: TIA Openness scripts execute inside the TIA Portal process. For very large projects (>1000 DBs), chunk the work into multiple PlcTagTable iterations and write incrementally to avoid memory pressure.
  • Bookmark the Help Portal: Both V16 help entries referenced in this article remain valid as cross-version references: Exporting PLC tags and Overview of export formats (PLC blocks).
  • Compare-and-merge workflow: When the source-of-truth PLC project is updated, re-run the Openness script and diff the output CSV against the previous run. Commit both files to your version-control system; this gives you a tag-level audit trail for the OPC UA Address Space.
  • License activation: Openness automation requires the Openness license checkbox under Start → Siemens Automation → TIA Portal Vxx → License analysis. Verify the license status before debugging script errors that may in fact be license-related.

FAQ

What is the fastest way to export a single data block's tags?

Right-click the DB in the project tree, choose Generate source from blocks, and confirm. The resulting SCL source file lists every tag with type, offset, and initial value. For deeper inspection, open the source in the SCL editor.

Can I export tags to Excel directly?

Yes. Open the tag table, press Ctrl+A then Ctrl+C, and paste into Excel. For automated CSV export use the TIA Portal Export → Tags (CSV) function or the TIA Openness API as shown in the C# snippet above.

Which TIA Portal versions support TIA Openness?

TIA Openness ships with TIA Portal Professional V14 and later. Each major TIA version ships its own Openness DLLs under PublicAPI\V<xx>; compile your automation against the matching version. V16, V17, and V18 are the most commonly deployed in production today.

Why do some tags not appear in the OPC UA server?

The S7-1500 OPC UA server only exposes tags with both "HMI visible" and "HMI accessible" flags set. Verify these in the tag table properties; without them, the CPU filters the tag out of the published Address Space regardless of any external export script.

Does XML export preserve nested STRUCT and UDT members?

The XML export captures the full structural declaration, but downstream consumers must parse the nested <Member> hierarchy. The Openness API is preferable when STRUCTs are deeply nested because it exposes recursive Members collections directly without XML parsing.

Back to blog