想用VB走OPC读取wincc的数据,数据量很大,用异步通信方式,现在的问题是在服务器中建立2个及以上的组的时候,异步读取的相关回调事件,只认我第一个添加的group。也就是说当我把MyGroup指向Item(2)的时候,他的回调事件不执行。请问怎么破。
问题补充:
感谢城班回答,你可能是没有理解我的意思,我用OPCGroups.add,添加两个组,比如分别叫group1和2。但是只有group1的事件脚本执行,group2的事件不执行。两个组属性一样。我猜可能是一个组集合中,只能有一个事件组,所以第二个组的事件不执行。
最佳答案
将你的相关代码补发上来。
下面的代码是从网上拷贝的:
''异步读回调
Private Sub GroupObj_AsyncReadComplete(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date, Errors() As Long)
Dim ErrorString As String
If (TransactionID = READASYNC_ID) Then
If Errors(1) = 0 Then
Edit_ReadVal = ItemValues(1)
Edit_ReadQu = GetQualityText(Qualities(1))
Edit_ReadTS = TimeStamps(1)
Else
ErrorString = ServerObj.GetErrorString(Errors(1))
MsgBox ErrorString, vbCritical, "Error AsyncReadComplete()"
End If
End If
End Sub
简单点的:
Private Sub objTestGrp_AsyncReadComplete( _
ByVal TransactionID As Long, ByVal NumItems As Long, _
ClientHandles() As Long, ItemValues() As Variant, _
Qualities() As Long, TimeStamps() As Date, Errors() As Long)
Dim i As Integer
Dim Index As Integer
For i = 1 To NumItems
'' 得到客户标识符
Index = ClientHandles(i)
'' 表示数据字符串
txtTag(Index).Text = ItemValues(i)
Next i
End Sub
提问者对于答案的评价:
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc363060.html