有人用Delphi编写过OPC自动化客户端吗? 点击:2156 | 回复:6



Maka

    
  • 精华:1帖
  • 求助:0帖
  • 帖子:9帖 | 10回
  • 年度积分:0
  • 历史总积分:42
  • 注册:2003年3月31日
发表于:2003-11-13 12:21:00
楼主
如果我使用OPC基金会的模拟服务嚣,怎样用Delphi写OPC自动化客户端? 先谢了!!!



gongkongedit

  • 精华:1099帖
  • 求助:0帖
  • 帖子:14392帖 | 54470回
  • 年度积分:0
  • 历史总积分:622
  • 注册:2008年9月08日
发表于:2003-11-13 12:21:00
1楼
delphi 完全支持COM,干吗不编写定制接口的客户端

电烙铁

  • 精华:0帖
  • 求助:0帖
  • 帖子:5帖 | 43回
  • 年度积分:0
  • 历史总积分:136
  • 注册:2003年11月19日
发表于:2006-02-23 12:54:00
2楼
我一直就想用自己写的上位机程序通过PPI电缆来监视和修改西门子的PLC 的内存 ,于是就买了个西门子的PC AccessV1.0.2.26 OPC软件,回家一看,好家伙,没加密的。可以随便装。安装好后我的电脑就有OPC服务器了,还有个用VB写的客户程序例子。我打开VB6编译运行,果然可以监视和修改西门子的PLC 的内存。

细看这个VB例子,

    '建立与OPC服务器的连接
    Set QOpcServer = New OPCServer
    Call QOpcServer.Connect("S7200.OPCServer") 'S7200.OPCServer是西门子OPC服务器的名称
    Set QGroups = QOpcServer.OPCGroups        ' Get OPCGroups Collection Object from QOPCServer
    ' Set Default Properties for Group Collection
    ' These Properties are used to set the Properies for new Groups
    QGroups.DefaultGroupIsActive = False ' Set Default Group Active State to Inactive
    Set QGroup = QGroups.Add("QGroup1")   ' Add a new Group to the Group Collection
    ' Set Group Properties
    QGroup.IsSubscribed = True   ' Enable Callbacks
    QGroup.UpdateRate = 100     '这个群组的刷新速度是100ms
    '下面再往群组里添加要传送的地址单元


z在Vb里,是用New来创建类的实例,但我搞不清Delphi用什么来做这事?????哪位大哥知道?

电烙铁

  • 精华:0帖
  • 求助:0帖
  • 帖子:5帖 | 43回
  • 年度积分:0
  • 历史总积分:136
  • 注册:2003年11月19日
发表于:2006-02-23 12:55:00
3楼
我一直就想用自己写的上位机程序通过PPI电缆来监视和修改西门子的PLC 的内存 ,于是就买了个西门子的PC AccessV1.0.2.26 OPC软件,回家一看,好家伙,没加密的。可以随便装。安装好后我的电脑就有OPC服务器了,还有个用VB写的客户程序例子。我打开VB6编译运行,果然可以监视和修改西门子的PLC 的内存。

细看这个VB例子,

    '建立与OPC服务器的连接
    Set QOpcServer = New OPCServer
    Call QOpcServer.Connect("S7200.OPCServer") 'S7200.OPCServer是西门子OPC服务器的名称
    Set QGroups = QOpcServer.OPCGroups        ' Get OPCGroups Collection Object from QOPCServer
    ' Set Default Properties for Group Collection
    ' These Properties are used to set the Properies for new Groups
    QGroups.DefaultGroupIsActive = False ' Set Default Group Active State to Inactive
    Set QGroup = QGroups.Add("QGroup1")   ' Add a new Group to the Group Collection
    ' Set Group Properties
    QGroup.IsSubscribed = True   ' Enable Callbacks
    QGroup.UpdateRate = 100     '这个群组的刷新速度是100ms
    '下面再往群组里添加要传送的地址单元

Vb里用New来创建类的实例,但我搞不清Delphi用什么来做这事?????

木道人

  • 精华:0帖
  • 求助:0帖
  • 帖子:5帖 | 105回
  • 年度积分:0
  • 历史总积分:345
  • 注册:2002年9月30日
发表于:2006-05-04 11:46:00
4楼
这段代码用Delphi编写如下:
其中定义如下
var
  MyOPCAutoServer : IOPCAutoServer;     //OPC服务器
  MyOPCGroups : OPCGroups;   //OPC组集合
  MyOPCGroup :  OPCGroup; //OPC组,
  MyOPCItems :  OPCItems; //OPC标签集合
begin
   MyOPCAutoServer:=CoOPCServer.Create;
   MyOPCAutoServer.Connect('ProgID','NodeName');
   MyOPCGroups:=MyOPCAutoServer.OPCGroups;
   MyOPCGroups.Set_DefaultGroupUpdateRate(500);//更新频率500ms

   MyOPCGroup:=MyOPCGroups.Add('OPCGroup');   //新添加的OPC
   MyOPCGroup.Set_IsActive(true);
   MyOPCGroup.Set_IsSubscribed(True); 
   MyOPCItems:=MyOPCGroup.OPCItems;  //建立OPC标签集合
end;  

sztaoyanbin

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 141回
  • 年度积分:0
  • 历史总积分:270
  • 注册:2003年12月04日
发表于:2006-05-12 14:04:00
5楼
ddding

tangzhj

  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 2回
  • 年度积分:0
  • 历史总积分:8
  • 注册:2006年2月09日
发表于:2006-05-17 17:50:00
6楼
var
  MyOPCAutoServer : IOPCAutoServer;     //OPC服务器
  MyOPCGroups : OPCGroups;   //OPC组集合
  MyOPCGroup :  OPCGroup; //OPC组,
  MyOPCItems :  OPCItems; //OPC标签集合
begin
   MyOPCAutoServer:=CoOPCServer.Create;
   MyOPCAutoServer.Connect('ProgID','NodeName');
   MyOPCGroups:=MyOPCAutoServer.OPCGroups;
   MyOPCGroups.Set_DefaultGroupUpdateRate(500);//更新频率500ms

   MyOPCGroup:=MyOPCGroups.Add('OPCGroup');   //新添加的OPC
   MyOPCGroup.Set_IsActive(true);
   MyOPCGroup.Set_IsSubscribed(True); 
   MyOPCItems:=MyOPCGroup.OPCItems;  //建立OPC标签集合
end;
为何我执行上述代码MyOPCAutoServer:=CoOPCServer.Create;时会出错,提示内存分配访问无效,但vb代码正常  

热门招聘
相关主题

官方公众号

智造工程师