Skip to content
Advertisement

How to write an array tag in a VARIANT structure on an OpenOPC server

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 write in an array tag. The developper of the OpenOPC library (Barry Barnreiter) recommand to use a VARIANT variable because OPC “expect to see a Windows VARIANT structure when writing complex objects such as arrays”.

  • I did install Pywin32 (build 217) as suggested here.
  • I tried to send a simple integer instead of an array in a VARIANT structure.

Here’s the code:

JavaScript

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

JavaScript

Here’s the entire traceback:

JavaScript

And here’s the configuration of the computer:

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

Advertisement

Answer

You have to change your line opc_local = OpenOPC.open_client() for opc_local = OpenOPC.client(). This will make you connect directly to the OPC server, as opposed to using the OpenOPC Gateway Service.

The VARIANT structure is not included inside the Gateway Service exe. Note that the Gateway Service exe is it’s own frozen Python distribution. Thus it only includes the Python modules inside it that it needs to run and nothing else. So by avoiding using the Gateway Service you should not have this problem since you’ll be executing your code entirely using the Python distribution that you installed yourself on your PC.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement