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

📄 item.cpp

📁 此文件为VC++开发环境下的OPC client trend 源代码
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
//  OPC Trend VC++ Client:	Item.CPP
//							(Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
//          Author: Raphael Imhof
//    Initial Date: 11/04/98
//       $Workfile: Item.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 CItem class.
//					Encapsulation of item related methods.
//					
//
/////////////////////////////////////////////////////////////////////////////
//
//  History of Changes     (Please remove very old comments and blank lines!)
//            $Log: /IDK/OPCServer/clients/VC++/Trend/Item.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 "Item.h"
#include "IOPCSyncIO.h"
//#include "IOPCAsyncIO.h" async trend read not supported in step 1
#include "TrendDataDlg.h"
#include "MainFrm.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNCREATE(CItem,	CObject)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CItem::CItem()
{
	memset(&m_timeStamp,0, sizeof(FILETIME));
	m_dwRequestedSamples = 20; //default
	m_pGroup = NULL;
	m_quality = 0;
	m_data_type = VT_EMPTY; 
	memset(&m_value,0,sizeof(VARIANT));
	m_TrenData.RemoveAll();
}

CItem::~CItem()
{

}

CGroup* CItem::GetGroup()
{
	return m_pGroup;
}

void CItem::SetGroup(CGroup* pGroup)
{
	m_pGroup = pGroup;
}

void CItem::SetDataType(VARTYPE data_type)
{
	m_data_type = data_type;
}

VARTYPE CItem::GetDataType()
{
	return m_data_type;
}


void CItem::SetQuality(WORD quality)
{
	m_quality = quality;
}

WORD CItem::GetQuality()
{
	return m_quality;
}

void CItem::SetValue(VARIANT value)
{
	m_value = value;
}

VARIANT CItem::GetValue()
{
	return m_value;
}

void CItem::SetTimeStamp(FILETIME time_stamp)
{
	m_timeStamp = time_stamp;
}

FILETIME CItem::GetTimeStamp()
{
	return m_timeStamp;
}

BOOL CItem::LoadTrendData()
{
	//sync only for the beginning
	
	//delete all existing data
	m_TrenData.RemoveAll();
	
	CTrendDataDlg	dlg;

	dlg.m_dwSamples = m_dwRequestedSamples;
	if(IDOK == dlg.DoModal()) 
	{
		m_dwRequestedSamples = dlg.m_dwSamples;
	}
	else return FALSE;
	
	if(0 == dlg.m_iRead) //sync
	{
		CIOPCSyncIO	opcSyncIO(GetGroup()->GetInterface());

		HRESULT			res;
		HRESULT*		pErrors;
		TRACE("---> error array ?");
		OPCDATASOURCE	dwSource = OPC_DS_CACHE; //cache (database always)
		OPCHANDLE*		phServer = new OPCHANDLE[m_dwRequestedSamples];
		for(DWORD i = 0; i < m_dwRequestedSamples; i ++)
		{
			phServer[i] = GetHandle();
		}

		OPCITEMSTATE*	pItemValues;//out

		res = opcSyncIO.Read( dwSource, m_dwRequestedSamples, phServer, &pItemValues, &pErrors);
		if(SUCCEEDED(res))
		{
			//copy the value from pItemValues and write it in the content view
			SetQuality(pItemValues[0].wQuality);
			SetValue(pItemValues[0].vDataValue);

			for(DWORD i = 0; i < m_dwRequestedSamples; i++)
			{
				m_TrenData.Add(pItemValues[i]);
				VariantClear( &(pItemValues[i].vDataValue) );
			}

			CoTaskMemFree(pErrors);
			CoTaskMemFree(pItemValues);

			((CMainFrame*)AfxGetMainWnd())->GetOutPutBar().DisplayText(_T("Sync Read OK"));

			delete[] phServer;
			return TRUE;
		}
		else 
		{
			delete[] phServer;
			GetGroup()->GetInfoServer()->DisplayError(res);
			return FALSE;
		}
	}
	else if(1 == dlg.m_iRead) //async
	{		
		/*
		async trend read is not supported in step1	
		
		*/
		return FALSE;
	}

	return FALSE;
}

unsigned int CItem::GetTrendData(CArray<OPCITEMSTATE, OPCITEMSTATE>** trend_data)
{
	*trend_data = &m_TrenData;
	return((*trend_data)->GetSize());
}

DWORD CItem::GetRequestedSamples()
{
	return m_dwRequestedSamples;
}

⌨️ 快捷键说明

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