Skip to content

Testserver cannot register multiple device notification #326

@StefanVanDyck

Description

@StefanVanDyck

I was trying to use the test server to mock the behavior of the PLC.
Everything worked great, but I ran into some issues when using device notifications.

First I didn't realize until I started debugging the code that the:
The test server has to run in the same python process as the calling code to be able to work.
Seems like it relies on this global callback store variable to be populated by the client somehow?
Not quite sure if that's really the issue, but I just never got it to work running in a forked process or a docker container.
If this is the case, it might be useful to add some additional asterisk in the docs to make this extra clear.

Secondly, when registering multiple device notifications on different variables:
The test server reuses the same handle.
The offending line seems to me to be this one: https://github.com/stlehmann/pyads/blob/master/pyads/testserver/advanced_handler.py#L167
This will not increment handles across different PLCVariables.
Instead changing it to PLCVariable.notification_count kinda makes it work.
Unless device notifications are deleted and then the whole handle things goes out of whack anyway.

In conclusion I suppose the problem is the python code is trying to guess what the handle is the C-library will use, but that guessing is not entirely correct. Not sure how to fix that.
Might be totally wrong about this though, not really sure I understand all the stuff that's happening here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions