vb.net的OPC通讯 点击:2154 | 回复:1



boskin

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:11帖 | 0回
  • 年度积分:0
  • 历史总积分:33
  • 注册:2002年8月30日
发表于:2004-02-26 11:13:00
楼主
我用simens的OPC.SimaticNet做OPC Server,vb.net和VB分别作为OPC Client, 连接Server、添加Group和Item的程序分别如下: VB Public WithEvents ServerObj As OPCServer Public WithEvents GroupObj As OPCGroup Dim ItemObj1 As OPCItem Set ServerObj = New OPCServer ServerObj.Connect "OPC.SimaticNET", "192.168.21.150" Set GroupObj = ServerObj.OPCGroups.Add("MyOPCGroup") GroupObj.IsSubscribed = True Set ItemObj1 = GroupObj.OPCItems.AddItem("S7:[S7 connection_1]MW2", 1) VB.Net Public WithEvents ServerObj As OPCSiemensDAAutomation.OPCServer Public WithEvents GroupObj As OPCSiemensDAAutomation.OPCGroup Dim ItemObj1 As OPCSiemensDAAutomation.OPCItem ServerObj = New OPCSiemensDAAutomation.OPCServer ServerObj.Connect("OPC.SimaticNET", "192.168.21.150") GroupObj=ServerObj.OPCGroups.Add("MyOPCGroup") GroupObj.IsSubscribed = True ItemObj1 = GroupObj.OPCItems.AddItem("S7:[S7 connection_1]MW2", 1) 执行VB程序没有问题,可以顺利对Item进行读写,执行vb.Net时,执行到GroupObj=ServerObj.OPCGroups.Add("MyOPCGroup")时就提示有错误:未将对象应用设置到对象的实例.



owenyang

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 5回
  • 年度积分:0
  • 历史总积分:5
  • 注册:2004年2月22日
发表于:2004-02-26 11:13:00
1楼
我没有开发果opc ,但我认为在.net中GroupObj=ServerObj.OPCGroups.Add("MyOPCGroup")这样使用时不正确的,你必须先实例化一个opcgroup,然后再add, 或者在括号中的是一个opcgroup实例,而不能是一个字符串,也就是可以这样: 将这个对象 GroupObj 赋值,然后增add it to opcgroups,不知我说的又没有道理。

热门招聘
相关主题

官方公众号

智造工程师