OPC Programming with Python and gateway service using Pyro
OpenOPC uses the DA Automation interfaces. It will work with Automation wrapper DLLs from a range of vendors, and ships with the Graybox wrapper.
If you know Python already, you're sure to love OpenOPC..
OpenOPC for Python is a free, open source toolkit that makes easier OPC DA client programming. As a bonus, OpenOPC includes a gateway service allowing remote, and even cross-platform (Linux, Mac) operation. The gateway makes use of Pyro (Python Remote Objects).
Pyro is short for PYthon Remote Objects. It is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. Never worry about writing network communication code again, when using Pyro you just write your Python objects like you would normally. With only a few lines of extra code, Pyro takes care of the network communication between your objects once you split them over different machines on the network. All the gory socket programming details are taken care of, you just call a method on a remote object as if it were a local object.
Pyro provides an object-oriented form of RPC. You can use Pyro within a single system but also use it for IPC. For those that are familiar with Java, Pyro resembles Java's Remote Method Invocation (RMI). It is less similar to CORBA - which is a system- and language independent Distributed Object Technology and has much more to offer than Pyro or RMI.
opc = OpenOPC.client()
print opc['Channel 1.Real8']
The functional programming style allows statements to be chained in an elegant, readable manner. This single line of code, for example
will read the values of all items matching the wildcard pattern.
Standard Python constructs are used wherever possible. For example, the read() function returns a tuple consisting of the value, quality and timestamp:
(19169, 'Good', '06/24/07 15:56:11')
value, quality, time = opc.read('Random.Int4')
Alternatively, the short form of the function supplies only the value, which will be set to None in the event of any problem:
value = opc['Random.Int4']
OpenOPC for Python
OpenOPC for Python is a free, open source OPC (OLE for Process Control) toolkit designed for use with the popular Python programming language.
Because the OpenOPC library implements a minimal number of Python functions which may be chained together in a variety of ways, the library is simple to learn and easy to remember. In its simplest form, you can read and write OPC items as easily as any variable in your Python program.
print opc['Square Waves.Int4']
opc['Square Waves.Real8'] = 100.0
Cross platform support
OpenOPC works with both Windows and non-Windows platforms. It has been tested with Windows, Linux, and Mac OS X.
Most OPC toolkits today are designed for use with static system languages (such as C++ or C#), providing a close mapping to the underlying Win32 COM methods. OpenOPC discards this cumbersome model and instead attempts to take advantage of the dynamic language features provided by Python.
OPyCua is an attempt to write an OPC UA communication stack using the Python programming language.
- 'share early, share often'
- Write a series of articles describing how opc ua works, using python code snippets.
- Create a consistent ua comunication stack in python for the binary TCP mapping.
- Create an API for writing OPC UA servers and clients.
The Python Standard Library comes with all the tools we need to implement an OPC UA communication stack.
Using these 3 modules we can implement the 'Transport Layer', the 'Secure Channel Layer' and the 'Serialization Layer'.
- There is socket to create TCP packets and throw them on the wire.
- There is ssl to create secure sockets. Using OpenSSL, which is also used by the OPC Foundation.
- There is struct to encode and decode binary data. ( But we'll probably use Construct )
XML/DA client |
Java clients |
DCOM implement |
Intermediate SW/HW solution |
UA-COM wrappers |
Links and tools