logo资料库

wtopcsvr.dll使用手册.doc

第1页 / 共20页
第2页 / 共20页
第3页 / 共20页
第4页 / 共20页
第5页 / 共20页
第6页 / 共20页
第7页 / 共20页
第8页 / 共20页
资料共20页,剩余部分请下载后查看
WTOPCSvr DLL User’s Guide
Creating a Custom OPC Server using WTOPCSvr.DLL
Installing the OPC Proxy DLL’s
Link WTOPCSvr.lib with the Application
Generate a new CLSID
Registry Entries
Initialization of WTOPCSvr.DLL
Creating Process Tags
Dynamic Tag Creation
Write Callback Notification
Clean-up Functions
Performance Related Functions
OPC Alarms & Events
NT Security Additions
WTOPCSvr.DLL Exported functions
Initialization and Registry Functions
WTSvrTest MFC Example
WTSvrTst2 MFC Example
WTOPCSvr DLL User’s Guide The WinTECH Software Rapid Development DLL for OPC Servers, (WTOPCSvr), provides an easy to use API for integrating custom data with OPC. All the details of COM and OPC are handled by the DLL, which allows an application to present data points to OPC at a high-level, 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. WTOPCSvr basically operates as a data librarian. The controlling application creates Process Tags by passing a name and value to the DLL. The DLL records the data point and makes it available to any OPC Client application by name. The controlling application may change the value of the data at any time, and all attached clients would be automatically notified. Callback notification is provided for any Process Tag that is modified by an OPC Client connection. (The application has control over which tags are OPC_WRITEABLE.) WTOPCSvr now supports dynamic creation of OPC Tags. A callback function is supplied which returns control to the application if a client requests a tag that has not been previously defined. The application may in turn create the tag using the requested path and name combination or ignore the request.
Creating a Custom OPC Server using WTOPCSvr.DLL Installing the OPC Proxy DLL’s The first step in creating an OPC Server is to obtain and install the OPC Proxy/Stub DLL’s from OPCFoundation (http://www.opcfoundation.org)  Download and upzip the proxy/stub files.  Copy opccomn_ps.dll, opcproxy.dll, opcae_ps.dll, opchda_ps.dll to the SYSTEM32 Directory. *Be sure not to overwrite any newer versions* Type REGSVR32 opccomn_ps.dll Type REGSVR32 opcproxy.dll Type REGSVR32 opc_aeps.dll Type REGSVR32 opchda_ps.dll     You will also need to download and install the OPC Server Browser Object supplied by the OPC Foundation. The OPC Foundation also advises that you verify that your system contains the actxprxy.dll and if not, install the ActiveX Redistributable Installation Kit from Microsoft. The aprxdist.zip file containing the Microsoft software is also available from the OPC Foundation Web-Site. Link WTOPCSvr.lib with the Application WTOPCSvr.lib contains the export definitions for the DLL’s API. Include this file with the project files for the custom application and include WTOPCSvrAPI.h with those modules which will be making calls into the DLL. Generate a new CLSID Each OPC Server is identified by a unique CLSID. The GUIDGen.exe utility supplied by Microsoft may be used to generate a unique identifier for the new server application. Run GUIDGen.exe, (located in the Visual C++\Bin directory). Generate a new CLSID and copy to the clipboard to be pasted in to your server application as described below.
Registry Entries The WTOPCSvr.DLL exports two API functions that make modifications to the Windows Registry for installation of the custom server. UpdateRegistry (BYTE *pCLSID_Svr, LPCSTR Name, LPCSTR Descr, LPCSTR ExePath); UnregisterServer (BYTE *pCLSID_Svr, LPCSTR Name); These functions take as arguments the CLSID generated above, (as well as text strings to identify and describe the new server). While the UpdateRegistry and UnregisterServer functions may be called from the controlling application at any time, it is generally preferred to implement the registry functions based on command-line entries during start-up of the application. A self-registering server would process the \RegServer and \UnregServer command line options similar to the code below, (extracted from OPCSimSvr Application): const GUID CLSID_OPCSimSvr = {0x99b8f471, 0xc027, 0x11d2, {0x80, 0xb8, 0x0, 0x60, 0x97, 0x58, 0x58, 0xbe}}; BOOL COPCSimSvrApp::InitInstance() { TCHAR szTokens[] = _T("-/ "); CString HelpPath; CString SvrName, SvrDescrip; int i; HelpPath = AfxGetApp()->m_pszHelpFilePath; i = HelpPath.ReverseFind('\\'); HelpPath = HelpPath.Left(i+1); HelpPath += "OPCSIMSVR.EXE"; // // Self-Registration code // (look for cmdline options to register & unregister server) // SvrName = "WinTECH.OPCServer"; SvrDescrip = "WinTECH Software OPC Server Simulator"; CString tempCmdLine(m_lpCmdLine); LPTSTR lpszToken = _tcstok(tempCmdLine.GetBuffer(1), szTokens); while (lpszToken != NULL) { if (_tcsicmp(lpszToken, _T("UnregServer"))==0) { UnregisterServer ((BYTE *)&CLSID_OPCSimSvr, SvrName); return (FALSE); } else if (_tcsicmp(lpszToken, _T("RegServer"))==0) { UpdateRegistry ((BYTE *)&CLSID_OPCSimSvr, SvrName, SvrDescrip, HelpPath); return (FALSE); } lpszToken = _tcstok(NULL, szTokens); }
Initialization of WTOPCSvr.DLL The Windows Registration functions described above may be called prior to the initialization of the WTOPCSvr.DLL. During the self-registration process, the focus is on making the necessary changes to the Registry and then exiting the application. There is no need at this point to go through the effort of initializing DCOM and loading up the OPC Server support. The exported function: InitWTOPCsvr (BYTE *pCLSID_Svr, UINT ServerRate); does just that. When this function is executed, the DLL performs all necessary initialization of COM/DCOM and creates the OPCServer Interface object to be used for client connections. The specified ServerRate defines how fast the OPC Client data connections are refreshed. Creating Process Tags After initialization, the WTOPCSvr.DLL is now ready to accept data points from the custom application. Three exported functions are provided: CreateTag (LPCSTR Name, VARIANT Value, WORD InitialQuality, BOOL IsWriteable); UpdateTag (HANDLE TagHandle, VARIANT Value, WORD Quality); UpdateTagByName (LPCSTR Name, VARIANT Value, WORD Quality); SetWtOPCsvrQualifier (char Delimiter); As each process tag is created, the DLL returns a HANDLE to identify the point for future references, (updates), from the application. The naming convention used by WTOPCSvr.DLL for browsing operations, (OPC_NS_FLAT or OPC_NS_HIERARCHIAL), is a function of how the names are assigned by the controlling application. If segmented names are used to create the tags, (strings containing the delimiter ‘.’, such as “PLANT A.PROCESS1.TAG17”), WTOPCsvr.DLL will automatically configure the name space as hierarchial, otherwise a flat name space is used. If you want to use a delimiting character other than ‘.’, you can select it using SetWtOPCsvrQualifier(). Dynamic Tag Creation If the design warrants, WTOPCSvr.DLL may be used to provide for dynamic creation of OPC Tags as requested by attached clients. Rather than create all the OPC Tags up-front, the application may choose to have the DLL issue a callback function whenever an OPC Client requests a tag name that is not already listed. EnableUnknownItemNotification (UNKNOWNITEMPROC lpCallback); If enabled, the callback function will receive control anytime a client requests a tag that has not been previously defined. The requested tag name and path may then be used as arguments to CreateTagA() to dynamically create the tag before returning from the callback and giving control back to the client. If the application chooses to ignore the request, the client will receive a OPC_E_UNKNOWNITEMID response from the DLL. WTOPCSvr.DLL also supports a user callback function that indicates when the last client reference to a tag has been removed. This may be used by the server application to delete the tag when it is no longer needed. The following exported function enables this functionality: EnableItemRemovalNotification (ITEMREMOVEDPROC lpCallback);
The callback will receive the handle to the removed item, as well as the path and item names. Write Callback Notification If process tags are created as OPC_WRITEABLE, attached client applications may change the value of data points contained within WTOPCSvr.DLL. WTOPCSvr.DLL provides the ability for the controlling application to define a callback routine for notification of client writes. This would be required in most situations to allow the server application to accept the new value and perform the write to the actual device. EnableWriteNotification (WRITENOTIFYPROC lpCallback); If enabled, the callback function will receive the HANDLE of any data point written by an attached OPC Client, as well as the value to be written and a pointer to an error DWORD to allow feedback to the client if the write operation fails Clean-up Functions The only remaining functions exported from WTOPCSvr.DLL provide the mechanism for gracefully closing the custom server. int NumbrClientConnections (); void RequestDisconnect (); RemoveTag (HANDLE TagHandle); UninitWTOPCsvr(); Generally, the server logic should check to see if any OPC Clients are connected before allowing the application to close. OPC 2.0 clients may be requested to disconnect. Any tags created by the application should be removed using the defined function. The UnintWTOPCsvr() function calls CoUnitialize and should be placed in the ExitInstance procedure of the application. Performance Related Functions Beginning with version 4.0 of the WtOPCsvr.dll, there have been several extended API functions added to support more efficient updating for large item counts. The dll now supports an option to use hashing for storage and lookup of text strings representing item names. Significant performance gains are provided in the areas of intensive string manipulation such as the item browsing functions. A second series of API functions improves upon the data update cycle by updating multiple items with a single command rather than one at a time. The WtSvrTst2 example application that is packaged with the WtOPCsvr.dll may be used to generate performance numbers using various tag counts and various combinations of these two options. Refer to the API descriptions below for detailed information relative to the use of these functions.
OPC Alarms & Events The WtOPCsvr.dll provides basic support for the Alarms & Events standard by providing level checking for each process tag. The dll will automatically create an OPC A&E Server using the same CLSID as the Data Access Server. As each tag is created, the controlling application may specify two levels of high and low alarm limits surrounding it’s value. As a tag’s value is updated, either by the controlling application or by an attached client, the dll will check its value against these limits and generate the appropriate A&E messages if exceeded. These messages are accessible from any standard OPC A&E client application. WtOPCsvr.dll also exports functions that allow the controlling application to generate textual events to any interested client. Finally, if greater control over A&E Server operation is desired, the application may disable the internal limit checking and process all the A&E Interface calls from a client directly. A simple callback object is provided that may be overridden by the application to process the individual A&E Interfaces as required. NT Security Additions To accommodate OPC Server designs where it is desired to control access to certain tags based on the identity of the connected user, WtOPCsvr.dll supports api functions that allow a security mask to be applied for both read and write access to individual tags. The user may then define a list of user names with specific rights. When the security option is enabled, WtOPCsvr.dll will verify the access rights of the client against the sever defined user list and allow or deny access accordingly. Additionally, an extended write callback is provided that contains the user name of the client making a write requiest for a tag. This information may then be used to maintain an audit trail of users who have updated a particular tag.
WTOPCSvr.DLL Exported functions Initialization and Registry Functions BOOL InitWTOPCsvr (BYTE *pCLSID_Svr, UINT ServerRate); Use this function to initialize DCOM and create the OPC Server. CLSID_Svr defines the CLSID which OPC Clients will use to connect to this server. ServerRate is expressed in msecs and defines the rate at which client connections are updated. The return value will be TRUE if the function succeeds, otherwise FALSE. BOOL UpdateRegistry (BYTE *pCLSID_Svr, LPCSTR Name, LPCSTR Descr, LPCSTR ExePath); This function makes modifications to the Windows Registry to allow other applications to find and execute the server. CLSID_Svr defines the CLSID which OPC Clients will use to connect to this server, (this is a BYTE Pointer to the C-style GUID structure). Name defines the Server Name Descr may be anything to describe the server, and will usually contain the vendor name. ExePath defines the full Windows Directory path to the executable (i.e. c:\OPC\test\mysvr.exe). The return value will be TRUE if the function succeeds, otherwise FALSE. BOOL AddLocalServiceKeysToRegistry (LPCSTR Name); This function makes additional modifications to the Windows Registry to allow the server to run as an NT Service. Name defines the Server Name BOOL UnregisterServer (BYTE *pCLSID_Svr, LPCSTR Name); This function removes entries from the Windows Registry. CLSID_Svr defines the CLSID which OPC Clients will use to connect to this server. Name defines the Server Name The return value will be TRUE if the function succeeds, otherwise FALSE.
Tag Creation & Update Functions HANDLE CreateTag (LPCSTR Name, VARIANT Value, WORD InitialQuality, BOOL IsWriteable); This function creates a process tag within WTOPCSvr.DLL. Name defines the identifier that OPC Clients will use to access the tag. This name may be any string of text as required by the server. Segmented names, (those containing the delimiter character ‘.’), are valid and will cause WTOPCSvr.DLL to structure the OPC name space as hierarchial, for browsing operations. Value defines the initial data to be associated with the tag InitialQuality defines the OPC Quality flags associated with the tag. IsWriteable determines whether or not the tag may be written from an OPC Client The return value will be a HANDLE to the created point or INVALID_HANDLE_VALUE if the tag could not be created. BOOL SetTagProperties (HANDLE TagHandle, DWORD PropertyID, LPCSTR Description, VARIANT Value); Any number of OPC Item properties may be set for a defined tag with this function. The DLL maintains a list of all defined properties and their current value for access by an OPC Client. The return value will be TRUE if the function succeeds, otherwise FALSE. BOOL UpdateTag (HANDLE TagHandle, VARIANT Value, WORD Quality); BOOL UpdateTagWithTimeStamp (HANDLE TagHandle, VARIANT Value, WORD Quality, FILETIME timestamp); This function allows the controlling application to change the value, quality flag, and timetstammp of a defined process tag. If the timestamp is not supplied by the application, the dll will use the current PC time setting. TagHandle defines the point. Value defines the new data. Quality defines the new Quality condition The return value will be TRUE if the function succeeds, otherwise FALSE. BOOL UpdateTagByName (LPCSTR Name, VARIANT Value, WORD Quality); This function also allows the controlling application to change the value and quality flags of a defined process tag. Name defines the point. Value defines the new data. Quality defines the new Quality condition The return value will be TRUE if the function succeeds, otherwise FALSE.
分享到:
收藏