stlehmann / pyads

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

How to access a Nested Structs? #350

Closed fieryWaters closed 9 months ago

fieryWaters commented 1 year ago

Hi, the documentation does not cover nested custom datatypes. Is this supported?

For example, if I have: TYPE TPoint : STRUCT x : REAL; y : REAL; END_STRUCT END_TYPE

TYPE ListOfPoints: STRUCT rampPoints : ARRAY [1..30] OF TPoint; rampSize : INT := 0; END_STRUCT END_TYPE

In PyADS, I try:

TPoint_def = ( ("x", pyads.PLCTYPE_REAL, 1), ("y", pyads.PLCTYPE_REAL, 1) )

ListOfPoints_def=( ("rampPoints", TPoint_def, 30), ("rampSize", pyads.PLCTYPE_INT,1) )

test1 = plc.get_symbol("Main.test1", structure_def=ListOfPoints_def, array_size=1)

Is there a Pythonic way to do this or do I just need to avoid custom nested types? Thanks!

chrisbeardy commented 1 year ago

hello, unfortunately this is not directly supported, but there is a workaround. please see #308. Hopefully support for this will be directly added to pyads at some point.

Please can you close this issue as it is a duplicate of #308, thanks. Any comments / additions, please add to #308.

chrisbeardy commented 1 year ago

@fieryWaters please can you close this and refer to #308, thanks

chrisbeardy commented 1 year ago

@stlehmann this can be closed, duplicate #308, thanks