⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionpoint.cpp

📁 一个OPC客户端监视程序
💻 CPP
字号:
//**************************************************************************
//
//  Description:  Callback class for OPC Data Access 2.0
//
//**************************************************************************
#include "stdafx.h"
#include "OPCClientSpy.h"
#include "ConnectionPoint.h"
#include "IAdvSink.hpp"
#include "ValueMsgView.h"

extern CValueMsgView *theMsgValue;

CComModule _Module;  // just needed to keep ATL happy

//**************************************************************************
// Called by the server at the update rate when data changes
STDMETHODIMP OPCCallback::OnDataChange(
                                    DWORD       Transid,
                                    OPCHANDLE   grphandle,
                                    HRESULT     masterquality,
                                    HRESULT     mastererror,
                                    DWORD       count,
                                    OPCHANDLE * clienthandles,
                                    VARIANT   * values,
                                    WORD      * quality,
                                    FILETIME  * time,
                                    HRESULT   * errors)
{
   // If Transid != 0, this is a refresh
   for( DWORD index=0; index<count; index++ )
   {
      if( SUCCEEDED(errors[index]) )
      {
         Item* pItem = (Item*)clienthandles[index];
         if( pItem )
         {
            pItem->value = values[index];
            pItem->quality = quality[index];
            pItem->timestamp = time[index];
         }
      }
   }
   PostMessage(*theMsgValue, WM_OPCDATA, 0, 0);
   return S_OK;
}

//**************************************************************************
// Called by the server to complete an ASyncIO2::Read
STDMETHODIMP OPCCallback::OnReadComplete(
                                    DWORD       Transid,
                                    OPCHANDLE   grphandle,
                                    HRESULT     masterquality,
                                    HRESULT     mastererror,
                                    DWORD       count,
                                    OPCHANDLE * clienthandles,
                                    VARIANT   * values,
                                    WORD      * quality,
                                    FILETIME  * time,
                                    HRESULT   * errors)
{
   ASSERT( Transid == 3 ); // test only
   for( DWORD index=0; index<count; index++ )
   {
      if( SUCCEEDED(errors[index]) )
      {
         Item* pItem = (Item*)clienthandles[index];
         if( pItem )
         {
            pItem->value = values[index];
            pItem->quality = quality[index];
            pItem->timestamp = time[index];
         }
      }
   }
   PostMessage(*theMsgValue, WM_OPCDATA, 0, 0);
   return S_OK;
}


//**************************************************************************
// Called by the server to complete an ASyncIO2::Write
STDMETHODIMP OPCCallback::OnWriteComplete(
                                    DWORD       Transid,
                                    OPCHANDLE   grphandle,
                                    HRESULT     mastererr,
                                    DWORD       count,
                                    OPCHANDLE * clienthandles,
                                    HRESULT   * errors)
{
   ASSERT( Transid == 2 ); // test only
   for( DWORD index=0; index<count; index++ )
   {
      if( FAILED(errors[index]) )
      {
         Item* pItem = (Item*)clienthandles[index];
         PostMessage(*theMsgValue, WM_OPCWRITE, errors[index], 0);
      }
   }
   return S_OK;
}


//**************************************************************************
// Called by the server to complete an ASyncIO2::Cancel
STDMETHODIMP OPCCallback::OnCancelComplete(
                                    DWORD       transid,
                                    OPCHANDLE   grphandle)
{
   return S_OK;
}

//**************************************************************************
// Called by 2.0 servers when shutting down.
STDMETHODIMP OPCShutdown::ShutdownRequest(LPCWSTR szReason)
{
   reason = szReason;
   PostMessage(*theMsgValue, WM_OPCSHUTDOWN, (WPARAM)reason.GetBuffer(0), 0);
   return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -