发表于: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")时就提示有错误:未将对象应用设置到对象的实例.