📄 group.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
//
// OPC Trend VC++ Client: Group.CPP
// (Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
// Author: Raphael Imhof
// Initial Date: 11/04/98
// $Workfile: Group.cpp $
// $Revision: 1 $
// $Date: 7/27/99 5:24p $
// Target System: Microsoft Windows NT 4.0
// Environment: Visual C++ 5.0 / OPC DataAccess 1.0 / 2.0
// Remarks:
//
/////////////////////////////////////////////////////////////////////////////
//
// Description: implementation of the CGroup class.
// Encapsulation of group related methods.
//
//
/////////////////////////////////////////////////////////////////////////////
//
// History of Changes (Please remove very old comments and blank lines!)
// $Log: /IDK/OPCServer/clients/VC++/Trend/Group.cpp $
//
// 1 7/27/99 5:24p Imhof
//
// 1 7/27/99 5:19p Imhof
//
// 5 1/15/99 7:04p Imhof
// Updated legal notice.
//
// 4 12/15/98 10:30a Imhof
// Modifications for OPC 2.0
//
// 3 11/06/98 5:53p Imhof
// Added header, comment and made some small code changes.
//
//
// $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC. MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND WITH RESPECT TO THE VALIDTY OF THE
// CODES OR DESIRED RESULTS AND DISCLAIMS ALL SUCH
// REPRESENTATIONS AND WARRANTIES, INCLUDING FOR EXAMPLE,
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE. SIEMENS BUILIDNG TECHNOLOGIES, INC. DOES NOT
// REPRESENT OR WARRANT THAT THE FOLLOWING CODE SAMPLES ARE
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Group.h"
#include "IOPCItemMgt.h"
#include "IOPCSyncIO.h"
/*
no async trend read support
#include "IOPCSyncIO.h"
*/
#include "AddItemDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNCREATE(CGroup, CObject)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGroup::CGroup()
{
m_dwOPCSTMFormatDataTimeConnection = 0;
m_pInfoServer = NULL;
m_Items.RemoveAll();
}
CGroup::~CGroup()
{
//should be already done => size = 0 !
int size = m_Items.GetSize();
CItem* pItem = NULL;
for (int i = 0; i < size; i++)
{
pItem = m_Items[0];
RemoveItem(&pItem);
}
}
BOOL CGroup::AddItem(CItem** item)
{
HRESULT res;
CAddItemDlg dlg;
USES_CONVERSION;
if(IDOK != dlg.DoModal()) return FALSE;
CIOPCItemMgt opcItemMgt(GetInterface());
OPCITEMRESULT* pAddResults = NULL;
HRESULT* pErrors = NULL;
OPCHANDLE hItem;
CItem* new_item = new CItem;
const unsigned short usItems = 1;
OPCITEMDEF add_items[usItems];
add_items[0].szItemID = A2OLE(dlg.m_sItemTag);
add_items[0].szAccessPath = A2OLE("");
add_items[0].bActive = TRUE;
add_items[0].hClient = (OPCHANDLE)new_item;
add_items[0].dwBlobSize = 0;
add_items[0].pBlob = NULL;
add_items[0].vtRequestedDataType = VT_R4;
res = opcItemMgt.AddItems(usItems, add_items, &pAddResults, &pErrors);
if(SUCCEEDED(res))
{
new_item->SetName(dlg.m_sItemTag);
hItem = pAddResults->hServer;
new_item->SetHandle(hItem);
new_item->SetDataType(pAddResults->vtCanonicalDataType);
new_item->SetGroup(this);
CoTaskMemFree(pAddResults);
CoTaskMemFree(pErrors);
*item = new_item;
m_Items.Add(new_item);
return TRUE;
}
else
{
GetInfoServer()->DisplayError(res);
delete new_item;
return FALSE;
}
}
BOOL CGroup::AddItem(CItem** item, CString sItemName)
{
HRESULT res;
USES_CONVERSION;
CIOPCItemMgt opcItemMgt(GetInterface());
OPCITEMRESULT* pAddResults = NULL;
HRESULT* pErrors = NULL;
OPCHANDLE hItem;
CItem* new_item = new CItem;
const unsigned short usItems = 1;
OPCITEMDEF add_items[usItems];
add_items[0].szItemID = A2OLE(sItemName);
add_items[0].szAccessPath = A2OLE("");
add_items[0].bActive = TRUE;
add_items[0].hClient = (OPCHANDLE)new_item;
add_items[0].dwBlobSize = 0;
add_items[0].pBlob = NULL;
add_items[0].vtRequestedDataType = VT_EMPTY; //native
res = opcItemMgt.AddItems(usItems, add_items, &pAddResults, &pErrors);
if(SUCCEEDED(res))
{
new_item->SetName(sItemName);
hItem = pAddResults->hServer;
new_item->SetHandle(hItem);
new_item->SetDataType(pAddResults->vtCanonicalDataType);
new_item->SetGroup(this);
CoTaskMemFree(pAddResults);
CoTaskMemFree(pErrors);
*item = new_item;
m_Items.Add(new_item);
return TRUE;
}
else
{
GetInfoServer()->DisplayError(res);
delete new_item;
return FALSE;
}
}
BOOL CGroup::RemoveItem(CItem** item)
{
HRESULT res;
HRESULT* pErrors = NULL;
CIOPCItemMgt opcItemMgt(GetInterface());
const unsigned short usItems = 1;
OPCHANDLE remove_items[usItems];
remove_items[0] = (*item)->GetHandle();
res = opcItemMgt.RemoveItems(usItems, remove_items, &pErrors);
if(SUCCEEDED(res))
{
CoTaskMemFree(pErrors);
for(int i = 0; i < m_Items.GetSize() ; i++)
{
if( *item == m_Items[i] )
{
m_Items.RemoveAt(i,1);
m_Items.FreeExtra();
delete *item;
}
}
return TRUE;
}
else
{
GetInfoServer()->DisplayError(res);
return FALSE;
}
}
unsigned int CGroup::GetItems(CArray<CItem*, CItem*>** items)
{
*items = &m_Items;
return((*items)->GetSize());
}
void CGroup::SetOPCSTMFormatDataTimeConnection(DWORD dwConnection)
{
m_dwOPCSTMFormatDataTimeConnection = dwConnection;
}
DWORD CGroup::GetOPCSTMFormatDataTimeConnection()
{
return m_dwOPCSTMFormatDataTimeConnection;
}
CInfoServer* CGroup::GetInfoServer()
{
return m_pInfoServer;
}
void CGroup::SetInfoServer(CInfoServer* pInfoServer)
{
m_pInfoServer = pInfoServer;
}
BOOL CGroup::Refresh(OPCDATASOURCE dwSource)
{
//value gets returned over the IAdvise sink
// not implemented for trend
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -