TIA Direct Export

How Export and Compare read TIA projects directly, with CLI options and conflict handling.

VS Code uses the direct exporter for Export, Compare, diff previews, Take TIA Version, and post-import refresh. A comparison exports the entire selected PLC into a fresh temporary directory and compares its sources and .s7res files with the workspace and the last synchronization baseline. It does not need TIA object fingerprints or a compile just to compare.

plccheck tia export software "Demo" --plc PLC_1 --engine direct --live --out exported
plccheck tia diff --project "Demo" --plc PLC_1 --root exported --engine direct exported/PLC_1

--live saves an open project and copies its persistence files while holding TIA exclusive access. VS Code uses this for explicit exports and manual comparisons even when its binding contains an .ap21 path, so unsaved TIA edits are included. CLI exports of an explicit project file without --live retain their offline behavior. Direct comparison uses a live snapshot for project paths/names; an explicit .zap21 compares the archive.

tia diff --engine openness remains the CLI default and assesses each file the way import does (see Import validation). Direct comparison requires --project and --plc. --snapshot-out <empty-directory> retains the comparison export for a caller that owns its lifetime; otherwise it is removed when the command finishes.

VS Code exports use --allow-partial: successfully rendered items remain usable when another PLC object or project-library definition is unsupported or cannot be rendered. Export warnings identify those objects and prevent stale-file pruning. Comparison snapshots record unavailable PLC identities separately; their existing local entries are unknown, never reported as deleted, and previews/replacements refuse those objects. Other selected objects remain comparable and fetchable. Invalid persistence, filesystem errors, and colliding sanitized object paths still fail the operation. Ordinary CLI exports remain strict by default; partial exports cannot use --delete-stale.

Baselines and changes

Export metadata includes:

  • sourceHash: SHA-256 of the exact exported source bytes, retained for existing tooling and old baselines.
  • sourceExtension: the synchronized source format, so format-only changes are attributed to the changed side. Older sidecars without this baseline require reconciliation when formats differ.
  • contentHash: SHA-256 after removing a UTF-8 BOM, normalizing line endings, and ignoring final newlines. Source-line whitespace is preserved. XML export provenance (DocumentInfo) is excluded.
  • resourceHash: SHA-256 of the accompanying resource file, or an empty string when no resource file existed.
  • tiaFingerprint: the hash of the object's TIA fingerprints that the Openness exporter records. The direct exporter builds it from the fingerprints TIA stored with a block or data type, and leaves it empty when TIA has not stored valid ones. Tag tables have none.

Local and remote content are compared independently with that baseline. One-sided changes appear on the corresponding side; different changes on both sides are conflicts. Matching current content is unchanged even if both sides differ from the baseline. Older metadata can still use its exact sourceHash; ambiguous resource changes without a resource baseline remain unknown. Comparison does not overwrite sources or manufacture a new baseline from edited local content.

Folder comparisons include new TIA objects; file comparisons stay within the selected identities. Object identity includes the PLC, block/type kind, and TIA group path. A format change retains the existing local path in the result. Deleted local sources with surviving metadata remain unknown and are never interpreted as a request to delete from TIA. Missing TIA objects remain distinguishable from genuinely new local sources through their existing metadata.

Failed or incomplete exports never publish a comparison or trigger stale-file pruning. Tag tables under PLC tags participate alongside blocks and data types. Nested PLC roots remain excluded. Ambiguous source identities and invalid metadata fail the comparison.

VS Code keeps the accepted sidebar comparison's snapshot for diff previews. Failed or superseded comparisons retain it, and import-only checks do not replace it. Mutations, backend changes, and disposal invalidate it; unlinking or rebinding removes obsolete cached snapshots. Binding checks prevent reusing it for a different project. Take TIA Version and post-import refresh use fresh exports.

Fetches use metadata identity when available, so a locally moved or renamed source can still preview its original TIA object. Take TIA Version restores the snapshot's original filesystem location, removes the obsolete local representation, and refuses to overwrite a different file already occupying the restored location.

Project-library types

Both exporters write a .meta.json next to each document under Types with the type GUID, version GUID, version number, state (Committed or InWork) and the same content hashes as PLC sources. TIA's .libinfo and .libint stay as TIA writes them. They have no hash or version GUID for an in-work version.

Comparing a PLC folder also compares the .liblink files in it, the Types definitions they use and the types those depend on. A Types folder or document can be passed directly. Both engines take the export root from the inputs: the folder above an input's PLC folder (the nearest folder with a .plc.json), or an input folder that holds PLC folders. --root only places inputs outside every PLC folder, such as Types passed on its own. Rows for definitions have kind library-type and are matched by type GUID, rows for .liblink files have kind library-link. Only the definitions a comparison selects have to be valid, so a local-only file under Types that is not one fails only a comparison that selects it. Reasons:

  • library-version-changed: TIA has another version than the baseline. Every release and every replaced in-work version gets a new version GUID, so this also shows when the document is the same.
  • library-type-in-work: TIA has an in-work version of the type. change.testInstancePlc names the PLC that holds the test instance, and on a .liblink it means this PLC holds it. An in-work version only applies to that PLC, so this is reported for as long as it lasts, as unknown when nothing else changed. TIA can edit an in-work version without giving it a new version GUID, so a local edit of the type's document is both-changed, and the import needs --overwrite for it.
  • library-version-behind: the instance behind the .liblink uses an older version than the type's current one, for example in a PLC that was not updated after a release. Also reported for as long as it lasts.
  • library-link-changed: the .liblink points to another version in TIA, or was added or removed there. Only the TIA version can be taken, which removes the local file when TIA has none. A .liblink is never imported.

A definition exported before its .meta.json had the version GUID is tia-only with reason missing-metadata until the next export. A local edit of a definition is local-changed with reason content-changed. tia import --library-types imports it as a new version (see below). tia export --engine direct --json lists in-work types and the PLC holding each test instance in libraryTypesInWork. In VS Code the type and .liblink rows of every linked PLC in a destination show in one TIA Portal library Source Control provider for that destination, not in the PLC providers. A type in work or an instance on an older version with nothing else changed is listed in its own group and offers only Open Diff, since taking the TIA version would change nothing. A row whose content did change stays in its change group. A type several PLCs report shows the row of the newest compare. Library rows offer Open Diff and Take TIA Version, which writes a type into Types with its .libinfo and .libint. An edited type also offers Import, which runs tia import --library-types (see below). Import in that provider's title bar, or on Types in the Explorer, compares every linked PLC in the destination first and imports the edited documents in the selection. Conflicts are held back and import from their own row. A document without a library baseline is held back too. An edited one imports from its own row, and Take TIA Version or an export creates the baseline of one that was not edited. Compare in that provider, or on the Types folder in the Explorer, compares every linked PLC in the destination. A compare of a folder inside a PLC keeps the library-type rows of the last full compare.

tia diff --engine openness reports the same rows. The bridge writes the project library and the .liblink files in the folders the inputs select into a temporary snapshot, with the code an export uses, and plccheck compares that snapshot like the direct one. The snapshot starts as a copy of the local Types folder, so TIA only exports the versions that changed since the export, in-work versions and locally edited definitions. With the Openness engine a folder that contains PLC folders or Types selects all of them.

Importing an edited type

tia import --library-types imports edited documents under Types. Pass the Types folder or single documents, with --root at the export root. It takes no PLC sources, import those in a separate run. TIA can not change a released version and refuses imports into a test instance, so the import goes through the library and leaves every PLC on the new version:

  1. An instance of the type's current version is put in work, in the --plc PLC or else the first PLC that has one. A type imported with a type it uses is put in work in that type's PLC when it has an instance there, since TIA builds the new version against the versions the test instance's PLC uses. A type without an instance is refused.
  2. The local document replaces the in-work version, which is then released. The version number is the one in the local .libinfo when it is higher than every existing version, otherwise the next patch number. Author and comment also come from the .libinfo. Only a change to the document or its .s7res makes it an edit, a change to the .libinfo alone is not imported.
  3. The types that TIA puts in work because they use a released type are released too, dependencies first.
  4. Every PLC with an instance on an older version of a released type is updated with UpdateProject, dependencies first. When a document is imported over a type that uses another released type, TIA adds a copy of the old version of that type to the test PLC (<name>_1), so that PLC is updated too and the copy goes with the other unused instances.
  5. The PLCs that changed are compiled. If one has errors the project is not saved (see below). Otherwise it is saved, the released definitions are exported again with their .meta.json, and the .liblink files of the instances that moved are rewritten. The exported files of instances TIA deleted are removed, except a source edited since the export.

The first update in a PLC makes TIA delete every library instance in that PLC that nothing references, of any type and version, also ones the import has nothing to do with. These are unused copies, so the import reports them and goes ahead. It refuses before changing anything when a PLC would end up inconsistent:

  • A type in the PLC uses a released type, but gets no new version. TIA only puts a type in work when the PLC that tests the release has an instance of its current version. After the update that type would still use the old version, and the PLC does not compile.
  • A released type uses another version of a type than the PLC has. TIA would add a second copy of that type (<name>_1) for it.
  • A type that uses a released type is in work in TIA.
  • A type that gets a new version with a released type has a local document edited since the export. Its document is exported again after the release, so pass it in the same run.
  • A type that uses a released type and gets a new version with it would be tested in another PLC than that type. TIA would build it against the old version. Pass --plc with a PLC that has instances of both.

The refusals are planned from the dependencies of each type's current version, since the edited document's are only known once TIA has read it. After the releases the import checks them again against the released versions and stops before updating any PLC if a document now uses another version of a type than a PLC has, or a released type uses an older version of another type released in the run.

If anything fails after the first change in TIA (a release, an update, a compile error), the project is not saved and the error lists what was released and updated. If refreshing the exported files fails after the save, the error says so; export the project again before the next import. A project the bridge opened is closed without saving, and the tia rpc host drops its session so a later save can not keep the partial change. In a TIA instance that already had the project open the changes stay until the project is closed there without saving.

A document is checked against its .meta.json like a PLC source. If TIA released another version since the export (library-version-changed) or has the type in work (library-type-in-work) and the document changed too, the import needs --overwrite. On an in-work type that replaces the in-work content. Unchanged documents are skipped.

--dry-run reports the versions that would be created, the dependents, per PLC the instances that would move and the ones TIA would delete, and any refusal, without changing anything. It exits non-zero when it reports a refusal. The deletions are predicted from TIA's cross-references of every library instance in the PLCs that get updated. With --json the result has a library object with types, plcs (moved and removed), refusals, and after an import compile, the refreshed files and the removedFiles. The imported documents are counted in filesImported.

The extension runs the dry run first and shows its plan for confirmation: the versions it releases, the dependents released with them, and per PLC the instances that move and the ones TIA deletes. A predicted refusal is shown instead, and nothing is imported. A conflicting type (changed in TIA too, or without a baseline) imports with --overwrite only from its own row, and the confirmation names it. After the import the library rows are dropped, the comparisons shown for the destination's PLCs run again and the compile messages of the changed PLCs show in Problems. The comparisons also run again after a failed import, since one that fails after the save leaves the exported files stale. After a finished import, which the bridge saved, they compare as usual. After a failed one they compare only the saved project and never save it, so the failed import stays unsaved in TIA Portal. If the import's progress shows the bridge opened the project itself (project.open), it closed it again unsaved, and they compare the saved file as usual. The import itself can not be cancelled once the plan is confirmed, since the bridge can not roll back a release or a PLC update.

Automatic comparison

Automatic comparison is enabled for every linked project, without a setting. The extension watches System/PEData*.plf and PEData.idx outside or inside the workspace and debounces persistence changes for 750 ms. A five-second metadata check recovers missed events and unavailable directories; it does not export unchanged projects. Name-based bindings resolve their storage path from the status bar's discovered TIA instances. Archives are not watched.

The first available storage snapshot of an open project triggers an initial comparison. Instance discovery polls at a 20-second minimum interval and also refreshes on focus and operations; opening a previously closed project re-arms comparison without requiring a save. Subsequent storage changes run a quiet whole-root comparison through the existing operation queue. Changes during a comparison coalesce into one follow-up. Unlinking, rebinding, and disposal cancel pending work and prevent publishing outdated results.

Background comparisons pass tia diff --engine direct --saved-only. The bridge attaches only to an already-open project, takes exclusive access and copies persisted storage without calling Save, so a refresh neither launches TIA, opens closed projects, saves unfinished edits nor triggers a save feedback loop. Filesystem events are advisory: non-source persistence writes may trigger a comparison, but only content differences appear in SCM. Automatic comparison does not modify local sources or baselines, compile, import, or install Openness trust. A user-started command can establish trust when needed.

Failed background comparisons retain the previous sidebar and cached preview. Transient failures retry after two and four seconds, then wait for another storage change. The first failure is logged to the Siemens TIA Portal output channel without a popup.

Import validation

Import still uses Openness. The bridge holds TIA exclusive access from validation through import and save. A TIA fingerprint that matches the baseline's shows that the object is unchanged in TIA, so a direct/native serialization difference is not a TIA edit. Without a matching fingerprint the bridge exports the object's current content and checks the content/resource baselines again. tia diff --engine openness uses the same assessment, so the two always agree. A native export only skips a file whose fingerprint matches. A displayed comparison cannot authorize overwriting an intervening TIA edit. Missing baselines and conflicts require explicit overwrite; project-library guards still apply.

Group names retain their original TIA identity in metadata; only exported filesystem names are sanitized. Imports resolve that identity against the actual TIA group tree, including names containing /, instead of creating sanitized duplicate groups. Missing or ambiguous original groups require a fresh export before importing.

Document import results are checked before refreshing metadata. TIA can return Failure or PartialSuccess without throwing; these are failures, not successful synchronization. An external-source fallback is refused when it would lose a document's resource texts.

A document or source import replaces the block in TIA. .s7dcl and .scl files carry a block number only for manually numbered FBs, FCs and DBs (S7_BlockNumber), and never the event class of an OB. On its own TIA V21 gives the replaced block the lowest free number, and turns every OB into an automatically numbered "Program cycle" OB. The import reads number, numbering mode and OB event class before it replaces a block and puts them back afterwards. S7_BlockNumber in the source still decides the number of a manually numbered block. The event class is read-only in Openness, so an OB that lost it is compiled, exported as Simatic ML, given its event class, number and cycle time back and imported again. Its priority is written back afterwards. If the imported OB does not compile, the existing OB and its priority are put back and the import fails for that file. TIA only exports compiled blocks, so an uncompiled OB is compiled before the import to take that backup. An OB that is not a "Program cycle" OB and does not compile is not replaced, and the import fails for that file. A block that ends up with another type, number or event class also fails the import, before the project is saved.

Each imported block has an identity object in the import result with before, after and the list of restored properties. The Openness export and import record obEventClass next to blockNumber in the .meta.json. A block created by an import takes the recorded number when it is free, and a created OB the recorded event class. The direct exporter does not read the event class yet, so its sidecars have no obEventClass. tia diff with the Openness engine reports a block whose number or event class differs from the sidecar as tia-changed with reason block-identity-changed.

Verification

Automated coverage includes the source/resource change matrix, converged edits, missing and legacy baselines, additions, local deletions, format changes, folder/file scope, nested roots, invalid metadata, failed snapshots, cache cleanup, rebinding, queue reentrancy, and trust preflight handling. Run:

npm run typecheck
npx eslint ./client/src --ext .ts,.tsx --max-warnings=0
npm run test:tia
npm run test:webview:render
go -C go_lsp test ./...
dotnet build tia_openness_bridge/TiaOpennessBridge.csproj -c Release
powershell -NoProfile -File scripts/test-tia-bridge-helpers.ps1
node scripts/build-go-lsp.js --target windows-amd64

Watcher unit tests exercise actual file events, burst debouncing, missed events, storage replacement/deletion, unavailable paths, rebinding, cancellation, queueing, and bounded retries.