ASP.net开发opc客户端,aspx上数值不能显示。
我用asp.net+OPCDAAuto.dll想写网页来显示opc服务器里面的值。
这是LV3.aspx.vb里面的代码。
----------------------------------------------------------------------
Imports OPCAutomation
Partial Class _Default
Inherits System.Web.UI.Page
'Inherits System.Web.UI.Control
Dim NUMITEMS As Integer = 24 ' 24 varialbes
Dim WithEvents AnOPCServer As OPCAutomation.OPCServer
Dim WithEvents ConnectedOPCServer As OPCAutomation.OPCServer
Dim WithEvents ConnectedGroup As OPCAutomation.OPCGroup
Dim OPCItemIDs(NUMITEMS) As String
Dim ClientHandles(NUMITEMS) As Int32
Dim ItemServerHandles As System.Array
Dim AddItemServerErrors As System.Array
Dim value1, value2 As Double
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Response.Redirect("LV4.aspx", True)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("LV3.aspx", True)
End Sub
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Try
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Cybectec.VisualSubstation.1", "")
Catch ex As Exception
ConnectedOPCServer = Nothing
MsgBox("OPC server connection encouter error: " + ex.Message)
End Try
Try
ConnectedOPCServer.OPCGroups.DefaultGroupIsActive = True
ConnectedOPCServer.OPCGroups.DefaultGroupDeadband = 0
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add("Equinix")
ConnectedGroup.UpdateRate = 1000 ' update rate=10ms
ConnectedGroup.IsSubscribed = True
Catch ex As Exception
MsgBox("OPC server add group encouter error: " + ex.Message)
End Try
Try
Dim ItemCount As Integer = NUMITEMS
Dim AddItemServerErrors As System.Array
OPCItemIDs(1) = "PUE L3"
ClientHandles(1) = 1
OPCItemIDs(2) = "PUE L4"
ClientHandles(2) = 2
ConnectedGroup.OPCItems.DefaultIsActive = True
ConnectedGroup.OPCItems.AddItems(ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, AddItemServerErrors)
Catch ex As Exception
' Error handling
MsgBox("OPC server add items encouter error: " + ex.Message)
End Try
End Sub
Protected Sub ConnectedGroup_DataChange(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Array, ByRef ItemValues As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Array) Handles ConnectedGroup.DataChange
value1 = ItemValues(1)
value2 = ItemValues(2)
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
OPCItemValue_1.Text = value1
OPCItemValue_2.Text = value2
End Sub
End Class
我一步一步调试的时候,在value1 = ItemValues(1),value2 = ItemValues(2)这里看到是有值的。
然后我调用Button3_click的时候。
Protected S