Fpo 011
Fpo 011
Fpo 011
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
ISBN 978-3-95450-146-5
180 Data Acquisition
Proceedings of PCaPAC2014, Karlsruhe, Germany FPO011
ISBN 978-3-95450-146-5
Data Acquisition 181