This C library provides a portable and simple API for accessing Allen-Bradley and Modbus PLC data over Ethernet.
Thanks to user @nc-koko for surfacing these problems.
Please double check that you are getting all the events you think you should get after upgrading. And, please let me know if you see duplicate events! I did not see any in my testing, but absence of evidence is not evidence of absence.
This has two main fixes/enhancements:
This has two fixes in it. The first fixes issue #385 to help the contributed CLI compile on MinGW64. The second allows the querying of the "elem_type" attribute for AB tags. For now, this supports PCCC tags mostly and CIP PLC tags if you set the elem_type in the tag attribute string. This will change so that the tag type as read back from the PLC is returned but not in this release.
This has fixes from user @tinajohnson (and apologies for dropping this PR on the floor for so long!) for string termination that could have been a problem if the tag names was long. It also has a performance change that user Rohit found where there could be a extra 100ms delay in some conditions of PLC connection set up. The final fix was for a problem found by user @engerlf where the loop that handled spurious condition variable wake ups was doing an incorrect time comparison.
Thanks very much for all the support from users on this release!
Thanks to @tinajohnson for the buffer overrun fixes! This also exposed a CI build problem on GitHub because Visual Studio version 16 is no longer available on the Windows CI runner pool.
If you use Windows, please try this out. The DLLs are build with Visual Studio v17 2022 instead of version 16 2019. I do not know if there are any backwards incompatible changes since I do not have any Windows machines that are running anything earlier than Windows 10!
This release is thanks to user @Joylei who kicked it off with a nice pull request with additional callback functionality. There are two new API functions added to use callbacks with support for a user-supplied pointer parameter.
WARNING note that the library has no way of knowing what any wrapper system does with the data pointed to by the pointer argument! For instance, if you pass in a pointer to a normal Java object, chances are that the garbage collector will run at some point and move your object. Then the pointer will be invalid and your program will likely crash. However, for systems that do support pinning memory in place or do not move memory, this allows you to directly point to some application object. It can also be used to pass integer or floating point data no larger than a pointer.
The examples have been updated to show the use of this in C. The wiki has been updated with the new functions.
A few other changes are in this release such as cleaner handling of events and addition of a PLCTAG_EVENT_CREATED event that will fire when a tag is created and ready for use. Note that "ready for use" depends on the type of the tag. A normal tag in a ControlLogix will perform a tag read before being ready. A tag listing tag will not.
Please test this out. The version has changed to 2.5.0 because there is an API change. I tried hard to make sure that older code will continue to work with this, but there were enough internal changes to event handling that you probably should run this through your own test processes before picking it up for production use.
One more try. The previous try did not get merged correctly.
Thanks to @heppth for finding a use-after-free problem and helping to reproduce and debug it!
Please upgrade to this release, not the previously mentioned 2.4.11.
Many thanks to @radrevere for all the help and testing and thought! In some circumstances it was possible to overwrite memory and corrupt the heap.
It looks like the core problem was triggered by the following:
str_
special string attributes to tell the library what the correct string sizes are. Specifically, the actual size of the character data must be smaller than the default (82) size.Then the loop that zeros out the rest of the tag buffer will overwrite memory. I put checks on all three parts of writing to the tag buffer data:
Please test this extensively! I was not able to duplicate the problem until I met the three criteria above. I will probably need to add a section to the wiki about strings because they are so tricky.
Many thanks to user @vernturbine on the forum for helping test the Micro8x0 tag listing. It looks like this is now working. I applied the same fixes to Omron systems as well. Perhaps they work now too? This splits out the tag listing example program into two programs: one for Control/CompactLogix systems and one for Micro8x0 systems. I need to refactor this in the future to make this cleaner.
There are also some additional tests added to the local test suite that I use before pushing to GitHub.
And finally there are some fixes for missing read/write completion events when using special/system tags (which no one but myself probably ever does). This was found when I tried to update the Java wrapper with the latest code.
This release contains a set of small fixes to allow up to 100k tags with a single instance of libplctag. It also contains some better error handling for errors on macOS for sockpair(). More tests have been added to the run_tests.sh script.
The performance tweaks in this release help the library support at least 100k tags without overwhelming the CPU. With 100k tags each using automatic reads every 4 seconds and 50 simulated PLCs, the library takes about 125% of the CPU (multiple cores) on my 2020 MacBook Air M1. The goals of this set of tweaks were to make sure that the tag tickler thread does not eat all the CPU and that reads are skipped on long delays to catch up with the original requested timing.