stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
247 stars 93 forks source link

Auto-update rate of symbols #348

Closed gbcarlos closed 1 year ago

gbcarlos commented 1 year ago

Hi everyone!

I'm reading out 10 symbols in a loop with 10Hz using symbol.read() but I'm getting the same error as in #35.

I just read that it would be enough to use symbol.value() instead of read() if I set auto_update=True. Now I am wondering at what rate the symbol is updated automatically if I set that property and if it is possible to change the rate.

chrisbeardy commented 1 year ago

The default settings for auto update=True will update the value if it changes on any plc cycle, therefore there is no need to update the rate, it will be as fast as your plc cycle.

If you wish to receive notifications cyclically at a set rate you have to attach the notification manually and can set the notification period in ms and the notification attribute to server cycle.

https://pyads.readthedocs.io/en/latest/documentation/symbols.html#device-notifications https://pyads.readthedocs.io/en/latest/documentation/connection.html#device-notifications

Can I please ask in the future that all questions are directed to Stack overflow using the tags PLC, Twincat and Twincat-ads. There is a small community there that will answer your questions. This is to just keep the Issues log as pyads issues. Thank you.

If you could kindly close this issue that would be great, thanks.

gbcarlos commented 1 year ago

Thanks a lot for the fast reply, I was not aware of the community but will post there in the future.

chrisbeardy commented 1 year ago

Just an additional thought, I don't know your application, but if it is logging based or if you do want to go faster poll time, I often find it is easier to create a cyclic array in the PLC which you populate with values and then do a read by list or read by structure to read all in one go. If you keep track of the read index then you can get a more predictable and time correct value set.

gbcarlos commented 1 year ago

Thanks for that idea, I will keep that in mind. For now reading them in roughly at PLC cycle is enough for my means but I will come back to it if the amount of read requests increase in the future.