Skip to main content

TwinCAT PLC file parser using xsdata

Project description

pytwincatparser

A Python package for parsing TwinCAT PLC files (TcPOU, TcDUT, 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)
  • Access POU (Program Organization Units), DUT (Data Unit Types), and ITF (Interfaces)
  • Extract declarations, implementations, methods, and properties
  • Extract VAR Blocks
  • Extract Return Values
  • Extract Comments
  • Generate HTML documentation for TwinCAT objects

Installation

This project uses uv as its package manager. To set up the development environment:

Windows

# Install uv if you don't have it
pip install uv

# Run the setup script
.\setup_uv.ps1

Usage

from pytwincatparser.TwincatParser import TwinCatLoader

# Initialize the loader with the path to TwinCAT files
loader = TwinCatLoader(search_path="path/to/twincat/files")

# Load all TwinCAT files
loader.load()

# Get a specific object by name
pou = loader.getItemByName("FB_Base")

# Get a method by name
method = loader.getItemByName("FB_Base._ConfigureAlarm")

# Get a property by name
property = loader.getItemByName("FB_Base.DesignationName")

# Get all loaded objects
all_objects = loader.getAllItems()

Look in the example folder!

Generating Documentation

You can generate HTML documentation for your TwinCAT objects using the generate_docs module:

from pytwincatparser.generate_docs import generate_documentation

# Generate documentation
generate_documentation(
    search_path="path/to/twincat/files",
    output_dir="path/to/output/directory",
    templates_dir="path/to/templates"  # Optional, defaults to 'templates' in the package directory
)

This will generate HTML documentation for all TwinCAT objects found in the search path. The documentation includes:

  • Object details (name, type, etc.)
  • Documentation comments
  • Variable sections
  • Methods and properties
  • Implementation code

See the examples/generate_documentation.py script for a complete example.

Requirements

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

License

MIT

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.2.18.tar.gz (33.0 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.2.18-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytwincatparser-0.2.18.tar.gz
Algorithm Hash digest
SHA256 bb25f05556be15c2f59d25509b7d45e5a3c01aaa0932fb431f2c4b79c3b12fae
MD5 02651c6e38fb24172279f3f9d6933a38
BLAKE2b-256 9f174ec2d5766e21b6af8ffe3f3212ed7182c6fedbc94b020e97338ded4668ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytwincatparser-0.2.18-py3-none-any.whl
Algorithm Hash digest
SHA256 1349e33280434d6e90f8da05b251c88ab452ae8a0718a7e5affb848860d40d97
MD5 6565c2707bd0e3d956c9c68e039bf4d1
BLAKE2b-256 eb03725b72e2e5645cc75bccbc4d6fd6b17e0b7c3f8d637b615173c361d53a0c

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