OPC Client Development Toolkit

* * * Affordable, Reliable, Guaranteed * * *

Using WinTECH Software's Rapid Client Development Toolkit, you can now include OPC functionality in your product in a fraction of the time it would normally take. API Calls into the Toolkit DLL present you with a list of available Servers and allow you to establish a connection. You may then create one or more OPC Groups and add items from a list presented from the connected server. You may also use the DLL to access Alarms & Events information in addition to Data Access. The complete API is listed below and the source code for several an example applications is included with the demo. The toolkit may be used with Visual Basic or C++.

The dll takes care of all the details necessary to interface to OPC Servers using either OPC 1.0 or OPC 2.0 Data Access Standards. All required OPC interfaces are supported by the dll, including the Browse functions. The demo version of the dll, (available below), allows you to create a complete working OPC Client solution for your custom application without cost or obligation. The API is fully documented and supported. After you have successfully integrated your application's data with the dll, and are satisfied that it works to your satisfaction, you may purchase a developer's license for the toolkit to remove the time limit. (The demo version of the dll will time-out after 30 minutes of operation.) The complete working source code for the dll is also available for those who want complete protection for their investment.

Why spend months of development time pouring over the OPC/DCOM specs before you begin developing? Why spend thousands more dollars to purchase a toolkit from one of the "Major Commercial Vendors"? We have over 20 years of software design experience in process-related industries. Our toolkits are robust, efficient, and field-proven in hundreds of locations through-out the world. Other vendors may sell toolkits that work equally as well, but there are none better, and certainly none as economical as those provided by WinTECH Software Design. Our Developer Toolkits are our main business. We were the first to provide fully functional, readily downloadable demos with an openly published API. This allows potential users to create and test server and client applications integrated with their own data without cost or obligation. Other vendors may sell their toolkits as a side-line and are often more interested in marketing their own OPC-based solutions than they are in supporting your development efforts. At WinTECH Software Design, your application is what's important to us. We stand behind the software with an unconditional guarantee. Technical support is without charge and licensed users have access to all future releases of the product. Please take the time to download and evaluate the demo toolkit(s) and if you have any comments or questions, please email us at: opc@win-tech.com

OPC Foundation Member

Download the Client Toolkit
WTclient.zip (133K)

WTclient User's Guide

The WinTECH Software Rapid Client Development DLL, (WTclient), provides an easy to use API for integrating a custom application with data from any OPC Server. All the details of DCOM and OPC are handled by the DLL, which allows an application to easily obtain data points from a Server, without having to be concerned with the actual implementation of the underlying interfaces. The DLL may be easily integrated with existing applications, or new ones. All required OPC Interfaces are supported for both OPC 1.0 and OPC 2.0 Data Access Standards as well as the Browse Interface. Support for Alarms & Events is also included.

Creating a Custom OPC Client using WTclient.DLL

Link WTclient.lib with the Application

WTclient.lib contains the export definitions for the DLLís API. Include this file with the project files for the custom application and include WTclientAPI.h with those modules which will be making calls into the DLL. If programming in Visual Basic, include the module1.bas from the VBA_example, (supplied with the demo), into your project.

Obtaining the List of OPC Servers

WTclient.dll exports two functions that allow the controlling application to obtain a list of available OPC Servers.

int NumberOfOPCServers (BOOL UseOPCENUM, LPCSTR MachineName);
BOOL GetServerName (int index, LPSTR Buffer, int BufSize);

OPCENUM is a component supplied by the OPC Foundation to allow prospective client applications to obtain a list of available servers on the local or remote machine. Unfortunately, at the time of this writing, the operation of OPCENUM is not consistant across all platforms. WTclient.dll allows the application to attempt to use the OPCENUM component to obtain the list of Servers, or to bypass OPCENUM and obtain the list by scanning the local copy of the Windows Registry. If OPCENUM is used, you can pass the name of a remote machine to obtain the remote server list.

Once the number of servers has been returned from WTclient.dll, the application can iterate through the list of names by calling:

BOOL GetServerName (int index, LPSTR Buffer, int BufSize);

A user supplied character buffer receives a name from the Server list as identified by a passed index. BufSize identifies the length of the user supplied character buffer and prevents the dll from loading a name that's too long. GetServerName returns TRUE if a valid Server name is returned in Buffer, otherwise the return value is FALSE.

Establishing an OPC Connection

HANDLE ConnectOPC(LPCSTR MachineName, LPCSTR ServerName, BOOL EnableDLLBuffering);

This function returns a valid HANDLE if a connection could be established to the OPC Server defined by MachineName and ServerName. Multiple simultaneous connections to different servers may be established, and the returned HANDLE identifies the connection for future calls to create groups and items. Passing a Null String as the MachineName parameter identifies the local machine. WTclient will attempt the connection using the OPC 2.0 ConnectionPoint Interface. If not available, it will revert the the OPC 1.0 DataObject Interface.

WTclient.dll operates in basically two modes. The first is used with those applications which support 'C-Style' callback functions. In this case, no buffering is performed inside the dll. As data change notifications are received from the connected OPC Server, callbacks are used to pass the new information to the controlling application, (refer to EnableOPCNotification below).

For those applications designed using tools which do not support callback functions, (such as Visual Basic 5.0), WTclient may be configured to maintain a list of all OPC Items, (Tags), created by the application. As data from the Server changes, the corresponding tag value in the dll's list will be updated. The controlling application may read the value of a tag at any time, (refer to ReadOPCItem below).

void PASCAL FAR DisconnectOPC(HANDLE hConnect);

When an application terminates, it is responsible for disconnecting from an attached Server. The DisconnectOPC() function will provide a clean shutdown of the connection defined by hConnect.

Obtaining a list of Server Tag Names

BOOL SetBrowseFilters (HANDLE hConnect, LPCSTR UserString, VARTYPE DataType, DWORD AccessType);
int NumberOfOPCItems(HANDLE hConnect);
BOOL GetOPCItemName (HANDLE hConnect, int index, char *pBuf, int BufSize);

These two functions operate similarly to those which allow you to obtain the list of Server names. NumberOfOPCItems() returns the total number of unique tags supported by a connected OPC Server. Incrementally calling GetOPCItemName will step through all the available tag names to allow the controlling application to select an item or present a Browse list to the user. Use SetBrowseFilters if you want to restrict the list of item names to those of a certain type.

BOOL BrowseTo (HANDLE hConnect, LPCSTR NodeName);
int BrowseItems (HANDLE hConnect, WORD Filter);

The application may also browse item names directly from the connected server by using these functions. The BrowseTo function sets the current browse position and BrowseItems operates basically as descibed above returning the number of item names that may be retrieved using the OPCItemName().

Creating OPC Groups and Tags

HANDLE AddOPCGroup (HANDLE hConnect, LPCSTR Name, DWORD *pRate, float *pDeadBand);
void RemoveOPCGroup (HANDLE hConnect, HANDLE hGroup);

WTclient.dll exports two functions which allow you to create and remove an OPC Group. The AddOPCGroup() function returns a handle to uniquely identify the group, and must be supplied to other Wtclient functions to reference tags, etc. The values passed to AddOPCGroup as parameters are determined by the controlling application and are specific to each Group. The name is arbitrary and not used by the Server. pRate is a pointer to the desired refresh rate, (in milliseconds), that the server uses to provide updates back to the client. The actual rate is returned from the server in pRate.

HANDLE AddOPCItem (HANDLE hConnect, HANDLE hGroup, LPCSTR ItemName);
BOOL SetItemUpdateHandle (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, HANDLE hUpdate);
void RemoveOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem);

To add an item to a defined OPC Group, simply call the AddOPCItem function with the group's handle and the tag name of the desired item. A handle value will be returned to uniquely define the item, (INVALID_HANDLE_VALUE will be returned if the requested item does not exist). SetItemUpdateHandle allows the client application to set the handle of the item as returned in the data update callback. This provides a mechanism for more efficient lookup for the item. Call RemoveOPCItem to clean-up allocated memory when closing a group.

Getting updated Tag Values from the Server

BOOL EnableOPCNotification (HANDLE hConnect, NOTIFYPROC lpCallback);

If your application supports callbacks, WTclient will issue the callback when notification from a connected Server indicates a change in the value of a Tag's data. The prototype for the callback is defined as follows:

void CALLBACK EXPORT OPCUpdateCallback (HANDLE hGroup, HANDLE hItem, VARIANT *pVar, FILETIME timestamp, DWORD quality)

The current value for a tag, timestamp and OPC Quality flags will be supplied to the application via the callback. The Tag is identified by the associated handles identifying the group and item.

BOOL ReadOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT *pVar, FILETIME *pTimeStamp, DWORD *pQuality);

If WTclient has been configured to maintain an internal buffer of tags, the controlling application may read the current value of a tag by using the ReadOPCItem function. If the requested item is not available, (or if DLLBuffering has not been selected), the function will return FALSE.

Writing Tag Values to the Server

BOOL WriteOPCItem (HANDLE hConnect, HANDLE hGroup, HANDLE hItem, VARIANT *pVar, BOOL DoAsync);

Writing new data to the connected Server is accomplished via the WriteOPCItem function. The identifying handles for the group and item must be supplied as well as the data to be written. The DoAsync parameter instructs the dll to perform an Asynchronous write to the Server.

Accessing OPC Item Properties

int NumberOfItemProperties (HANDLE hConnect, LPCSTR ItemName);
BOOL GetItemPropertyDescription (HANDLE hConnect, int PropertyIndex, DWORD *pPropertyID, VARTYPE *pVT, BYTE *pDescr, int BufSize);
BOOL ReadPropertyValue (HANDLE hConnect, LPCSTR Itemname, DWORD PropertyID, VARIANT *pValue);

These three functions allow the client application to read item properties from the server. NumberOfItemProperties fills an internal name array and the decription of each item property supported by the server is available by querying with GetItemPropertyDescription. The returned PropertyID may then be used to access the current value for the property directly from the server.

Functions supporting Alarms & Events

int NumberOfOPC_AEServers (LPCSTR MachineName);
BOOL GetOPC_AEServerName (int index, char *pBuf, int BufSize);
HANDLE ConnectOPC_AE(LPCSTR MachineName, LPCSTR ServerName);
void DisconnectOPC_AE(HANDLE hConnect);
BOOL Create_AE_Subscription (HANDLE hConnect, HANDLE SubscriptionHandle, DWORD *pBufferTime, DWORD *pMaxSize);
BOOL Enable_AE_Callback (lp_AECallback AEProc);

These six functions provide the client interface into an OPC Alarms & Events Server. The number of servers installed on the target machine may be obtained, selected, and a connection made using the defined procedures. Creating a subscription and providing a callback procedure will enable event messages to be received by the application as they occur within the server.

Last Updated: June 6, 2001
Copyright © 2000, WinTECH Software Design
Return to WinTECH Automation Apps..