1

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()
TexasEngineer
  • 684
  • 6
  • 15
  • PLC typically support either MODBUS or OPC data transfer. Here is an example with Gekko: https://stackoverflow.com/questions/57085640/how-do-you-implement-a-python-gekko-application-for-real-time-systems I'm not sure if they are function blocks that push or there is an MODBUS or OPC server on the PLC that allows writes or reads. – John Hedengren Nov 09 '19 at 23:00
  • Here is another post that may help https://stackoverflow.com/questions/38601989/opc-protocol-and-plc-interworking although it doesn't mention that IEC standards. – John Hedengren Nov 09 '19 at 23:02

1 Answers1

2

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)
Junho Park
  • 997
  • 4
  • 12
  • 1
    Thanks, it is helpful to see another OPC Python package. Do you have any experience with connecting with OPC to PLCs as well? – TexasEngineer Nov 16 '19 at 05:03
  • 2
    My colleagues have successfully used the OPTO22 PLC with python and Gekko. I don't exactly remember which OPC connection they have used. However, I have seen the OPTO22 brochure mentions that they support OPC-UA. – Junho Park Nov 16 '19 at 17:00
  • I suppose that I need to just read the Siemens documentation to see if it is compliant with the IEC standards. Thanks for the tips on OPTO22 and your other Python code. Your code is doing OPC DA though? – TexasEngineer Nov 22 '19 at 16:19