From 28f07dc51eb63bd1cc64009bc779c6a77b024cea Mon Sep 17 00:00:00 2001 From: Stefan Lehmann Date: Mon, 11 May 2020 17:59:02 +0200 Subject: [PATCH 1/3] Fix documentation --- doc/quickstart.md | 8 ++++---- pyads/ads.py | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index 184ffbc5..679b860c 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -286,7 +286,7 @@ can be seen here: >>> from ctypes import sizeof >>> >>> # define the callback which extracts the value of the variable ->>> def callback(addr, notification, user_handle): +>>> def callback(notification, data): >>> contents = notification.contents >>> var = next(map(int, bytearray(contents.data)[0:contents.cbSampleSize])) >>> @@ -325,15 +325,15 @@ For more information about the NotificationAttrib settings have a look at **Here are some examples of callbacks for other datatypes:** ```python -def callbackBool(adr, notification, user): +def callbackBool(notification, data): contents = notification.contents var = map(bool, bytearray(contents.data)[0:contents.cbSampleSize])[0] -def callbackInt(adr, notification, user): +def callbackInt(notification, data): contents = notification.contents var = map(int, bytearray(contents.data)[0:contents.cbSampleSize])[0] -def callbackString(adr, notification, user): +def callbackString(notification, data): dest = (c_ubyte * contents.cbSampleSize)() memmove(addressof(dest), addressof(contents.data), contents.cbSampleSize) # Remove nullbytes diff --git a/pyads/ads.py b/pyads/ads.py index 5755ef21..75f755da 100644 --- a/pyads/ads.py +++ b/pyads/ads.py @@ -430,8 +430,7 @@ def add_device_notification(adr, data, attr, callback, user_handle=None): :param Union[str, Tuple[int, int] data: PLC storage address as string or Tuple with index group and offset :param pyads.structs.NotificationAttrib attr: object that contains all the attributes for the definition of a notification - :param callback: callback function that gets executed on in the event - of a notification + :param callback: callback function that gets executed in the event of a notification :rtype: (int, int) :returns: notification handle, user handle @@ -980,8 +979,7 @@ def add_device_notification(self, data, attr, callback, user_handle=None): :param Union[str, Tuple[int, int] data: PLC storage address as string or Tuple with index group and offset :param pyads.structs.NotificationAttrib attr: object that contains all the attributes for the definition of a notification - :param callback: callback function that gets executed on in the event - of a notification + :param callback: callback function that gets executed in the event of a notification :rtype: (int, int) :returns: notification handle, user handle @@ -999,7 +997,7 @@ def add_device_notification(self, data, attr, callback, user_handle=None): >>> plc = pyads.Connection('127.0.0.1.1.1', 851) >>> >>> # Create callback function that prints the value - >>> def mycallback(adr, notification, user): + >>> def mycallback(notification, data): >>> contents = notification.contents >>> value = next( >>> map(int, @@ -1011,11 +1009,10 @@ def add_device_notification(self, data, attr, callback, user_handle=None): >>> # Add notification with default settings >>> attr = pyads.NotificationAttrib(size_of(pyads.PLCTYPE_INT)) >>> - >>> hnotification, huser = plc.add_device_notification( - >>> adr, attr, mycallback) + >>> handles = plc.add_device_notification("GVL.myvalue", attr, mycallback) >>> >>> # Remove notification - >>> plc.del_device_notification(hnotification, huser) + >>> plc.del_device_notification(handles) """ if self._port is not None: From 6337b5c74e26b008b1386c8212cd1ed696c4e5d7 Mon Sep 17 00:00:00 2001 From: Stefan Lehmann Date: Mon, 11 May 2020 18:02:09 +0200 Subject: [PATCH 2/3] Fix integration tests --- tests/test_integration.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index c23ef02d..b4902d2e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -478,7 +478,7 @@ def test_write_by_name(self): self.assert_command_id(requests[2], constants.ADSCOMMAND_WRITE) def test_device_notification_by_name(self): - def callback(adr, notification, user): + def callback(notification, data): pass handle_name = "TestHandle" @@ -500,7 +500,7 @@ def callback(adr, notification, user): self.assert_command_id(requests[2], constants.ADSCOMMAND_DELDEVICENOTE) def test_device_notification_by_tuple(self): - def callback(adr, notification, user): + def callback(notification, data): pass n_index_group = 1 @@ -527,7 +527,7 @@ def callback(adr, notification, user): self.assert_command_id(requests[1], constants.ADSCOMMAND_DELDEVICENOTE) def test_device_notification_data_error(self): - def callback(adr, notification, user): + def callback(notification, data): pass attr = NotificationAttrib(length=4) From 91f705b98c6be17fa5371b90d7d8be5970417bc7 Mon Sep 17 00:00:00 2001 From: Stefan Lehmann Date: Mon, 11 May 2020 18:02:16 +0200 Subject: [PATCH 3/3] Fix unit tests --- tests/test_connection_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_connection_class.py b/tests/test_connection_class.py index 1d28c186..77b848c3 100644 --- a/tests/test_connection_class.py +++ b/tests/test_connection_class.py @@ -538,7 +538,7 @@ def test_write_by_name_with_handle(self): self.plc.release_handle(handle) def test_device_notification(self): - def callback(adr, notification, user): + def callback(notification, data): pass handle_name = "test"