用VB 编写OPC服务器客户端程序,其中老是出现无效的过程调用或参数,求助!

调试程序发现错误出现在读数据“SetOne=MyOPCGroup.OPCItems(Index)”这句,另外,同步写数据是也没有写到服务器中去,程序整了好多天了还是没整出... 调试程序发现错误出现在读数据“Set One = MyOPCGroup.OPCItems(Index)”这句,另外,同步写数据是也没有写到服务器中去,程序整了好多天了还是没整出来。请求专业人士的帮忙解答,谢谢~~
Dim WithEvents MyOPCServer As OPCServer

Dim WithEvents MyOPCGroups As OPCGroups
Dim WithEvents MyOPCGroup As OPCGroup
Dim ServerName As String '服务器名
Dim GroupName As String '组名
Dim MyOPCItems As OPCItems
Dim ItemIDs() As String
Dim ItemNumb As Long
Dim MyServerHandles() As Long
Dim MyClientHandles() As Long
Dim Errors() As Long
Private Sub AddItem_Click()
On Error GoTo ErrorHandler
Set MyOPCGroups = MyOPCServer.OPCGroups
Set MyOPCGroup =MyOPCGroups.Add("GroupOne") '添加组名为Group One的组对象
MyOPCGroups.DefaultGroupUpdateRate = 500
ItemNumb = 4
Set MyOPCItems = MyOPCGroup.OPCItems
ReDim ItemIDs(ItemNumb)
ReDim MyClientHandles(ItemNumb)
ItemIDs(1) = "2,VB200,byte "
ItemIDs(2) = "2,VB201,byte "
ItemIDs(3) = "2,VB202,byte "
ItemIDs(4) = "2,VB203,byte "
Dim i As Integer
MyClientHandles(1) = 1
MyClientHandles(2) = 2
MyClientHandles(3) = 3
MyClientHandles(4) = 4
MyOPCGroup.IsActive = True '准备收发数据
MyOPCGroup.IsSubscribed = True '产生事件
Call MyOPCItems.AddItems(ItemNumb, ItemIDs,MyClientHandles, MyServerHandles, Errors)
End Sub

Private Sub Cmd_connect_Click()
Set MyOPCServer = New OPCServer
Call MyOPCServer.Connect(Text1.Text)
' connect from OPC Server
Cmd_disconnect.Enabled = True
Cmd_connect.Enabled = False
End Sub

Private Sub Cmd_disconnect_Click()
MyOPCServer.Disconnect
Disconnect from OPC Server

Set MyOPCServer = Nothing
Delete OPCServer Object
Cmd_disconnect.Enabled = False
Cmd_connect.Enabled = True
End Sub

Private Sub Cmd_Read_Click() '同步数据读写
Dim One As OPCItem
Dim Index As Long 'Index 为标签顺序号
Dim myValue(4) As Variant
Dim myQuality As Variant
Dim myTimeStamp As Variant
For Index = 1 To 4
Text2(Index - 1).Text =CStr(myValue(Index))
Next
Dim OneRead As String
Dim Xie As String
Set One = MyOPCGroup.OPCItems(Index)
One.Read OPCCache
OneRead = One.Value '读数据
MyOPCGroup.SyncRead OPCCache, ItemNumb,MyServerHandles, myValue, Errors
End Sub

Private Sub Cmd_write_Click()
Dim Index As Long 'Index 为标签顺序号
Dim myValue(4) As Variant
Dim myQuality As Variant
Dim myTimeStamp As Variant
For Index = 1 To 4
myValue(Index) = Text2(Index - 1).Text
Next
MyOPCGroup.SyncWrite 2, MyServerHandles,myValue, Errors
End Sub

Private Sub MyOPCGroup_DataChange(ByVal
TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long,
ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
Dim i As Long
Fori = 1 To NumItems
IfClientHandles(i) > 0 And ClientHandles(i) < 5 Then
Text4(i - 1).BackColor = vbWhite
Text4(i- 1).Text = ItemValues(i)
EndIf
Nexti
End Sub
ps:主要是本人现在没有财富分悬赏了,还请请多多见谅!
展开
 我来答
Dino_f
2012-12-14 · TA获得超过285个赞
知道小有建树答主
回答量:437
采纳率:0%
帮助的人:287万
展开全部
应该是OPCGroup这个类没有OPCItems这个方法提供调用,或他要求的Index参数不能是Long型。
来自:求助得到的回答
亲爱的小绵羊yo
2012-12-13 · 超过47用户采纳过TA的回答
知道小有建树答主
回答量:135
采纳率:0%
帮助的人:135万
展开全部
1
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式