Fpo 011

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Proceedings of PCaPAC2014, Karlsruhe, Germany FPO011

PyPLC, A VERSATILE PLC-TO-PC PYTHON INTERFACE


S. Rubio-Manrique, G. Cuní, D. Fernandez-Carreiras, Z. Reszela, A. Rubio,
CELLS-ALBA Synchrotron, Barcelona, Spain

Abstract Systems, on which the Tango Control System have just


The PyPLC Tango Device Server provides a developer- read access. The same control interface is used to
friendly dynamic interface to any Modbus-based control communicate with all this subsystems, with certain
device. Raw data structures from PLC are obtained customization depending on the control needs.
efficiently and converted into highly customized attributes
using the python programming language. The device PLC TANGO DEVICES
server allows to add or modify attributes dynamically An interface between Tango Control System and our
using single-line python statements. The compact python PLC-based subsystems was needed for three main
dialect used is enhanced with Modbus commands and purposes:
methods to prototype, simulate and implement complex
• Supervision of autonomous systems based on PLC's
behaviours. As a generic device, PyPLC has been
(EPS, PSS).
versatile enough to interact with PLC systems used in
• Configuration of the EPS settings and interlock
ALBA Accelerators as well as to our Beamlines SCADA
thresholds during commissioning.
(Sardana). This article describes the mechanisms used to
• Integrate critical and diagnostics signals into our
enable this versatility and how the dynamic attribute
Control services like Archiving, Taurus UI, Alarms,
syntax allowed to speed up the transition from PLC to
Beamlines SCADA (Sardana) [6][7].
user interfaces.

INTRODUCTION To achieve a successful integration of the PLC signals


into our control system it was needed to automate the
ALBA[1], member of the Tango Collaboration[2][3], is creation of Tango Attributes in the PLC device servers.
a third generation Synchrotron in Barcelona, Europe. It The commissioning work-flow required a regular update
provides light since 2012 to users through its 7 of I/O and variables lists in the PLC's, and existing UI's
beamlines,with 2 more under construction. and services like archiving had to be capable to keep pace
Programmable Logic Controllers from several vendors with each update of the attribute list.
(B&R, Pilz, …) are used for acquisition, protection and
motion within our Tango Control System[4]. PLC's are
the main component of equipment and personnel
protection systems, but they are also used in accelerators
and beamlines for vacuum/temperature diagnostics and
motion control. The most complex system managed by
PLC's is the Equipment Protection System (EPS)[5].
Equipment Protection System at ALBA
The EPS is an autonomous system ensuring the safe

Copyright © 2014 CC-BY-3.0 and by the respective authors


operation of all elements in ALBA accelerators and Figure 1: PyPLC Device Architecture.
Beamlines. It generates both interlocks and operation
permits, following the logics previously defined between DEVELOPING A PLC TANGO DEVICE
the Control section and the Accelerators and Experiments The first device server developed at ALBA for
divisions and programmed by Control engineers. communicating with PLC's was a C++ device server,
EPS uses 58 B&R CPU's and 110 periphery cabinets to ModbusPLC, running on top of the Modbus Device
collect more than 7000 signals. In addition to the main developed at the ESRF; that already implements all basic
purpose of protection, several hundreds of signals Modbus commands. The ModbusPLC C++ Tango device
distributed across the whole system are acquired for allowed to create and remove attributes depending on
diagnostics and control of movable elements: Tango property values [8], exporting as many integer
temperatures, vacuum sensors, position encoders and attributes as 16 bits registers were mapped in Modbus.
switches, electrovalves, ... This implementation presented several drawbacks:
Other PLC-based Systems • Hides the diversity of signals available from the PLC
The Modbus protocol and Tango devices are also used (digital inputs, flag registers, integers, 16 bits floats,
to control PLC's in the RF circulators, bakeout 32 bit values spanning multiple registers).
controllers, water cooling system, air conditioning in the • Too rigid for showing complex elements (needed
experimental hutches and overall Personnel Safety many attributes to represent a 3-position valve).

ISBN 978-3-95450-146-5
Data Acquisition 179
FPO011 Proceedings of PCaPAC2014, Karlsruhe, Germany

• Triggered 1 Modbus command per attribute read, for Table 2: PyPLC Command Formulas
a typical beamline PLC with hundreds of attributes it Open_PNV01=(WriteBit(193,2,1),1)[-1]
meant a full refresh every 30 seconds or so.
Close_PNV01=(WriteBit(193,1,1),0)[-1]
PyPLC, a Dynamic PyTango Device Server
PyTango, the Python binding of Tango, is the common
framework of development at ALBA [9]. The PyPLC Optimizing Modbus Communications
python device server overcomes the limitations of
ModbusPLC, providing the high versatility of python [10] The Modbus devices used at ALBA (mostly B&R plc's)
above the robustness of the reliable Modbus C++ server show several limitations in the implementation of their
(Fig.1). Modbus communications. The maximum amount of
registers to be acquired in a single modbus exchange is
Advantages of PyTango device servers in python are: 120. And those communications take between 120 ms and
• Python is a dynamically typed language, making 160 ms independently of the number of addresses read on
devices prototyping and extension much faster. each command.
• Objects and libraries are mutable, multiple To avoid these problems, PyPLC enhances the Modbus
inheritance and classes are modifiable in runtime. Tango Device providing smart mapping of the PLC
• Device servers can be executed in any OS with no memory. It allows to optimize ethernet/ serial
need of compiling or packaging. communications and setup selective address refresh when
• Tools like SWIG or Boost allow to use C++ APIs needed. The memory areas are read and allocated in the
libraries from python. device server as arrays, each of them dedicated to a
• In fact PyTango is just a layer above Tango C++, certain type of data (boolean, int, float, double). Attributes
which means that any feature/patch of mainstream of the PyPLC device will not access the Modbus
Tango is also available in PyTango. communications but this arrays mapped in memory
• Python allows to execute string formulas as python instead.
code, enabling complex Dynamic Attributes
declaration on runtime. Actually the refresh of a typical ALBA PLC is about 3
seconds for a PLC with 2000 registers mapped to 300
Taking profit of these advantages, we developed a attributes. Although faster refresh of certain areas of the
DynamicDS[11] template for Tango Devices that memory can be setup up to 300 ms.
provided dynamic attribute type creation, customized
calculations, configurable state composing and attribute- EXTENDING PYPLC
grouping. All these features being achieved through an Exporting PLC Variables to PyPLC
easy syntax accessible to machine operators and
scientists. When programming the PLC's, the controls engineer
load variables information retrieved from our cabling and
PyPLC inherits from DynamicDS template [12]. controls MySQL database [13]. Visual basic macros are
Creation of attributes is done writing new attribute used to update the PLC program using pre-defined logic
formulas into the DynamicAttributes property of the blocks and the set of signals connected to each CPU and
Tango database, a process that can be done manually or peripherals.
automated by scripts.
Copyright © 2014 CC-BY-3.0 and by the respective authors

Those same Visual basic macros generate .csv files that


Table 1: PyPLC Attribute Formulas, Int Array and a are used by the EPS Taurus UI and PyPLC device server
Writeable Boolean Flag. to load variables lists and Dynamic Attributes declaration.
TEMPERATURES=
Thanks to that, Taurus User Interfaces and PyPLC
DevVarLongArray(Regs(7800,100))
attributes are updated whenever the PLC program is
DIO_01= bool(
modified, with no need of editing the source code.
READ and Flag(80,7) or
WRITE and WriteFlag(81,7,int(VALUE))) Many analog and digital signals in ALBA beamlines
have been exported to the experiment control framework,
Sardana. The Sardana suite allows to add Tango
To enable the use of Modbus commands in the attribute
controlled hardware as experimental channels, being able
formulas, the PyPLC exports all the commands needed
to use them as I/O or experimental data (e.g. temperatures
for accessing Modbus variables (Read/Write
and vacuum pressures). Limited motion control have been
Input/Holding Registers) and PLC variable type
implemented using PyPLC, which allowed direct control
(Bit/Coil/Flag/Int/Long/Float/IeeeFloat/Double). Those
from Sardana macros used by scientists.
methods can be used inside attributes (Table 1) or
commands (Table 2) declaration to access any type of
variable mapped in Modbus addresses.

ISBN 978-3-95450-146-5
180 Data Acquisition
Proceedings of PCaPAC2014, Karlsruhe, Germany FPO011

Extending PyPLC Functionality REFERENCES


PyPLC provides a common interface to any device that [1] ALBA website: http://www.cells.es
uses the Modbus protocol, specific States and Status [2] TANGO website: http://www.tango-controls.org
messages can be linked to PLC values using the same [3] A.Götz, E.Taurel et al., “TANGO V8 – Another Turbo
syntax of dynamic attributes. But, certain subsystems Charged Major Release”, ICALEPCS'13, San
require a more specific interface to express intermediate Francisco, USA (2013)
states like warning, external interlocks, complex error [4] R.Ranz et al., “ALBA, The PLC based Protection
codes, attributes managed by multiple registers (e.g. Systems.”, ICALEPCS'09. Kobe, Japan (2009)
multiple-stage pneumatic elements). [5] D.Fernández-Carreiras et al., “Personnel protection,
equipment protection and fast interlock systems”,
This is achieved subclassing PyPLC into new Tango
ICALEPCS'11, Grenoble, France (2011)
Devices that extend its functionality, in the same way that
[6] T.Coutinho et al., "Sardana, The Software for
PyPLC inherits from DynamicDS. Those classes are
Building SCADAS in Scientific Environments",
AlbaPLC (customized to EPS state machines), PLCValve
ICALEPCS'11. Grenoble, France (2011)
for pneumatic valves and FSOTR for 3-position
[7] SARDANA website: http://www.sardana-controls.org
fluorescence screens. Those classes use Tango Qualities
[8] R.Sune, E.Taurel and S.Rubio, “Adding Dynamic
to complement the raw attribute values, passing the
Attributes to a C++ Device Server”, available at
information regarding Alarm/Warning/Moving limits and
www.tango-controls.org (2008)
positions with each value sent to clients.
[9] D.Fernández et al., “Alba, a Tango based Control
Higher-level procedures involving several Tango System in Python”, ICALEPCS'09, Kobe, Japan
devices are implemented using macros from PANIC (2009)
Alarm System[14][15] or Sardana SCADA. Those macros [10] S.Rubio et al., “Dynamic Attributes and other
allow the scientists to program automated actions on functional flexibilities of PyTango”, ICALEPCS'09,
elements controlled by the EPS (valves, shutters) during Kobe, Japan (2009)
experiments. [11] Fandango website: http://www.tango-controls.org/
Documents/tools/fandango/fandango
CONCLUSSION [12] PyPLC website: http://www.tango-controls.org/
PyPLC Tango Device provides a common interface to device-servers/alba/pyplc-device-server/
all PLC's at ALBA using the Modbus protocol. This [13] D. Beltran et al., “ALBA Control And Cabling
developer-friendly interface allowed dynamic and effort- Database”, ICALEPCS'09, Kobe, Japan (2009)
less integration of new PLC signals into our Archiving, [14] S.Rubio et al., “Extending Alarm Handling in
Alarm System and Beamlines SCADA (Sardana). This Tango”, ICALEPCS'11, Grenoble, France (2011)
work-flow enabled by PyPLC reduced the time needed to [15] S.Rubio et al., “PANIC, a Suite for Visualization,
upgrade or modify PLC systems in Beamlines. Logging and Notification of Incidents”, PCaPAC'14,
Karlsruhe, Germany (2014)
ACKNOWLEDGEMENTS
Many former ALBA engineers have collaborated in the
PLC-related projects in the last 6 years: D.Fernández,
A.Rubio, R.Ranz, R.Montaño, R.Suñé, M.Niegowski,

Copyright © 2014 CC-BY-3.0 and by the respective authors


M.Broseta and J.Villanueva. The collaboration of Tango
core developer, Emmanuel Taurel, was fundamental in
the development of Dynamic Attributes templates and
debugging of PyPLC performance.

ISBN 978-3-95450-146-5
Data Acquisition 181

You might also like