Blog | Accelerators, Big science, Fusion, Technology

A Fast Integration of PLCs and EPICS

Jernej Varlec

Programmable logic controllers (PLCs) have been widely used in industrial control systems for many years now, such as aviation, automotive, processing, production assembly-line, manufacturing, energy and oil-processing industry. Engineers find PLCs simple to program and capable of controlling a multitude of automatic processes. PLCs contain microcontroller units (MCUs) whose capabilities have increased steadily with time, making PLCs much more capable than a decade ago and ready to tackle new challenges in system automation.


PLCs run a real-time proprietary operating system and have a hardened embedded processor. They have become one of the best options for various industrial automation solutions based on their increased programming flexibility and ease, smaller sizes, larger memory, scalability, and Gigabit Ethernet and built-in wireless features.

In a nutshell: today’s PLC technology is flexible, easy to use, well-known and dependable. That is why the use of PLCs to control large physics machines has also become universal. Nevertheless, PLC deployment was traditionally the domain of electrical engineers. With rapid new approaches, including integration with open-source frameworks such as EPICS, PLC program development is increasingly becoming a software engineer’s game.

Beckhoff Communication Options

We have various projects in which we have found Beckhoff to be the optimal choice for PLC technology in our customers systems. In our experience, Beckhoff offers good round-the-clock user support and affords good and affordable development environment tools. The company provides a multitude of communication options such as EtherCAT, Modbus/TCP and ADS.

We also find Beckhoff a great choice because it offers a lot of support for OOP (Object-Oriented Programming) development – and thus the development of modular code that is not difficult to maintain. A big plus in a world of spaghetti code! TwinCAT also works well with Git and allows multiple people to efficiently work together on a project, which is not quite the rule in the PLC world.

In the past, the scientific community has used mainly Modbus for interfacing Beckhoff’s PLCs to the software framework in its machines because of Modbus’ manageability and simplicity. On the other hand, we found ourselves often needing higher performance, so we are now concentrating on leveraging ADS — the Automation Device Specification. The latter describes a device-independent and fieldbus-independent interface to devices within the TwinCAT system architecture.

Why Did We Choose the ADS Interface?

First of all, ADS is Beckhoff’s proprietary communication protocol that is well optimised to interconnect all of the various modules the company provides internally, so it is stable and fast. For us, it was the natural protocol to use for communicating with PLCs in demanding systems. Traditionally, Beckhoff has provided a dependable ADS library, regularly updated, that can be used in C or C++ programs. This means it perfectly fits our EPICS (Experimental Physics and Industrial Control System) applications, where we combine the library with our own optimised driver. The latter allows us to develop quickly and runs on top of TCP/IP, allowing for high data throughput, which is essential for us. (When integrating EPICS and Beckhoff PLCs, we usually program in C++ and use double slashes.)

Figure 1: Architecture of EPICS IOC – ADS Device Integration.


Our reasons to use Beckhoff’s ADS protocol:

  • Beckhoff provides a library that can be used with AsynPortDriver;
  • Runs on top of the TCP/IP stack;
  • Assures high volume data throughput;

Developing Our Own EPICS Device Support for ADS

A few years ago, we investigated all the available EPICS and Beckhoff integration solutions, but none satisfied our requirements. We wanted something that could easily be included as an EPICS module and at the same time can read large numbers of EPICS PVs (Process Variables). So we created an EPICS module which we based on the AsynPortDriver.

We are proud we could increase the speed of writing data by using a couple of different methods for standard reading, otherwise limited to 500 variables per second. We created another way of reading by queuing up the reads from PLC to the EPICS database in “bunches” of up to 15 reads in one transaction.

We then execute the reads in multiple transactions, which speed up the transfer to EPICS quite significantly. With our tests, we have measured the new limit to be about 10 kPVs (scalar) per second. We are currently working to similarly increase the writing speed from EPICS databases to PLCs, as well. Namely, the generic rate supported by the Beckhoff library is roughly 500 PLC variables per second. With the new write method, we expect to reach speeds with at least several kPVs per second.

Characteristics of the new EPICS module using the DynamicAsynPortDriver:

  • PLC to EPICS read-speed up to 10k PVs per second;
  • EPICS to PLC write-speed up to 500 PLC-variables per second at the moment (multiple thousand PLC-variables per second speed upgrade in development);
  • DynamicAsynPortDriver enables dynamically variable registration at runtime;

Figure 2: Test results of reading rates


A PLC-based Machine Protection System

The increased reading speed was crucial in several of our projects. For example, for a client we created a fast machine protection system (MPS) that runs on PLCs with an EPICS-based monitoring interface. To our knowledge, the latter has not been done before with the high reading speeds, and we are pretty proud of this.

The MPS in question requires a lot of simultaneous data reads of the system sensor parameters. In this case, we nearly reached the maximum dependable throughput rate of 10 kPVs per second that our new integration solution enables. All of the MPS logic is contained on the PLCs, and we use EPICS just as an operator interface. We gave the customer the possibility to have full-screen functionality for the PLCs while taking advantage of the PLC speed of processing.

Namely, the latter has a fast refresh rate and address data items with a cycle time of 50 microseconds. So we can still interlock fast enough for the system to be considered safe. Basically, we use the EPICS database just as an interface to the operators who can observe the system via the screens facilitated by EPICS.

The whole logic is on the PLCs; all the interlocks happen there. The EPICS database is used for alarm logging, archiving, and, as mentioned, displays for operators. The latter can interact with the MPS, i.g., set threshold values for interlocks and alarms, acknowledge interlocks, read logs.


We believe that interfacing PLCs with EPICS in scientific applications will become more and more common. We intend to spruce up the DynamicAsynPortDriver with refactoring and better documentation. We will also update the ADS device support to use the latest version of the Beckhoff ADS library. Work progresses on improving write speeds via Beckhoff ADS from EPICS to PLCs. Ideally, we want to get to similar rates as when reading. Naturally, we also have some additional ideas too.

At Cosylab, we have been appreciative EPICS users for quite some time and have supported the EPICS community throughout the years. After a couple of less active years, we are ramping up our collaboration with the open-source community by increasing our contribution. We plan to release our ADS device support on GitHub soon so that it will be open to any pull request and improvement from the EPICS community. We will, of course, be also open to any questions regarding the new module.

See you at the next EPICS collaboration meeting!

About the author

Jernej Varlec has spent the last couple of years working closely with customers worldwide, helping them with control system design and device integration problems. As part of the Scientific Services, he is hard at work strengthening the team’s capabilities in software development, device integration, and project management. When he is not poking around control systems, he likes to read a good book or pot a couple of balls at the local pool hall.

Others Also Read