Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with auto_update in connection with structs #427

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/documentation/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------
Expand Down
5 changes: 4 additions & 1 deletion pyads/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
Loading