iterativ / openopc2

πŸ”₯ OPC DA Python Library with awesome CLI
Other
92 stars 12 forks source link
opc opc-da opc-da-client opc-da-server openopc

LinuxSetup

PyPI version PyPI - Python Version

OpenOPC 2 is a Python Library for OPC DA. It is Open source and free for everyone. It allows you to use OPC Classic (OPC Data Access) in modern Python environments. OPC Classic is a pure Windows technology by design, but this library includes a Gateway Server that lets you use OPC Classic on any architecture (Linux, MacOS, Windows, Docker). So this Library creates a gateway between 2022 and the late 90ties. Like cruising into the sunset with Marty McFly in a Tesla.

OpenOPC 2 is based on the OpenOPC Library that was initially created by Barry Barnleitner and hosted on Source Forge, but It was completely refactorerd and migrated to Python 3.8+

πŸ”₯ Features

🐍 OpenOPC vs OpenOPC 2

Open OPC 2 is based on OpenOPC and should be seen as a successor. If you already have an application that is based on OpenOPC, you can migrate with a minimal effort. Our main motivation to build this new version was to improve the developer experience and create a base for other developers that is easier to maintain, test and work with...

πŸš€ Getting started

Windows local installation

The quickest way to start is the cli application. Start your OPC server and use the openopc2.exe cli application for test (no python installation required).

Now you know that your OPC server is talking to OpenOPC 2. Then lets get started with python. If you use OpenOPC 2 with Python in windows directly you are limited to a 32bit Python installation. This is because the dlls of OPC are 32bit. If you prefer working with a 64bit Python version you can simply use the With OpenOPC Gateway.

WindowsSetup

You must install the gbda_aut.dll (in /lib) which is the GrayboxOpcDa wrapper.

http://gray-box.net/daawrapper.php?lang=en

python -m openopc2 list-servers

Multi platform installation

One of the main benefits of OpenOPC 2 is the OpenOPC gateway. This enables you to use any modern platform for developing your application. Start the OpenOPC service in the Windows environment where the OPC server is running. The Service starts a server (Pyro5) that lets you use the OpenOPC2 OpcDaClient on another machine. Due to the magic of Pyro (Python Remote Objects) the developer experience and usage of the Library remains the same as if you work in the local Windows setup.

(Download the executables here)

LinuxSetup

On the Windows Machine open the console as administrator.

openopcservice install
openopcservice start

On your Linux machine

pip install openopc2

python

from openopc2.da_client import OpcDaClient

βš™οΈ Configuration

The configuration of the OpenOpc 2 library and the OpenOpcGateway is done via environment variables.

OPC_CLASS=Graybox.OPC.DAWrapper
OPC_CLIENT=OpenOPC
OPC_GATE_HOST=192.168.1.96    # IMPORTANT: Replace with your IP address
OPC_GATE_PORT=7766
OPC_HOST=localhost
OPC_MODE=dcom
OPC_SERVER=Matrikon.OPC.Simulation
C:\>set ENV_VAR=VALUE
C:\>set OPC_GATE_HOST=172.16.4.22    # this is an example
C:\openopc2\lib>regsvr32 gbda_aut.dll
C:\openopc2\lib>regsvr32 gbda_aut.dll -u

CLI

The CLI (Command Line Interface) lets you use OpenOPC2 in the shell and offers you a quick way to explore your opc server and the OpenOPC DA client without the need of writing Python code.

The documentation of the CLI can be found here

WindowsSetup

WindowsSetup

WindowsSetup

WindowsSetup

OpenOPC Gateway

This task can be completed from one of two ways (make sure to have it installed first):

C:\openopc2\bin> zzzOpenOPCService
C:\openopc2\src>python OpenOPCService.py debug
C:\openopc2\>net stop zzzOpenOPCService

Configure the way the OpenOPC Gateway Service starts

If you are going to use this service frequently, it would be better to configure it to start in "automatic" mode. To do this:

πŸ™ Credits

OpenOPC 2 is based on the OpenOPC python library that was originally created by Barry Barnleitner and its many Forks on Github. Without the great work of all the contributors, this would not be possible. Contribution is open for everyone.

The authors of the package are (among others):

Years Name User
2008-2012 πŸ‡ΊπŸ‡Έ Barry Barnreiter barry_b@users.sourceforge.net
2014 πŸ‡·πŸ‡Ί Anton D. Kachalov https://github.com/ya-mouse
2017 πŸ‡»πŸ‡ͺ JosΓ© A. Maita https://github.com/joseamaita
2022 πŸ‡¨πŸ‡­ Lorenz Padberg https://github.com/renzop
2022 πŸ‡¨πŸ‡­ Elia Bieri https://github.com/eliabieri

πŸ“œ License

This software is licensed under the terms of the GNU GPL v2 license plus a special linking exception for portions of the package. This license is available in the LICENSE.txt file.