SkillAgentSearch skills...

Libplctag

This C library provides a portable and simple API for accessing Allen-Bradley and Modbus PLC data over Ethernet.

Install / Use

/learn @libplctag/Libplctag

README

libplctag - a C library for PLC communication

What is libplctag?

libplctag is an open source C library for Linux, Windows and macOS using EtherNet/IP or Modbus TCP to read and write tags in PLCs. The library has been in production since early 2012 and is used by multiple organizations for many tasks including controlling radio telescopes, large and precision manufacturing, controlling fitness equipment, food handling and many, many more.

| Latest Stable Release: | | :-: | | Latest Release |

Tier One Platforms

These are OS/compiler combinations that are fully tested with each release:

| OS | OS Version | Compiler | Compiler Version | Architecture | Status | | :-: | :-: | :-: | :-: | :-: | :- | | Alpine Linux | v3.23.0-62 | GCC | 15.2.0 | x86-64 | Release branch CI status | | Alpine Linux | v3.23.0-62 | GCC | 15.2.0 | Aarch64 | Release branch CI status | | macOS | 14 | Apple-Clang | 17.0.0 | x86-64 | Release branch CI status | | macOS | 15 | Apple-Clang | 17.0.0 | Aarch64 | Release branch CI status | | Ubuntu Linux | 24.04 | GCC | 13.3.0 | x86-64 | Release branch CI status | | Ubuntu Linux | 24.04 | GCC-musl | 13.3.0 | x86-64 | Release branch CI status | | Ubuntu Linux | 24.04 | GCC | 13.3.0 | Aarch64 | Release branch CI status | | Ubuntu Linux | 24.04 | GCC | 13.3.0 | x86 | Release branch CI status | | Windows | 11 (Server 22) | MSVC | 19.44.35221.0 | x86-64 | Release branch CI status | | Windows | 11 (Server 22) | MSVC | 19.44.35221.0 | x86 | Release branch CI status | | Windows | 11 (Server 22) | MSVC | 19.44.35221.0 | Aarch64 | Release branch CI status | | Windows | 11 (Server 22) | MinGW-GCC. | 14.2.0 | x86-64 | Release branch CI status |

WARNING - DISCLAIMER

Note: PLCs control many kinds of equipment and loss of property, production or even life can happen if mistakes in programming or access are made. Always use caution when accessing or programming PLCs!

We make no claims or warrants about the suitability of this code for any purpose.

Be careful!

Get it!

Download it from the releases page!

Support it!

If you find libplctag useful, consider supporting its development:

Thanks to our $25+/month sponsors:

  • @jspinks8144 - thanks!

Features

High Level Features

  • EtherNet/IP and Modbus TCP support.
  • Open source licensing under the MPL 2.0 or LGPL 2+.
  • Pure C library for portability across Linux, Windows and macOS as well as 32-bit and 64-bit.
  • Support for x86, ARM and MIPS, and probably others.
  • Very stable API with almost no changes other than feature additions since 2012.
  • Low memory use and very high performance and capacity. Uses protocol-specific features to increase performance.
  • Simple API with minimal use of language-specific data to enable easy wrapping in other languages.
  • Extensive example programs showing use of all library features.
  • Wrappers for higher level languages like C#/.Net, Julia etc.
  • Free!

Detailed Features

PLC Support

  • support for Rockwell/Allen-Bradley ControlLogix(tm) PLCs via CIP-EtherNet/IP (CIP/EIP or EIP).
    • read/write 8, 16, 32, and 64-bit signed and unsigned integers.
    • read/write single bits/booleans.
    • read/write 32-bit and 64-bit IEEE format (little endian) floating point.
    • raw support for user-defined structures (you need to pull out the data piece by piece)
    • read/write arrays of the above.
    • multiple-request support per packet.
    • packet size negotiation with newer firmware (version 20+) and hardware.
    • tag listing, both controller and program tags.
  • support for Rockwell/Allen-Bradley Micro 850 PLCs.
    • Support as for ControlLogix where possible.
  • support for older Rockwell/Allen-Bradley such as PLC-5 PLCs (Ethernet upgraded to support Ethernet/IP), SLC 500 and MicroLogix with Ethernet via CIP.
    • read/write of 16-bit INT.
    • read/write of 32-bit floating point.
    • read/write of 32-bit integer (L data file) on Micrologix.
    • read/write of arrays of the above (arrays not tested on SLC 500).
    • read/write single bits for B and N data files.
  • support for older Rockwell/Allen-Bradley PLCs accessed over a DH+ bridge (i.e. a LGX chassis with a DHRIO module) such as PLC/5, SLC 500 and MicroLogix.
    • read/write of 16-bit INT.
    • read/write of 32-bit floating point.
    • read/write of arrays of the above.
  • extensive example code. Including
    • tag listing.
    • setting up and handling callbacks.
    • logging data from multiple tags.
    • reading and writing tags from the command line.
    • getting and setting individual bits as tags.
  • Support for Omron NX/NJ series PLCs as for Allen-Bradley Micro800.
  • Support for Modbus TCP.

Platform Support

  • CMake build system for better cross-platform support on Windows, Linux and macOS.
    • Native CMake support is present in recent versions of Microsoft Visual Studio.
  • Semantic versioning used and supported with specific library APIs for compatibility and feature checking.
  • C library has no dependencies apart from libc, or musl, and pthreads on some platforms.
  • Binary release for all Tier 1 platforms as well as Linux (Ubuntu/Debian) Arm v6 and Arm v7-hf.
  • RaspberryPi supported. Both Linux and Windows IoT-based (some effort required to configure Visual Studio to build).

Alternate Programming Languages

The C library is designed for easy wrapping. Wrappers for many other languages include the following:

Code

How to Get The Code

The code for the core library is at libplctag. Stable code is on the default release branch. If you check out code from GitHub, it will default to the release branch.

If you want pre-built binaries, we have them available on the releases page. Just pick the one you want and download the ZIP file for your system. We have 32 and 64-bit builds for x86 Linux and Windows and 64-bit builds for x86-64 macOS.

Go to the main project at the libplctag organization to see the other wrappers.

Example Code

Oh, wait, you want code! There are many examples in the examples directory.

A good place to start is

View on GitHub
GitHub Stars862
CategoryDevelopment
Updated2d ago
Forks266

Languages

C

Security Score

100/100

Audited on Mar 29, 2026

No findings