Metadata-Version: 2.4
Name: pytwincatparser
Version: 0.5.6
Summary: TwinCAT PLC file parser using xsdata
Project-URL: Documentation, https://github.com/drehstromer/pytwincatparser#readme
Project-URL: Issues, https://github.com/drehstromer/pytwincatparser/issues
Project-URL: Source, https://github.com/drehstromer/pytwincatparser
Author-email: drehstromer <privat@samuelruckli.ch>
License: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: lxml>=5.3.0
Requires-Dist: pytest>=8.3.5
Requires-Dist: xsdata[lxml]>=24.12
Description-Content-Type: text/markdown

# 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

```python

_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

- [X] Add support for return values of methods and functions
- [X] Add support for specifier like CONSTANT and PERSISTEN in Variable blocks
