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.0.tar.gz (48.5 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.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytwincatparser-0.5.0.tar.gz
Algorithm Hash digest
SHA256 35dc20ccb874aa0911260ce2aa2f560dae72b869b279a7b05aa68c44cf1ddfca
MD5 6ff06c3e3b6b11b04648b6c39a07d184
BLAKE2b-256 4143d4d654581082291e7be988ad6c23e4007d85b533caac54bc2c6bc6ec6621

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytwincatparser-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90492e71cb29e631535b3e1bd200c0ae5979a77f31f96b2523530fe5f9d70d2
MD5 5f55485dac9842854f7da496ee09f7bf
BLAKE2b-256 1684eebf3909efac4313ee5efc823bd52a464b6ac9d406c8102155cd3fa7d132

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