OPCServer 提供的全部接口说明

http://www.dqjsw.com.cn/dianqi/OPC/301.html
1.What is OPC?


OPC是OLE for Process Control的缩写。顾名思义,OPC是一种利用微软的COM/DCOM技术来达成自动化控制的协定,根据OPC Specification 的定义,OPC is "a standard mechanism for communicating to numerous data sources, either devices on the factory floor, or a database in a control room."

在现今的工业自动化中,我们需要一套整合的信息系统,由底层的各项装置采集信息 (Field Management),中层的控制系统或图控应用程序进行程序的控制 (Process Management),再由最上层的整合软件将这些信息整合起来以供企业决策或效能提升,如下图所示:

    OPC 为硬件制造商与软件开发商提供了一条桥梁,透过硬件厂商提供的 OPC Server 接口,软件开发者不必考虑各项不同硬件间的差异,便可自硬件端取得所需的信息,所以软件开发者仅需专注于程序本身的控制流程的运作。此外,由于 COM/DCOM 实作并隐藏了网络的细节,透过 OPC 可以很容易地达成远程控制的理想。

2.How does OPC work?
在说明 OPC Server/Client 运作方式之前,我们先简单介绍一下 Microsoft 发展的 COM/DCOM 是什么?
COM 是一种发展软件组件的方法,所谓的软件组件,是指一个可以提供应用程序、操作系统、以及其它组件服务的二进制可执行程序。事实上,发展自订的 COM 对象就好象是在建构一套可以动态执行的对象导向 API 一般。你可以在应用程序执行的时期随意拼上或移除所需要的组件。依据 COM 这样的概念,发展应用程序就像是堆积木一样,每一个 COM 组件就是一块积木,你可以利用各式各样不同的积木,拼凑出你所需要的应用程序。

在实作上,COM 透过一组一组的接口 (Interface) 提供服务,所有 COM 组件的使用者,都必须透过这些 Interface 来使用组件提供的功能。OPC 的规格中便定义了许多 OPC Server 应该提供的 Interface,要撰写一个 OPC Server 的 COM 组件,你必须在你的组件中加入这些接口,并提供它们的实作,Client 便可以透过这些接口,操作连接到 OPC Server 的硬件装置,这也就是 OPC Server/Client 运作的方式。以下的图标可以让这样的概念更清晰。

3. OPC Server 架构

如前面所述,OPC Server 透过一组一组的接口提供服务,不过在实作的架构上,OPC Server 共分为三层:分别是 OPCServer, OPCGroup, OPCItem


其中每一个 OPCItem 对应到一个实际的硬件装置上的某一个 channel 或 port;每一个 OPCGroup 则包含了许多的 OPCItem,同时并定义这些 OPCItem 更新的时间、方式,以及提供读取 OPCItem 值的接口;而每一个 OPCServer 则包含若干个 OPCGroup,同时提供操作这些 OPCGroup 的接口。


下图可以较清楚地说明 OPCServer/OPCGroup/OPCItem 间的关系:

  4. OPC Custom Interface

接下来的这一节,我们将讨论 OPC Serve 的重点,也就是每一组接口的定义,以及它所提供的功能。
OPCServer 提供的接口:
IOPCCommon
HRESULT SetLocaleID ( dwLcid ) 设定位置信息
HRESULT GetLocaleID ( pdwLcid ) 取得位置信息
HRESULT QueryAvailableLocaleIDs ( pdwCount, pdwLcid ) 查询可用的位置ID
HRESULT GetErrorString ( dwError, ppString) 取得错误信息字符串
HRESULT SetClientName (szName)设定Clinet的名称


IOPCServer
HRESULT AddGroup(szName, bActive, dwRequestedUpdateRate, hClientGroup, pTimeBias, pPercentDeadband, dwLCID, phServerGroup, pRevisedUpdateRate, riid, ppUnk) 新增一个 OPCGroup
HRESULT GetErrorString(dwError, dwLocale, ppString) 取得错误信息字符串
HRESULT GetGroupByName(szName, riid, ppUnk) 依据名称取得OPCGroup 的介面
HRESULT GetStatus(ppServerStatus) 取得 OPCServer的状态信息
HRESULT SetClientName (szName)设定Clinet的名称RemoveGroup(hServerGroup, bForce)移除一个OPCGroup
HRESULT CreateGroupEnumerator(dwScope, riid, ppUnk) 产生一个OPCGroup 列举器

IConnectionPointContainer
HRESULT EnumConnectionPoints( IEnumConnectionPoints ppEnum) 列举所有的 Connection Points
HRESULT FindConnectionPoint( REFIID riid, IConnectionPoint ppCP)找出一个 Connection Point

IOPCItemProperties
HRESULT QueryAvailableProperties(szItemID, pdwCount,ppPropertyIDs, ppDescriptions, ppvtDataTypes ); 查询可用的 OPCItem属性
HRESULT GetItemProperties (szItemID, dwCount, pdwPropertyIDs,ppvData, ppErrors ) 取得 OPCItem 的属性
HRESULT LookupItemIDs( szItemID, dwCount, pdwPropertyIDs,ppszNewItemIDs, ppErrors )使用名称查询OPCItem 的 ID

IOPCBrowseServerAddressSpace (optional)
HRESULT QueryOrganization(pNameSpaceType )查询组织名称
HRESULT ChangeBrowsePosition(dwBrowseDirection, szString )变更浏览的位置
HRESULT BrowseOPCItemIDs( dwBrowseFilterType, szFilterCriteria, vtDataTypeFilter, dwAccessRightsFilter, ppIEnumString )浏览 OPCServer 內所有定义的 OPCItem
HRESULT GetItemID( szItemDataID, szItemID ) 取得 OPCItem 的 ID
HRESULT BrowseAccessPaths( szItemID, ppIEnumString )浏览存取OPCItem 的路径

OPCGroup Object 提供的接口

IOPCGroupStateMgt
HRESULT GetState(pUpdateRate, pActive, ppName, pTimeBias, pPercentDeadband, PLCID, phClientGroup, phServerGroup)取得OPCGroup的状态即设定信息
HRESULT SetState(pRequestedUpdateRate, pRevisedUpdateRate, pActive, pTimeBias, pPercentDeadband, PLCID, phClientGroup)设定OPCGroup 的状态信息
HRESULT SetName(szName)设定OPCGroup的名称
HRESULT CloneGroup(szName, riid, ppUnk) 复制一个OPCGroup

IOPCSyncIO
HRESULT Read(dwSource, dwCount, phServer, ppItemValues, ppErrors); 以同步方式读取OPCGroup内的OPCItem(s) 的值
HRESULT GetItemProperties (szItemID, dwCount, pdwPropertyIDs,ppvData, ppErrors ) 取得 OPCItem 的属性
HRESULT Write(dwCount, phServer, pItemValues, ppErrors) 以同步方式将值写入OPCGroup 內的 OPCItem(s)

IOPCAsyncIO2
HRESULT Read(dwCount, phServer, dwTransactionID, pdwCancelID, ppErrors,) 以非同步方式读取OPCGroup内的OPCItem(s)的值,值会在读取硬件的动作结束后以callback的形式传回
HRESULT SetState(pRequestedUpdateRate, pRevisedUpdateRate, pActive, pTimeBias, pPercentDeadband, PLCID, phClientGroup)设定OPCGroup的状态信息
HRESULT Write(dwCount, phServer, pItemValues, dwTransactionID, pdwCancelID, ppErrors)以非同步方式将值写入OPCGroup内的OPCItem(s)
HRESULT Cancel2 (dwCancelID) 取消前一次的非同步讀取/寫入
HRESULT Refresh2(dwSource, dwTransactionID, pdwCancelID) 更新 OPCGroup 內 OPCItem(s) 的值
HRESULT SetEnable(bEnable) 將 OPCGroup 設為 Enable
HRESULT GetEnable(pbEnable) 傳回 OPCGroup 是否為 Enable

IOPCItemMgt

HRESULT AddItems(dwCount, pItemArray, ppAddResults, ppErrors); 在OPCGroup内新增OPCItem(s)
HRESULT ValidateItems(dwCount, pItemArray, bBlobUpdate, ppValidationResults, ppErrors)检查OPCItem(s)的名称是否可用
HRESULT RemoveItems(dwCount, phServer, ppErrors) 移除OPCGroup 內的 OPCItem(s)
HRESULT SetActiveState(dwCount, phServer, bActive, ppErrors)高定 OPCItem(s)是否为Avtive
HRESULT SetClientHandles(dwCount, phServer, phClient, ppErrors)设定 OPCItem(s) 的 handle
HRESULT SetDatatypes(dwCount, phServer, pRequestedDatatypes, ppErrors) 设定OPCItem(s)的数据类型
HRESULT CreateEnumerator(riid, ppUnk)产生OPCItems的列举器

IConnectionPointContainer

HRESULT EnumConnectionPoints( IEnumConnectionPoints ppEnum)列举所有的 Connection Points
HRESULT FindConnectionPoint( REFIID riid, IConnectionPoint ppCP)找出一个Connection Point

5. 结论
OPC Server/Client 是一套利用微软的 COM/DCOM 技术达成工业自动化资料取得的架构。OPC Server 提供了许多的接口,Client 端透过这些接口,可以取得与 OPC Server 相连的硬件装置的信息,而无须了解这些硬件装置的细节信息。也就是说,程序设计者可以使用相同的程序代码,操作不同的硬件装置,充分达成 software reuse 的理想。同时,由于 COM/DCOM 已实作了网络部分的细节,也使得 Client 对 OPC Server 进行远程访问非常容易,使程序设计者很容易地达成远程控制的目标。
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值