OPC UA

OPC UA (Open Platform Communications United Architecture) is a data exchange standard for industrial communication. It is an open interface standard that is independent of the manufacturer or system supplier of the application.

As a temporary solution, we are implementing communication using a Python OPC UA client. The Python script serves as a kind of middleman and communicates with the remote station and horstFX via OPC UA.

How the OPC UA client is set up and how communication with horstFX works is described below. The following procedure may vary from case to case and therefore serves as an example.

1. Installing the Python OPC UA client

We utilize the FreeOpcUA Python client as our OPC UA client. https://github.com/FreeOpcUa/python-opcua 

This client is installed and configured on the control box. This setup allows the Python script to be conveniently started directly from horstFX.

1.1. Installing / Checking the Installed Python Version

Certain versions of Debian Linux come pre-installed with Python 3, including the version installed on our control box.

To execute commands via the console:

1. Log in as the Root User:

su -l root

Please request the password directly from fruitcore.

 

2. Updating the System:

apt update

Avoid executing the "apt upgrade" command.

 

3. Checking the installed Python version

python3 -V

1.2. Installing pip

To install pip via the console, use the following commands:

apt install -y python3-pip
pip3 install --upgrade pip

1.3. Installing the OPC-UA client and necessary packages

The necessary libraries can be installed via the console using the following commands.

1. Install numpy:

pip3 install numpy

2. Installing cryptography:

pip3 install cryptography

3. Installing dateutil:

pip3 install python-dateutil

4. Installing the lxml library:

pip3 install lxml

5. Installing the pytz library:

pip3 install pytz

6. OPC-UA Client Installation

pip3 install opcua

2. How the Python OPC UA Client Works

The functionality of the client is well described at https://github.com/FreeOpcUa/python-opcua. There are plenty of examples available to help understand how it works effectively.

3. Communication between horstFX and the Python OPC UA Client

Communication between the Python script and horstFX can be established using TCP/IP sockets.

3.1. Setting up Communication in horstFX

How communication can be established on the horstFX side is described in the 'Sockets' section.

Setting up communication on the Python side

Integrating the Socket module in Python can be achieved by using the following command:

import socket

3.2.1. Setting up the Socket Connection

# Socket Connection
HOST = "0.0.0.0"                                # IP HORST
PORT = 3000                                     # Port HORST
 
# connect to horstFX via Socket
s = socket.socket()                             # Create a Socket object
s.bind((HOST, PORT))                            # Bind the port.
print("socket listen for client")
s.listen(5)                                     # Wait for client connection.
c, addr = s.accept()                            # Establish connection with the client.
print("socket accepted by client")

3.2.2. Reading the message from horstFX

msg = c.recv(1024)                                  # Read the message from horstFX via the Socket.

3.2.3. Sending a message to horstFX

c.sendall("Hallo HORST".encode('utf-8'))             # Send a message to HORST via the Socket.

4. Running the Python script directly through horstFX

Instructions on how to run the Python script for communication via OPC UA directly from horstFX are detailed in the 'Running External Python Scripts' section.