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.4.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.4-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytwincatparser-0.5.4.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.4.tar.gz
Algorithm Hash digest
SHA256 f8ef1085367e5c2c2f61d9a6a486c920bda3978f59d8495c8f92706b3a40b093
MD5 7d41b741dd1e43c2ebfaee9201440023
BLAKE2b-256 495e4a465852de1584e81c064c2826c63c65d5c6a91cde92a07721ea92916107

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytwincatparser-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2f99a881a03324b48682712cb4f8d20fcfd4884b0a343a6bfdcc1b70a1b31d0
MD5 b00a47a67cce707cb8d769576f00e96f
BLAKE2b-256 78ecc380a9371a535ec1c290fce01d6e1d511a1228519344be9655eb2a4ae48a

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