PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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, ...).
See the following site for more details: http://www.opcfoundation.org/
WINDEV allows you to access the data via Automation or Active X (OPC DA Auto 2.0 specification).
Therefore, the use of OPC in WINDEV is performed via an Automation object or via an ActiveX that is used as OPC client layer. In most cases, this Automation object or this ActiveX is supplied by the electronic hardware vendor.
The operating mode of OPC with WINDEV is using the same programming principles as the Automation objects and ActiveX.
Note: 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. See the help about the Automation objects for more details.
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 code line:
AutomationParameter(apArrayBaseSubscript, 1)
See the help about AutomationParameter for more details.
2. In most cases, passing simple parameters (integer, string, ...) by address is not accepted.
In WINDEV, passing parameter by address 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 arrays in input must be passed by value (by enclosing the parameter between brackets)
  • The arrays in output must necessarily be created with a size set to 0 and passed by address.
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 sub-key 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 sub-keys 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 requested OPC client: for example, "Siemens OPC DAAutomation 2.0" or "Matrikon OPC Automation 2.0".
  4. Double-click the tree row to display the description: a new window is opened with a tree on the left and text on the right.
  5. Copy all the 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 supplied 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.
Minimum required version
  • Version 9
Comments
Click [Add] to post a comment