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

fix function block properties #261 #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion pyads/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ def _create_symbol_from_info(self) -> None:
info = adsGetSymbolInfo(self._plc._port, self._plc._adr, self.name)

self.index_group = info.iGroup
self.index_offset = info.iOffs
if self.index_group == 0xF019:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this value to a constant alongside ADSIGRP_SYM_VALBYHND so the code is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to call this constant, as it is not documented, but I can make something up, if there are no guidelines for that case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest something like ADSIGRP_SYM_MONITORDUMMY

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should also be a comment to the group definition explaining that it's undocumented and that it's used in the context of monitored variables.

# For function block properties with monitoring = call
# get symbol using handle instead
self.index_group = constants.ADSIGRP_SYM_VALBYHND
self.index_offset = self._plc.get_handle(self.name)
else:
self.index_offset = info.iOffs

if info.comment:
self.comment = info.comment

Expand Down Expand Up @@ -230,6 +237,8 @@ def __repr__(self) -> str:
def __del__(self) -> None:
"""Destructor"""
self.clear_device_notifications()
if self.index_group == constants.ADSIGRP_SYM_VALBYHND:
self._plc.release_handle(self.index_offset)

def add_device_notification(
self,
Expand Down