cdmahong
cdmahong
采纳率33.3%
2015-01-12 02:19 阅读 3.2k

基于VB.NET的opc程序AsyncWrite无法写入

在用VB.NET编写OPC读写西门子S7400程序一个地址,Asyncread能够顺利读取OPC SCOUT里面的数据,但Asyncwrite运行也无错误,但是却无法更改地址的数据, 在个人PC OPC SCOUT上,DB1.DBW数据无变化,AsyncWriteComplete无运行,请教高人我错在哪里或缺少什么?应该怎么改?
Private Sub PLC_U_AddItem2()
For j As Short = 65 To 65
MyOPCItemIDs2(j - 65) = "S7:[@LOCALSERVER]DB1,W1666,1"
MyOPCItemIsArray2(j) = 0
MyClientHandles2(j) = j - 64
Next j
MyGroup2.OPCItems.AddItems(ItemCount, MyOPCItemIDs2, MyClientHandles2, MyItemServerHandles2, AddItemServerErrors2)
End Sub
Sub PLC_AsyncRead()
Dim MyErrors2 As System.Array
If MyGroup2.OPCItems.Count > 0 Then
lTransID_Rd2 = 1
MyGroup2.AsyncRead(1, MyItemServerHandles2, _
MyErrors2, lTransID_Rd2, lCancelID_Rd2)
End If
End Sub
Private Sub PLC_AsyncWrite(ByVal NumItemsW As Integer, ByRef ItemValuesW As Array, ByRef MyErrors As System.Array)
Dim lHandle As Array = Array.CreateInstance(GetType(Integer), 1)
For i = 1 To 1
lHandle.SetValue(MyItemServerHandles2(i), i - 1)
lTransID_Rd2 = 1
Next
MyGroup2.AsyncWrite(1, lHandle, ItemValuesW,
MyErrors, lTransID_Rd2, lCancelID_Rd2)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim ItemValuesW1 As Array = Array.CreateInstance(GetType(Object), dims, bounds)
Dim myErrors As Array = Array.CreateInstance(GetType(Integer), dims, bounds)
For i = 1 To 1
ItemValuesW1.SetValue(Convert.ToInt32(TextBox7.Text), 1)
Next
Call PLC_AsyncWrite(1, ItemValuesW1, myErrors)

End Sub
Private Sub MyGroup2_AsyncWriteComplete(ByVal TransactionID As Long, ByVal NumItems As Long, _ClientHandles() As Long, itemvalue() As Long, Errors() As Long)
Dim i As Short
MsgBox(1)
For i = 0 To 32
buf(i) = itemvalue(i)
Next
End Sub
End Class

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐