Does libplctag have tag change events?

156 views
Skip to first unread message

Mark Hancock

unread,
Jul 19, 2023, 4:38:12 PM7/19/23
to libplctag
A previous library I was using provided a way to get notified when a tag value chaged.
This requires support for tag polling.
Does libplctag have a mechanism for that (other than creating my own polling thread, etc.?

tim...@gmail.com

unread,
Jul 19, 2023, 5:25:51 PM7/19/23
to libplctag
libplctag offers an AutoRead feature, but doesn't itself offer a way to detect changes to the tag value.
But there is an example of how to add this functionality yourself in the .NET wrapper repository

Kyle

unread,
Jul 21, 2023, 4:18:44 PM7/21/23
to libplctag
One of the challenges with change events is how to determine that they happened.   It catch every possible bit flip, you would need double the buffer for the whole tag in order to do a complete binary comparison.  You could get a really good approximation by calculating a very good hash (maybe SHA256 or something) but that isn't ideal when you have a single 4-byte int tag value.

You can roll your own change event handler in C by hooking onto the existing callback system, waiting for a READ event to complete, then using the API call to get the raw bytes of the tag and doing whatever comparison you want.  If I added a PLCTAG_EVENT_CHANGED event type and an API call to inject events, it would be even easier.   Maybe I'll do that...

Tim's example above is a good one for .Net!

Best,
Kyle
Reply all
Reply to author
Forward
0 new messages