stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
257 stars 95 forks source link

Symbol auto_update does not work with structs #372

Open ascaron37 opened 6 months ago

ascaron37 commented 6 months ago

When trying to set auto_update to a struct symbol, I receive following error:

  File "/home/.../app/adapters/ads_client.py", line 93, in init_variables
    symbol.auto_update = True
    ^^^^^^^^^^^^^^^^^^
  File "/home/.../lib/python3.11/site-packages/pyads/symbol.py", line 364, in auto_update
    self._auto_update_handle = self.add_device_notification(
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../lib/python3.11/site-packages/pyads/symbol.py", line 252, in add_device_notification
    attr = NotificationAttrib(length=sizeof(self.plc_type))
                                     ^^^^^^^^^^^^^^^^^^^^^
TypeError: this type has no size

I guess it has something to do, that a struct symbol has no plc_type. I think there should be a query if it is a structure or a native type like this:

        if attr is None:
            if self.is_structure:
                size_of_struct = pyads.size_of_structure(self.structure_def)
                attr = NotificationAttrib(length=size_of_struct)
            else:
                attr = NotificationAttrib(length=sizeof(self.plc_type))