OPC .Net client server toolkits for OPC DA, HDA, AE, XML-DA      Advanced
OPC
Solutions    
         OPC .Net client server toolkits for OPC DA, HDA, AE, XML-DA
Online Tools
- OPC Error Lookup
Search  
   
* privacy and security Guaranteed  
XMLDA.NET Read Sample Application Login  

XMLDA.NET Sample Application

Visual Basic Windows Forms Application that uses the XML-DA Read method

XMLDA.NET Sample client application The values of a set of 5 items are read from an OPC-DA or XML-DA server. The request list with the item names and optional parameters is defined in an embedded XML file. This XML file was created and can be modified with the ItemListBuilder utility.

   Dim embeddedList As ListBuilder

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Try
         embeddedList = New ListBuilder
         embeddedList.LoadEmbedded("ItemList.xml")

         ' display the item names defined in the list
         Dim readItemList As ReadRequestItemList = embeddedList.GetReadItemList("Read1")
         Dim txt As String = ""
         Dim ri As ReadRequestItem
         For Each ri In readItemList.Items
            txt += ri.ItemName + Environment.NewLine
            tbItems.Text = txt
         Next
      Catch ex As Exception
         MessageBox.Show(ex.Message, "Exception at Load Item Configuration")
         Application.Exit()
      End Try
   End Sub

   '----------------------------------------------------------------------------------------
   ' Get Server Status
   Private Sub btnGetStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetStatus.Click
      Dim srv As XmlServer = New XmlServer(cbURL.Text)
      Dim status As ServerStatus
      Dim reply As ReplyBase
      reply = srv.GetStatus(Nothing, Nothing, status)
      tbStatus.Text = status.ProductVersion & ControlChars.CrLf & status.VendorInfo
   End Sub

   Private Sub btnRead_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
      Dim srv As XmlServer = New XmlServer(cbURL.Text)   ' server object
      Dim readItemList As ReadRequestItemList
      readItemList = embeddedList.GetReadItemList("Read1")
      Dim reply As ReplyBase
      Dim options As RequestOptions = New RequestOptions
      options.ReturnErrorText = True
      options.ReturnItemName = True
      Dim rslt As ReplyItemList
      Dim err As OPCError()
      Try
         reply = srv.Read(options, readItemList, rslt, err)
         If rslt Is Nothing Then
            MessageBox.Show(err(0).Text, "Error at Read")
         Else
            Dim txt As String = ""
            Dim iv As ItemValue
            For Each iv In rslt.Items
               txt += iv.ItemName
               If iv.ResultID Is Nothing Then ' success
                  txt += "   = " + iv.Value.ToString() + Environment.NewLine
               Else
                  txt += " : Error: " + iv.ResultID.Name + Environment.NewLine
               End If
            Next
            tbItems.Text = txt
         End If
      Catch ex As Exception
         MessageBox.Show(ex.Message, "Exception in Read")
         Close()
      End Try
   End Sub

 

 

home | contact us | return policy | privacy policy | security policy | Copyright © 2018 Advosol Inc. All Rights Reserved.