ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / OLE functions
  • Overview
  • Automation programming for OPC
  • Overview
  • Defining the name of the OPC server to use
  • Specific features of Automation programming for OPC
  • Limitations of WLanguage
  • Errors returned by Automation server
  • Automation interfaces for the Asynchronous mode
  • Notes
  • Example
  • Dialog with an OPC UA server
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
OPC stands for "OLE for Process Control".
OPC is a standard implementation based on OLE/COM for managing the physical devices (automaton, alarms, captors, ...).
For more information, visit: http://www.opcfoundation.org/
WINDEV allows access to data:
  • via Automation.
  • via ActiveX (OPC DA Auto 2.0 specification).
  • via an OPC UA server.
Therefore, the use of OPC in WINDEV is performed via an Automation object or via an ActiveX that is used as OPC client library. In most cases, this Automation object or this ActiveX is supplied by the electronic hardware vendor.
Using OPC with WINDEV follows the same programming principles as Automation objects and ActiveX.
Remark: In the rest of this document, the Automation objects and the ActiveX will be called "Automation objects".
Automation programming for OPC

Overview

The programming of Automation objects for OPC in WLanguage corresponds to the programming of Automation objects. For more information, see the help on Automation objects.
However, some constraints are linked to the OPC standard and to the internal implementation of the Automation objects.

Defining the name of the OPC server to use

To use the automation syntax, you must know the name of the OPC server. his name is specific to each manufacturer of OPC hardware.
This name can be found automatically. To get this information, contact the manufacturer of the OPC server.

Specific features of Automation programming for OPC

1. The subscripts of arrays start from 1
The source subscript of the arrays must be forced at the beginning of the initialization code of the project by the following line of code:
AutomationParameter(apArrayBaseIndex, 1)
For more details, see the help about AutomationParameter.
2. In most cases, passing simple parameters (integer, string, etc.) by reference is not accepted.
In WINDEV, passing parameters by reference is the default mode. Passing the variables by value must be forced by enclosing each parameter between brackets. For example:
oServer>>Connect((sOPCServer),(sComputerName))
3. Managing arrays:
  • The input arrays must be passed by value (by enclosing the parameter between brackets)
  • The output arrays must necessarily be created with a size set to 0 and passed by reference.
Example:
nArrServerHandle is array of 1 int  // input
nArrValue is array of 0 Variant // output
nArrOutputError is array of 0 int // output
...
oGroup>>SyncRead(2,1,(nArrServerHandle),vArrValue,nArrError)
4. For the asynchronous mode (callback of WLanguage procedure by the Automation object), the Automation objects that are provided propose interfaces without description. Therefore, you must use the first syntax of AutomationEvent.

Limitations of WLanguage

In asynchronous mode, to handle an array of values, the array cells must be handled one by one. This feature is not available in this version.

Errors returned by Automation server

The information found in the errors is directly returned by the Automation objects.
Therefore, the lack of information comes from the implementation of the OPC Automation object.
We cannot document all the error cases for all the manufacturers.

Automation interfaces for the Asynchronous mode

1. Determination by the registry
The automation interfaces for the asynchronous mode can be found in the registry on a computer where the Automation object to use was installed.
To find the event interface of the OPC server, search for "DIOPCServerEvent" in the data. The key containing this value is the key to use.
To find the event interface of the OPC group, search for "DIOPCGroupEvent" in the data. The key containing this value is the key to use.
To find the event interface of all the OPC groups, search for "DIOPCGroupsEvent" in the data. The key containing this value is the key to use.
If several values are found, it means that several OPC Automation objects are installed on the computer:
  • the TypeLib subkey has a value in the following format (by default): {01704EB3-44B5-11D3-9C09-00105A3DD3AC} that corresponds to the identifier of the Automation object
  • perform a key search of the value found {01704EB3-44B5-11D3-9C09-00105A3DD3AC}
  • this key has subkeys like "1.0" or "2.0" that give the name of the OPC Automation object that provides the interface
2. Determination by OLEView
"OLE View" is a tool supplied with MS Visual Studio.
  1. Start OLE View.
  2. In the treeview on the left, open the "Type Libraries" branch.
  3. Find the desired OPC client: for example, "Siemens OPC DAAutomation 2.0" or "Matrikon OPC Automation 2.0".
  4. Double-click the tree row to open the description: a new window is opened with a tree on the left and text on the right.
  5. Copy the entire text into a text editor.
To find the interface of events for the OPC group, search for "dispinterface DIOPCGroupEvent" in order to find a block such as:
[
uuid(F8582D2B-88FB-11D0-B850-00C0F0104305),
helpstring("OPC Group Events"),
nonextensible
]
dispinterface DIOPCGroupEvent {
properties:
methods:
[id(0x00000001)]
void DataChange(
[in] long TransactionID,
[in] long NumItems,
[in] SAFEARRAY(long)* ClientHandles,
[in] SAFEARRAY(VARIANT)* ItemValues,
[in] SAFEARRAY(long)* Qualities,
[in] SAFEARRAY(DATE)* TimeStamps);
[id(0x00000002)]
void AsyncReadComplete(
[in] long TransactionID,
[in] long NumItems,
[in] SAFEARRAY(long)* ClientHandles,
[in] SAFEARRAY(VARIANT)* ItemValues,
[in] SAFEARRAY(long)* Qualities,
[in] SAFEARRAY(DATE)* TimeStamps,
[in] SAFEARRAY(long)* Errors);
[id(0x00000003)]
void AsyncWriteComplete(
[in] long TransactionID,
[in] long NumItems,
[in] SAFEARRAY(long)* ClientHandles,
[in] SAFEARRAY(long)* Errors);
[id(0x00000004)]
void AsyncCancelComplete([in] long CancelID);
};
The interface is given at the beginning of the block: here {F8582D2B-88FB-11D0-B850-00C0F0104305}.
The event number is given for each event: here, id(0x00000001) for the DataChange event.
To find the interface of events for the OPC server, search for "dispinterface DIOPCServerEvent" in order to find a block such as:
[
uuid(F8582D26-88FB-11D0-B850-00C0F0104305),
helpstring("OPC Server Event"),
nonextensible
]
dispinterface DIOPCServerEvent {
properties:
methods:
[id(0x00000001)]
void ServerShutDown([in] BSTR Reason);
};
The interface is given at the beginning of the block: here { F8582D26-88FB-11D0-B850-00C0F0104305}.
The event number is given for each event: here, id(0x00000001) for the ServerShutDown event.

Notes

  • WINDEV supports the OPC Client features for accessing data.
  • WINDEV supports the DA Auto 2.0 specification (access to data via Automation interface).
  • WINDEV does not support the arrays of values in asynchronous mode. If the array has a small size, an OPC element can be defined for each array value.

Example

WINDEV is provided with an example for OPC management. This example cannot be used as it is. It must be adapted to your OPC server.
Related Examples:
WD OPC Training (WINDEV): WD OPC
[ + ] This example presents the implementation of the OPC protocol in WINDEV.
OPC means OLE for Process Control.
It's a standard implementation based on OLE/COM for managing physical devices (robots, alarms, captors, ...).
For more details, see the WINDEV help or the following site: http://www.opcfoundation.org/
WINDEV allows for data access through Automation or ActiveX (OPC DA Auto 2.0 specification).
The use of OPC in WINDEV requires the use of an Automation object or of an ActiveX that serves as an OPC client layer.
This Automation object or ActiveX is usually provided by the manufacturer of the device.
Therefore, OPC in WINDEV is implemented using the basic principle of object automation and ActiveX.
Dialog with an OPC UA server
WINDEV allows you to connect to an OPC UA server. For more details, see the example provided.
Related Examples:
WD OPC UA Training (WINDEV): WD OPC UA
[ + ] This example shows how to communicate with an OPC UA server.
Minimum version required
  • Version 9
Comments
Click [Add] to post a comment

Last update: 06/22/2023

Send a report | Local help