Skip to main content

TwinCAT PLC file parser using xsdata

Project description

pytwincatparser

A Python package for parsing TwinCAT PLC files (TcPOU, TcDUT, TcIO, TcPlcProj, TcGvl, TcIO).

Description

This package provides tools to parse and work with TwinCAT PLC files. It uses xsdata to handle XML parsing. Be aware, that this is a python lib written by a beginner with help of AI assisted programming. My main work task is to design and program industrial machines, not develop python programms!

Features

  • Parse TwinCAT PLC files (.TcPOU, .TcDUT, .TcIO, .TcGvl, .TcPlcProj)
  • Load the twincatfile in python dataclasses
  • parse variable blocks
  • parse documentation
  • parse dependencies

Installation

pip install pytwincatparser

Usage

_strategy: BaseStrategy = None
_collected: dict[str, Objects] = {}

# for now only "twincat4024" strategy is allowed
if config.default_strategy is not None:
    strategy = get_strategy(config.default_strategy)
else:
    strategy = get_default_strategy()

# set the loader with the right strategy
_strategy = strategy()
_loader: Loader = Loader(loader_strategy=_strategy)

# load every file
for path in paths:
    tcobjects = _loader.load_objects(path=path)
    # for every found object
    for tcobject in tcobjects:
        # get identifier (fb_main.Do_This) and check if such a object is not loaded already
        if not tcobject.get_identifier() in _collected:
            _collected[tcobject.get_identifier()] = tcobject

Requirements

  • Python 3.11
  • lxml >= 5.3.0
  • xsdata[lxml] >= 24.12

License

MIT

Todo

  • Add support for return values of methods and functions
  • Add support for specifier like CONSTANT and PERSISTEN in Variable blocks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytwincatparser-0.5.5.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytwincatparser-0.5.5-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file pytwincatparser-0.5.5.tar.gz.

File metadata

  • Download URL: pytwincatparser-0.5.5.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for pytwincatparser-0.5.5.tar.gz
Algorithm Hash digest
SHA256 5b1e9dbf136d99db58559bba780728aa2a813a718368adba0dbd9de0660a34c4
MD5 31e8e8bb673d0cea9e169553b3bb6d82
BLAKE2b-256 ad1141267a22e486d357711f27f695d1fce273f558a411490e6bb7181a67a050

See more details on using hashes here.

File details

Details for the file pytwincatparser-0.5.5-py3-none-any.whl.

File metadata

File hashes

Hashes for pytwincatparser-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c925be9fcff2c0cee2e93a1f4e78f7ebc2351513223eb854687cef9161584ed0
MD5 299816b115d5f56aec9cea9d82528345
BLAKE2b-256 b36bfc5b5165311f90f3679b4af8a813518a37b08239a6f44d33a8f7ab7a628f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page