I have a machine learning and advanced control application in Python (TensorFlow + Gekko) that I need to integrate with a Programmable Logic Controller (PLC) that provides the data acquisition and final element control. Can I use a rack-mounted Linux (preferred) or Windows Server as the computational engine, with data transport through OPC-UA (OLE for Process Control – Universal Architecture)?
There is a Python OPC-UA / IEC 62541 Client (and Server) and a Python MODBUS package that I’ve used on other projects when connecting to Distributed Control Systems (DCS) such as Emerson DeltaV, Honeywell Experion/TDC3000, and Yokogawa DCS. Can I do the same with PLC function blocks such as with the Siemens Simatic S7-300? Siemens has newer PLCs that support TensorFlow such as the SIMATIC S7-1500 NPU (Neural Processing Unit) module but there are a variety of reasons why an external server is desirable. The IEC 61131 standard and PROFINET CBA standard are supported (IEC 61499 standard for Siemens) in the S7-300.
Below is a minimal function block that I’d like to use to communicate with a function block.
from opcua import Client client = Client("Matrikon.OPC.Simulation") try: client.connect() root = client.get_root_node() # Get a variable node using browse path myvar = root.get_child(["0:Objects", "1:MyObject", "2:MyVariable"]) print('Variable is ', myvar) finally: client.disconnect()
Advertisement
Answer
I had an experience that the ABB harmony OPC server didn’t support the ‘opcua’ as well. So, I used ‘OpenOPC’ package instead of ‘opcua’ like John suggested in the comment. But, I’m not sure the particular brand of OPC is compatible with ‘opcua’ or ‘OpenOPC’.
Please see the code that I used for OpenOPC package for test.
import OpenOPC import time import pywintypes pywintypes.datatime = pywintypes.TimeType opc = OpenOPC.client() opc.servers() opc.connect('Matrikon.OPC.Simulation.1') tags = ['Random.Int1', 'Random.Real4'] while True: try: value = OPC.read(tags,group='Simulation Items',update=1) print (value) except OpenOPC.TimeoutError: print ("TimeoutError ocured") time.sleep(1)