stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
247 stars 93 forks source link

Added feature for processing nested structures #384

Open msfur opened 2 months ago

msfur commented 2 months ago

Enables processing for nested structures, as mentioned in and fixes #308 and on Stackoverflow. Takes into account nested structures in the following form:

    substructure_def = (
         ("iVar", pyads.PLCTYPE_INT, 1),
         ("sVar", pyads.PLCTYPE_STRING, 1)
     )

    structure_def = (
         ("iVar1", pyads.PLCTYPE_INT, 1),
         ("structVar", substructure_def, 2)
     )

or

    structure_def = (
        ("iVar1", pyads.PLCTYPE_INT, 1),
        ("structVar",
            (
                ("iVar", pyads.PLCTYPE_INT, 1),
                ("sVar", pyads.PLCTYPE_STRING, 1)
            ), 2
        )
    )

Contains adaptations to size_of_structure(), dict_from_bytes() and bytes_from_dict() and the associated tests.

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 8985140072

Details


Totals Coverage Status
Change from base Build 8519762609: 0.03%
Covered Lines: 1713
Relevant Lines: 1814

💛 - Coveralls
chrisbeardy commented 2 months ago

@msfur this is awesome, looks great as a solution for the nested structs issue and thanks for adding the tests in too! If possible, could you please add a documentation example at the end of this section too? https://pyads.readthedocs.io/en/latest/documentation/connection.html#structures-with-multiple-datatypes

I will then merge.

msfur commented 2 months ago

@chrisbeardy I have made the desired change to the documentation and added an example.

keenanjohnson commented 1 day ago

This looks great! Any way I can support getting this merged?