Q: Will pyads notice and update symbol changes (offset, type) while running or on reconnect? #478
-
|
This is more a question: Today, the company that built and services our PLC (heating system) updated the control logic because some hardware components changed (electricity counters via Modbus RTU). After the rollout, some scripts that I have written to fine-tune the behavior of the systems, suddenly read awkward values. I am not sure whether the connection was dropped in between, I guess so. Could it be that pyads will keep symbol info (offsets, types) cached across connections such that reading a symbol will still use the outdated offset? (I hope, my scripts didn't write to unintended addresses...!) Anyway, restarting the scripts fixed the issues. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
If you are using read_by_name, or the get_symbol then it may cache the symbol info e.g. https://github.com/stlehmann/pyads/blob/54a34185ed963f8d9928a1877ab2d99fd38c9ef1/src/pyads/connection.py#L514C5-L536C82 for as long as the connection class instance is the same. If you restart the script (or recreate the connection class I believe) then this should refresh. I always just monitor for symbol changes and just restart my scripts if one changes as I'm not 100% sure of the recreating the connection class behaviour. You can monitor for symbol changes using something like the following: self._plc.add_device_notification(
(int("0xF100", 16), int("0x0000", 16)), # ADSIGRP_DEVICE_DATA, ADSIOFFS_DEVDATA_ADSSTATE
pyads.NotificationAttrib(ctypes.sizeof(pyads.PLCTYPE_INT)),
self._on_plc_status_change,
)
self._plc_symbol_changes: int = 0
self._plc.add_device_notification(
(int("0xF008", 16), 0), # ADSIGRP_SYM_VERSION
pyads.NotificationAttrib(ctypes.sizeof(pyads.PLCTYPE_BOOL)),
self._on_symbol_table_change,
)
def _on_plc_status_change(self, notification, _):
"""Notification callback for a change in PLC state (run to config etc)."""
*_, value = self._plc.parse_notification(notification, pyads.PLCTYPE_INT) # type: ignore
if value != pyads.ADSSTATE_RUN:
self._plc_fatal_com_error_message = "PLC exited run mode"
def _on_symbol_table_change(self, *_):
"""Notification callback for plc heartbeat."""
self._plc_symbol_changes += 1
if self._plc_symbol_changes > 1:
self._plc_fatal_com_error_message = "PLC symbol table has changed" |
Beta Was this translation helpful? Give feedback.
If you are using read_by_name, or the get_symbol then it may cache the symbol info e.g. https://github.com/stlehmann/pyads/blob/54a34185ed963f8d9928a1877ab2d99fd38c9ef1/src/pyads/connection.py#L514C5-L536C82 for as long as the connection class instance is the same. If you restart the script (or recreate the connection class I believe) then this should refresh. I always just monitor for symbol changes and just restart my scripts if one changes as I'm not 100% sure of the recreating the connection class behaviour. You can monitor for symbol changes using something like the following: