diff --git a/doc/documentation/routing.rst b/doc/documentation/routing.rst index ffbce3d8..78d12cfc 100644 --- a/doc/documentation/routing.rst +++ b/doc/documentation/routing.rst @@ -8,7 +8,7 @@ operating systems in the sections below. To identify each side of a route we will use the terms *client* and *target*. The *client* is your computer where pyads runs on. The -*target* is you plc or remote computer which you want to connect to. +*target* is your plc or remote computer which you want to connect to. Creating routes on Windows -------------------------- diff --git a/pyads/symbol.py b/pyads/symbol.py index 762cc99a..3ea6566b 100644 --- a/pyads/symbol.py +++ b/pyads/symbol.py @@ -252,7 +252,10 @@ def add_device_notification( """ if attr is None: - attr = NotificationAttrib(length=sizeof(self.plc_type)) + if self.is_structure: + attr = NotificationAttrib(length=self._structure_size) + else: + attr = NotificationAttrib(length=sizeof(self.plc_type)) handles = self._plc.add_device_notification( (self.index_group, self.index_offset), attr, callback, user_handle diff --git a/tests/test_symbol.py b/tests/test_symbol.py index d6200a87..51b17a6e 100644 --- a/tests/test_symbol.py +++ b/tests/test_symbol.py @@ -491,6 +491,32 @@ def my_callback(*_): self.assertAdsRequestsCount(3) # READWRITE, ADDNOTE and DELNOTE + def test_add_notification_structure(self): + """Test notification registering for structures""" + structure_def = ( + ("a", pyads.PLCTYPE_INT, 1), + ("b", pyads.PLCTYPE_INT, 1), + ("s", pyads.PLCTYPE_STRING, 1) + ) + values = [{"a": 1, "b": 2, "s": "foo"}, {"a": 3, "b": 4, "s": "bar"}] + data = bytes(bytes_from_dict(values, structure_def)) + + self.handler.add_variable( + PLCVariable("TestStructure", data, constants.ADST_VOID, symbol_type="TestStructure")) + + def my_callback(*_): + return + + with self.plc: + + symbol = self.plc.get_symbol("TestStructure", structure_def=structure_def, array_size=2) + + handles = symbol.add_device_notification(my_callback) + + symbol.del_device_notification(handles) + + self.assertAdsRequestsCount(3) # READWRITE, ADDNOTE and DELNOTE + def test_add_notification_delete(self): """Test notification registering"""