前段时间做一个实时数据的采集工作,实时数据来自监控系统,监控系统有西门子的wincc,ABB公司等。OPC是监控领域中最适合的数据集成方法。查了很多资料,都是VB,VC等的编程资料,基本找不到关于PB的OPC编程资料。现在把它整理出来,供大家参考。
先从网上下载OPCDA20.EXE安装起来,然后从网上找个OPC控件包(有DACLTSDK.dll,DACLTSDK_ActiveX.ocx,OPC_AEPS.DLL,opccomn_ps.dll,opchda_ps.dll,OPCPROXY.DLL,OpcRcw.Comn.dll)拷贝到%WINDIR%/System32文件夹下,然后执行命令注册:
REGSVR32 /s %WINDIR%/System32/opccomn_ps.dll
REGSVR32 /s %WINDIR%/System32/opcproxy.dll
REGSVR32 /s %WINDIR%/System32/opc_aeps.dll
REGSVR32 /s %WINDIR%/System32/opchda_ps.dll
REGSVR32 /s %WINDIR%/System32/OpcRcw.Comn.dll
regsvr32 /s %WINDIR%/System32/DACLTSDK_ActiveX.ocx
%WINDIR%/Opcenum /RegServer
在PB中创建一个opc控件,名字为ole_1,初始化
TRY
if ole_1.object.Connect(host,serverid) then
try
if ole_1.object.Addgroup("GROUP",updateRate) then
return true
else
return false
end if
CATCH ( runtimeerror erAddgroup)
return false
END TRY
else
return false
end if
CATCH (runtimeerror erConnect)
return false
END TRY
然后加标签
TRY
IHandle=ole_1.object.AddItem(itemname)
if IHandle>0 then
return IHandle
else
return 0
end if
取值
Value=ole_1.object.readItem(IHandle)
更详细的参考我的学生的博文http://hi.baidu.com/c306626531/blog/item/1ca69836f1abc8d4a3cc2bda.html
【天涯博客】本文地址http://blog.tianya.cn/blogger/post_show.asp?idWriter=23792194&Key=159396252&PostID=21191751&BlogID=2049916