opc服务器消息通知代码,OPCClient浏览OPCServer的简单实例程序源代码.doc
OPCClient瀏覽OPCServer的簡單實(shí)例程序源代碼
OPC Client瀏覽OPC Server的簡單實(shí)例簡單程序//main.cpp
//************************************************************************************************
//瀏覽本地OPC服務(wù)器
//************************************************************************************************
#define _WIN32_DCOM // Needed in order to call CoInitializeEx()
#include
#include
#include
#import "C:\WINNT\system32\OpcEnum.exe" no_namespace//根據(jù)OpcEnum.exe更改
#include "opcda.h"
#include "opcenum_i.c"
//--------------------------------------------------------------------------------------------------------------
//版本號(hào)----可以從規(guī)范中查到
static const CLSID CATID_OPCDAServer10 =
{ 0x63d5f430, 0xcfe4, 0x11d1, { 0xb2, 0xc8, 0x0, 0x60, 0x8, 0x3b, 0xa1, 0xfb } };
// {63D5F430-CFE4-11d1-B2C8-0060083BA1FB}
static const CLSID CATID_OPCDAServer20 =
{ 0x63d5f432, 0xcfe4, 0x11d1, { 0xb2, 0xc8, 0x0, 0x60, 0x8, 0x3b, 0xa1, 0xfb } };
// {63D5F432-CFE4-11d1-B2C8-0060083BA1FB}
//[uuid(CC603642-66D7-48f1-B69A-B625E73652D7)] interface CATID_OPCDAServer30
//--------------------------------------------------------------------------------------------------------------
void OPCServerList();
int main(int argc, char* argv[])
{
HRESULT hr;
int n_return = 0;
try
{
// Initialize COM
if(
FAILED( hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) )
)
_com_issue_error(hr);
}
catch(_com_error e)
{
std::cout << "ERROR(" << e.Error() << "): ";
if( e.Description().length() > 0)
std::cout << (TCHAR*)e.Description() << std::endl;
else
std::cout << e.ErrorMessage() << std::endl;
n_return = 1;
}
OPCServerList();
// Uninitialize COM
CoUninitialize();
return 0;
}
//使用CoCreateInstance
void OPCServerList()
{
CLSID clsid;
clsid = CLSID_OpcServerList;//在opcenum_i.c中定義
IOPCServerList *gpOPC = NULL;
DWORD clsctx;
clsctx = CLSCTX_LOCAL_SERVER;//本地服務(wù)
IID IIDOPCServerList=IID_IOPCServerList;//在opcenum_i.c中定義
// 創(chuàng)建OPC服務(wù)器的瀏覽器對象-----
HRESULT hr = CoCr
總結(jié)
以上是生活随笔為你收集整理的opc服务器消息通知代码,OPCClient浏览OPCServer的简单实例程序源代码.doc的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux命令提示符不同,Linux命令
- 下一篇: stm32 HSE HSI