A bit more clarity on handling tag connection errorsplease.

26 views
Skip to first unread message

Nathan Fieldhouse

unread,
Sep 11, 2025, 1:18:46 AMSep 11
to libplctag
Hi Kyle,
I am using this to run 10 PLC's, when a machine is shut off the library result is -32 timeout. At one point I was destroying the tags for that PLC and attempting to recreate them.

I wasn't sure if that was the best way to handle them so instead on a -32 timeout I dont destroy and recreate, only for all other errors.

So my question is,  when a tag is created does the PLC CPU provide a pointer to a memory address for that tag? If so whats the chances that on a power cycle that will change? If it does that tag will no longer be valid and i will be reading invalid data which means my first method of handling the error is better.

I only ask this as I have one PLC that has two connections, one from myself and one from a HMI and almost daily I get a timeout but the PLC has not been power cycled its just not handling two requests very well, in this case it seemed re-creating the tags is not necessary.

What is your thoughts/suggestions?

Kind Regards
Nathan

Kyle

unread,
Sep 11, 2025, 4:03:42 PMSep 11
to libplctag
You can do it either way.   The library will automatically reconnect but it uses a backoff algorithm to make sure that it does not flood the PLC.

The PLC has no part in this.   The library creates a connection for each _PLC_, not each tag.   That connection is hidden behind the scenes and is not directly exposed by the C API.  The tags in the PLC are addressed by using the tag name and that does not change.

Is the network interface on the PLC heavily loaded?  You can usually get information about it by hitting the URL `http://1.2.3.4:80/` where you change `1.2.3.4` to the actual IP address of the PLC. This will give you a web page to see various information about the network interface.  The overall CPU load is on one of those pages.

You could also have some bursty behavior on you network.   I have seen this in production where the latency between request and response is low, varying between 3 and 5ms, and once in a while jumps considerably higher, e.g. 50-200ms.

What timeout value are you using?

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