OpenOPC VARIANT structure

  opc, python, python-2.7, server, variant

I’m trying to communicate with an OPC DA server and need to write in a tag which is in an array format. We can connect with a simulation server, read tags (int, real, array) and write tags (int, real, str). The problem comes when we need to use a VARIANT structure to send an array.

Here’s the code:

from win32com.client import VARIANT
import pythoncom
import OpenOPC
opc_local = OpenOPC.open_client()
opc_local.connect('Matrikon.OPC.Simulation','localhost')
values = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
w = opc_local.write(('Bucket Brigade.ArrayOfReal8', values))
print(w)

And here’s the error that we get when the line with opc_local.write gets executed:

AttributeError: 'module' object has no attribute 'VARIANT'

Here’s the configuration of the computer:

  • Windows 10
  • Python 2.7
  • Pyro 3.16
  • Pywin32 Build 223
  • OpenOPC 1.3.1 win32-py27

Source: Python Questions

LEAVE A COMMENT