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

📄 opcitem.h

📁 支持OPC的客户端演示程序
💻 H
字号:
/*
OPCClientToolKit
Copyright (C) 2005 Mark C. Beharrell

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
*/

#if !defined(AFX_OPCITEM_H__B01EC96B_8666_4498_93C9_980AAFEABFB6__INCLUDED_)
#define AFX_OPCITEM_H__B01EC96B_8666_4498_93C9_980AAFEABFB6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "OPCClient.h"


class COPCGroup;



/**
* Holds desciption of a property for an OPC item.
*/
struct CPropertyDescription{
	/// properties identifier
	DWORD id;

	/// server supplied textual description
	CString desc;

	/// data type of the property
	VARTYPE type;

	CPropertyDescription(DWORD i, CString d, VARTYPE t):id(i),desc(d), type(t){};
};


/**
* holds value for OPC item property
*/
struct SPropertyValue{
	/// the property that this value describes.
	const CPropertyDescription & propDesc;

	/// properties value.
	VARIANT value;

	SPropertyValue(const CPropertyDescription &desc, VARIANT &val):propDesc(desc){
		value.vt = VT_EMPTY;
		HRESULT result = VariantCopy( &value, &val);
		if (FAILED(result)){
			throw OPCException("VarCopy failed", result);
		}
	}

	~SPropertyValue(){
		VariantClear(&value);
	}
};



/**
* Provides wrapper for operations that typically exist at the group level (e.g. reads) (it is at this level
* that OPC supports the operation) however, we provide the operation at this level for ease of use.
*/
class COPCItem  
{
	OPCHANDLE serversItemHandle;
    VARTYPE vtCanonicalDataType;
    DWORD dwAccessRights;

	COPCGroup & group;

	CString name;

public:

	COPCItem(CString &itemName, bool active, COPCGroup &g);


	virtual ~COPCItem();


	void writeSync(VARIANT &data);


	void readSync(OPCItemData &data, OPCDATASOURCE source);


	/**
	* returned transaction object is owned
	*/
	CTransaction * readAsynch(ITransactionComplete *transactionCB = NULL);


	/**
	* returned transaction object is owned
	*/
	CTransaction * writeAsynch(VARIANT &data, ITransactionComplete *transactionCB = NULL);

	
	DWORD getAccessRights() const{
		return dwAccessRights;
	}

	OPCHANDLE getHandle() const{
		return serversItemHandle;
	}	

	const CString & getName() const{
		return name;
	} 

	void getSupportedProperties(CAtlArray<CPropertyDescription> &desc);

	
	/**
	* retreive the OPC item properties for the descriptors passed. Any data previously existing in propsRead will be destroyed.
	*/
	void getProperties(const CAtlArray<CPropertyDescription> &propsToRead, ATL::CAutoPtrArray<SPropertyValue> &propsRead);
};

#endif // !defined(AFX_OPCITEM_H__B01EC96B_8666_4498_93C9_980AAFEABFB6__INCLUDED_)

⌨️ 快捷键说明

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