Skip to content

OpenOPC and Python 3.7 on Windows

Introducing OpenOPC and Python 3.7

OpenOPC and Python 3.7 on Windows are the correct setup when working with some industrial automation projects that implement industry-tested OPC DA servers. It’s possible to use it from learning how the OPC DA protocol actually works to connect to multiple servers and build applications for deeper data integration.

OpenOPC for Python is a free, open source and easy to use OPC (OLE for Process Control) library that works very well with the popular Python programming language (now, version 3.7) on Windows. Also, includes a Windows gateway service that enable non-Windows clients to also access OPC-DA calls.

The procedure described here allow us to integrate OpenOPC 1.2.0 with recent versions of Python (v3.7+) and Pyro4 (v4.80+) installed on Windows.

Interested in the original version from Barry Barnreiter? Go here. However, if you want to try a different fork that works with Python 3.4+ (if you make some minor changes to the Python source code that affects Pyro4), go to the GitHub version of Anton D. Kachalov by clicking here.

To start working with OpenOPC and Python 3.7 on Windows, we need to know what’s included in the package:

  • An OpenOPC Gateway Service (a Windows service providing remote access to the OpenOPC library, which is useful to avoid DCOM issues).
  • An OpenOPC for Python library module (used to connect to an OPC server from both Windows and Linux).
  • A system check module (allows you to check the health of your system for performance, free memory, tasks list, among others).
  • A free OPC automation wrapper (required DLL file).
  • Documentation from the original author.

Prerequisites and Considerations

Basic Settings

Follow these steps to prepare your work environment:

  • First, understand the main goal here. We want to use OpenOPC 1.2.0 and Python 3.7.6 on Windows to exchange data with a standard OPC DA server on a Windows system through an OPC client application.
  • Next, design a system architecture for OPC DA remote data communication (both the server and client nodes are in different machines):
Prepare OPC DA system architecture to work with OpenOPC and Python
  • Make sure to download and install a recent Python version (we use here v3.7.6 on 32-bit) in both your server and client nodes. To do this, go here.
Python 3.7 downloads page
  • Make sure to download and install Python for Windows Extensions (pywin32) for the Python version you’re using (3.7) and for both your server and client nodes (pywin32-228.win32-py3.7.exe). To do this, go here.
Python for Windows Extensions on GitHub (required to work with OpenOPC)
  • Make sure to download and install a recent Pyro4 version (we use here v4.80) in both your server and client nodes. To do this, open a terminal prompt and use the “pip install Pyro4” command (it also installs associated package, “serpent”).
Installing Pyro4 with serpent on Windows (compatible version with Python 3.7)

Advanced Settings

  • Make sure to set these environment variables in your server node (use your own IP address in the OPC_GATE_HOST variable).
OPC_CLASS=Matrikon.OPC.Automation;Graybox.OPC.DAWrapper;HSCOPC.Automation;RSI.OPCAutomation;OPC.Automation
OPC_CLIENT=OpenOPC
OPC_GATE_HOST=192.168.1.6 # IMPORTANT: Replace with your own IP address
OPC_GATE_PORT=7766
OPC_HOST=localhost
OPC_MODE=dcom
OPC_SERVER=Hci.TPNServer;HwHsc.OPCServer;opc.deltav.1;AIM.OPC.1;Yokogawa.ExaopcDAEXQ.1;OSI.DA.1;OPC.PHDServerDA.1;Aspen.Infoplus21_DA.1;National Instruments.OPCLabVIEW;RSLinx OPC Server;KEPware.KEPServerEx.V4;Matrikon.OPC.Simulation;Prosys.OPC.Simulation
Required environmental variables for OpenOPC on Windows
  • Make sure to allow the firewall to keep the port 7766 open. If in doubt, and you’re doing a quick test, just turn off your firewall completely.
Firewall port 7766 must be open on Windows
  • Consider to apply the DCOM configuration guidelines written here for both the server and client nodes.
Website for tutorial on DCOM configuration guidelines on Windows
  • Keep in mind this scheme if you’re still have questions about which packages are required and which ones are optional for you to work without issues (remember that Python is necessary on all platforms):
1. Win32 platform, using the OpenOPC Gateway Service

Pywin32: optional
Pyro4: required

2. Win32 platform, talking to OPC Servers directly using COM/DCOM
Pywin32: required
Pyro4: optional

3. Non-Windows platform (use of Gateway Service is mandatory)
Pywin32: not applicable
Pyro4: required
  • For easy OPC client application testing, make sure to install an OPC server in your Windows machine (for instance, “MatrikonOPC Simulation Server”).
Download page for MatrikonOPC Simulation Server (very useful to test OpenOPC)
  • In order to get the most from the OpenOPC package, Windows developers should install both Pywin32 and Pyro4. Using Pyro4 to talk to the Gateway Service provides a quick and easy method for bypassing the DCOM security nightmares which are all too common when using OPC.

Details of Test Environment

  • Now, we’ll consider this specific environment:
Details of test environment that includes OpenOPC and Windows versions

Installation

Getting Started with OpenOPC

Begin to work with this package by doing this:

  • Clone or download the repository as a .zip file from here in both your server and client nodes.
OpenOPC 1.2.0 on GitHub
  • Extract the compressed file to a folder in both your server and client nodes (for instance, “C:\OpenOPC120”).
Contents of extracted OpenOPC package on Windows
  • Open a command prompt window (run it as administrator), go to your work directory and change to the “lib” folder. Then, register the OPC automation wrapper (gbda_aut.dll) in both the server and client nodes using the “regsvr32” command. Finally, check that the registration was successful.
Registering "gbda_aut.dll" (required for OpenOPC on Windows)
  • If, for any reason, you want to uninstall this file and remove it from your system registry later, type this in the command line:
C:\OpenOPC120\lib>regsvr32 gbda_aut.dll -u

Install the OpenOPC Gateway Service

Achieve this goal by running the “OpenOPCService.py” script with the Python interpreter and the “install” argument (remember to do it as administrator):

  • In the server node and as administrator, change to the “src” folder and install the “OpenOPC Gateway Service” by typing this in the command line:
Command to install the OpenOPC Gateway Service on Windows

Usage

Start the OpenOPC Gateway Service

Complete this task from one of two ways (make sure to have it installed first):

  • By clicking the “Start” link on the “OpenOPC Gateway Service” from the “Services” window (Start -> Control Panel -> System and Security -> Administrative Tools).
  • By running the “net start SERVICE” command like this:
Command to start the OpenOPC Gateway Service on Windows
  • You can also try to start this in “debug” mode, if you have problems starting the service:
Command to start the OpenOPC Gateway Service in debug mode on Windows

Stop the OpenOPC Gateway Service

Complete this task from one of two ways:

  • By clicking the “Stop” link on the “OpenOPC Gateway Service” from the “Services” window (Start -> Control Panel -> System and Security -> Administrative Tools).
  • By running the “net stop SERVICE” command.

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:

  • Select the “OpenOPC Gateway Service” from the “Services” window (Start -> Control Panel -> System and Security -> Administrative Tools).
  • Right-click and choose “Properties”.
  • Change the startup mode to “Automatic”. Click “Apply” and “OK” buttons.
  • Start the service (if not already started).
Startup type for OpenOPC Gateway Service on Windows

Implement the OpenOPC library module

The idea here is to test the OpenOPC library in two scenarios. Let’s see:

a. Client/server in the same node

Go to your server station and make sure you have completed the following prerequisites:

  • Windows 10 (64-bit)
  • Python 3.7.6 32-bit
  • Python for Windows Extensions Build 228 for Python 3.7
  • Pyro4 4.80
  • OpenOPC version: 1.2.0
  • OpenOPC Gateway Service version: 1.2.0
  • MatrikonOPC Simulation Server

Also, check these steps:

  • Make sure the “OpenOPC Gateway Service” is installed and running.
  • Make sure the “MatrikonOPC Simulation Server” is installed and running.
  • Go to your OpenOPC local repository (downloaded from here) and change to the “src” folder.
  • Then, open a command prompt to open a Python interpreter.
  • Type in the following instructions (also, follow the output):
>>> import OpenOPC
>>> opc = OpenOPC.open_client('localhost')
>>> opc    # here the "opc" object was created successfully
<Pyro4.core.Proxy …; not connected; for PYRO:obj_cfdb802c74654f21849adf9572fbee4b ...
>>> opc.servers()
['RSOPC Gateway', 'FactoryTalk Gateway', 'Kepware.KEPServerEX.V6', 'RSLinx OPC Server', 'RSLinx Remote OPC Server', 'Matrikon.OPC.Simulation.1']
>>> opc.connect('Matrikon.OPC.Simulation')
>>> opc.list()
['Simulation Items', 'Configured Aliases']
>>> opc.close()

Make sure to get similar responses from the system.

b. Client/server in different nodes

Go to your server station and make sure you have completed the following prerequisites:

  • Windows 10 (64-bit)
  • Python 3.7.6 32-bit
  • Python for Windows Extensions Build 228 for Python 3.7
  • Pyro4 4.80
  • OpenOPC version: 1.2.0
  • OpenOPC Gateway Service version: 1.2.0
  • MatrikonOPC Simulation Server

Also, check these steps:

  • Make sure the “OpenOPC Gateway Service” is installed and running.
  • Make sure the “MatrikonOPC Simulation Server” is installed and running.
  • Now, go to your OpenOPC repository in the remote client node and change to the “src” folder.
  • Then, open a command prompt to open a Python interpreter.
  • Type in the following instructions (also, follow the output):
>>> import OpenOPC
>>> opc = OpenOPC.open_client("192.168.1.6") # IP address for OPC DA server
>>> opc    # here the "opc" object was created successfully
<Pyro4.core.Proxy …; not connected; for PYRO:obj_e931559b8624441bac6744f006638d2 ...
>>> opc.servers()
['RSOPC Gateway', 'FactoryTalk Gateway', 'Kepware.KEPServerEX.V6', 'RSLinx OPC Server', 'RSLinx Remote OPC Server', 'Matrikon.OPC.Simulation.1']
>>> opc.connect('Matrikon.OPC.Simulation')
>>> opc.list()
['Simulation Items', 'Configured Aliases']
>>> opc.close()

Make sure to get similar responses from the system.

Documentation

A PDF manual for OpenOPC is included in this package inside the “doc” folder, written by the original author. Users and developers are encouraged to also look at the OpenOPC web site for additional usage examples that may not be contained in the manual.

Credits

The authors of this package are:

Copyright (c) 2008-2012 by Barry Barnreiter (barry_b@users.sourceforge.net)
Copyright (c) 2014 by Anton D. Kachalov (mouse@yandex.ru)
Copyright (c) 2017 by José A. Maita (jose.a.maita@gmail.com)

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.

Contact

If you need technical assistance to implement this in a larger project, go to the main site here or here for more detailed information.

Share this post

1 thought on “OpenOPC and Python 3.7 on Windows”

  1. Hi Jose, Great writeup, thank you. I contacted you via Email but got no answer, really interested in having a chat with you.

Comments are closed.