-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Description
I've tried to read this simple structure:
MyStruct = {
("MyVar1", pyads.PLCTYPE_BYTE, 1),
("MyVar2", pyads.PLCTYPE_REAL, 1)
}
Using Symbols:
myStruct = plc.get_symbol("MYSYMBOL", structure_def=MyStruct)
Reading and writing works fine. But when i try to use Notification:
myHandle = myStruct.add_device_notification(callback)
I've got a first error, and when found where and why, and solved, a second error.
The first error reports line 138 of symbol.py with error:
TypeError: unsupported operand type(s) for *: 'set' and 'int'
self._structure_size = size_of_structure(self.structure_def * self.array_size)
To let it work properly I had to change it in:
self._structure_size = size_of_structure(self.structure_def) * self.array_size
And this way it worked fine. But after that I got this second error in the same file but line 254:
TypeError: this type has no size
attr = NotificationAttrib(sizeof(self.plc_type))
To let them work properly with at least the primitive types (I've tested just with them) I've changed the code in:
if attr is None: # when optional attr.Length is provided it works fine, telling PLC to monitor changes of primitive or structure up to size of the variable
if self.plc_type is not None: # this is provided with primitive types
attr = NotificationAttrib(sizeof(self.plc_type))
elif self.structure_def is not None: # because it is left None instead of self.symbol_type that is got from ADS, but seems to be just a string and no typedef is provided even if structure_def param has been provided
attr = NotificationAttrib(self._structure_size) # size has been set correctly
else: # I don't know if or when this can occur
attr = NotificationAttrib(1) # this should at least work, notification is set without error on a single byte subscription length (minimum length) and a warning message should be provided. Or other choices should be provided and least (alternatively to notification(1) or as last chance should be raised an exception
import warnings
warnings.warn("No plc_type found for symbol notification with length 1 is used.")
# raise ValueError('No plc_type found for symbol notification. Len value cannot be retrieved') # use instead of notification(1)+warning.warn()
This way, it seems me that primitives and structures works fine.
What did I wrong or is there something to improve?
Metadata
Metadata
Assignees
Labels
No labels