OPC客户端设计

本文详细介绍OPC程序开发环境的配置步骤,包括必要DLL文件的安装,如OPC代理/存根DLL,以及如何使用注册组件opcenum.exe。文章还提供了一个CComPtr示例,展示如何初始化IOPCServerList对象。

1. 开发环境配置

  要安装和开发OPC程序,安装必要的OPC代理/存根(Proxy/Stub)DLL是必需的,这些文件提供了OPC接口的数据结构定义,可以使OPC客户端程序和服务器程序之间进行有效的通信。

  所有文件必须安装在客户端机器和服务器端机器上。要将这些文件放置在system32系统文件夹下。

需要文件:

  这些文件包括:

  opc_aeps.dll    //警报与时间服务器代理/存根

  opccomn_ps.dll   //公用的代理/存根(主要服务器都需要)

  opchda_ps.dll   //历史数据存取代理/存根

  aprxdist.exe     //运行环境需要

  opcenum.exe      //服务器类别搜索组建程序(都需要),如果没有,就无法在注册表中进行注册

安装方法:

  将上述文件全部复制到windows\system32目录下。

  安装代理/存根:

    REGSVR32 opcproxy.dll

    REGSVR32 opccomn_ps.dll

    REGSVR32 opc_aeps.dll

    REGSVR32 opchda_ps.dll

  安装opcenum.exe

    opcenum /regserver

 

//CComPtr: Smart pointer

CComPtr<IOPCServerList> pOPCServerList;

 

//Creates a single uninitialized object of the class associated with a specified CLSID.
hr = pOPCServerList.CoCreateInstance( CLSID_OpcServerList );

 

//A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.

//to register, you need to run opcenum.exe

if(REGDB_E_CLASSNOTREG == hr)
  return FALSE;

if( FAILED( hr ) )
  return FALSE;

 

The return value of function CoCreateInstance:
 
ValueDescription

S_OK

An instance of the specified object class was successfully created.

REGDB_E_CLASSNOTREG

A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.

CLASS_E_NOAGGREGATION

This class cannot be created as part of an aggregate.

转载于:https://www.cnblogs.com/johnpher/archive/2012/10/11/2720218.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值