Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

VB.NET example - OPC data with ListView

More
11 Aug 2014 07:10 #2151 by support
You are welcome :-)

Please Log in or Create an account to join the conversation.

More
10 Aug 2014 13:53 #2150 by neilcooley
Hi

Many thanks for the demo, I have now integrated the code into my own project and all I can say is what an improvement it is using your SDK over other companies.

Many thanks for the demo and I hope to do business with you in coming days.


Neil

Please Log in or Create an account to join the conversation.

More
08 Aug 2014 07:51 #2142 by support
Here is an updated example. It keeps the old (explicit Read) functionality, and also adds OPC Subscribe/Unsubscribe. I have added code comments to explain what's going on inside.

VS project (zipped):


File Attachment:

File Name: ListView1_...8-08.zip
File Size:13 KB



Screen snapshot:





Relevant code parts:
Option Explicit On
Option Strict On
 
Imports OpcLabs.EasyOpc.DataAccess
 
Public Class Form1
 
    ' Called whenever one or more subscribed items change
    Private Shared Sub EasyDAClient1_MultipleItemsChanged(sender As Object, e As EasyDAMultipleItemsChangedEventArgs) Handles EasyDAClient1.MultipleItemsChanged
        Dim count As Integer = e.ArgsArray.Length
        For i As Integer = 0 To count - 1
            Dim eventArgs As EasyDAItemChangedEventArgs = e.ArgsArray(i)
            ' We have passed the reference to the associated ListVeiwItem in a State argument when subscribing
            Dim listViewItem As ListViewItem = CType(eventArgs.State, ListViewItem)
            UpdateListViewItem(listViewItem, eventArgs.Exception, eventArgs.Vtq)
        Next
    End Sub
 
    ' Updates ListViewItem (from reading or change notification) with exception and value/timestamp/quality
    Private Shared Sub UpdateListViewItem(ByVal listViewItem As ListViewItem, ByVal exception As Exception, ByVal vtq As DAVtq)
        Dim vtqText As String = ""
        Dim exceptionText As String = ""
 
        If (Exception Is Nothing) Then
            vtqText = vtq.ToString()
        Else
            exceptionText = Exception.Message
        End If
 
        listViewItem.SubItems(1).Text = vtqText
        listViewItem.SubItems(2).Text = exceptionText
    End Sub
 
    ' IsSubscribed setter takes care of enabling/disabling the user interface elements
    Protected Property IsSubscribed As Boolean
        Get
            Return _subscribed
        End Get
        Set(value As Boolean)
            Dim oldValue As Boolean = _subscribed
            _subscribed = value
            If (_subscribed <> oldValue) Then
                UpdateButtons()
            End If
        End Set
    End Property
 
    Private Sub ReadButton_Click(sender As Object, e As EventArgs) Handles ReadButton.Click
        ' Prepare an array describing what we want to read and how
        Dim count As Integer = ItemsListView.Items.Count
        Dim argumentsArray(count - 1) As DAReadItemArguments
        For i As Integer = 0 To count - 1
            Dim listViewItem As ListViewItem = ItemsListView.Items(i)
            Dim itemId As String = listViewItem.Text
            argumentsArray(i) = New DAReadItemArguments("OPCLabs.KitServer.2", itemId, 50)
        Next
 
        ' Execute the Read operation
        Dim resultsArray() As DAVtqResult = EasyDAClient1.ReadMultipleItems(argumentsArray)
 
        ' Go through the result array, and update the list view items
        For i As Integer = 0 To count - 1
            UpdateListViewItem(ItemsListView.Items(i), resultsArray(i).Exception, resultsArray(i).Vtq)
        Next
    End Sub
 
    Private Sub SubscribeButton_Click(sender As Object, e As EventArgs) Handles SubscribeButton.Click
        IsSubscribed = True
 
        ' Prepare an array describing what we want to subscribe to and how
        Dim count As Integer = ItemsListView.Items.Count
        Dim argumentsArray(count - 1) As DAItemGroupArguments
        For i As Integer = 0 To count - 1
            Dim listViewItem As ListViewItem = ItemsListView.Items(i)
            Dim itemId As String = listViewItem.Text
            ' We use the last argument (State) to provide a reference to the associated ListViewItem
            argumentsArray(i) = New DAItemGroupArguments("OPCLabs.KitServer.2", itemId, 100, listViewItem)
        Next
 
        ' Execute the Subscribe operation
        EasyDAClient1.SubscribeMultipleItems(argumentsArray)
    End Sub
 
    Private Sub UnsubscribeButton_Click(sender As Object, e As EventArgs) Handles UnsubscribeButton.Click
        IsSubscribed = False
 
        ' Execute the Unsubscribe operation
        EasyDAClient1.UnsubscribeAllItems()
    End Sub
 
    Private Sub UpdateButtons()
        ReadButton.Enabled = Not IsSubscribed
        SubscribeButton.Enabled = Not IsSubscribed
        UnsubscribeButton.Enabled = IsSubscribed
    End Sub
 
    Private _subscribed As Boolean
End Class
 
Attachments:

Please Log in or Create an account to join the conversation.

More
08 Aug 2014 07:45 #2141 by support
N.,

In your request you wrote “reading”, so I interpreted as an explicit Read operation, that’s what it usually means.
No problem though, I will supply an example with a subscription and callback.

Best regards,

Please Log in or Create an account to join the conversation.

More
08 Aug 2014 07:44 #2140 by support
From: N.
Sent: Thursday, August 07, 2014 7:01 PM
To: Zbynek Zahradnik
Subject: RE: OPC Labs Contact Form - opc to listview

[...]

I found the example but I was expecting a call back when values changed, is this possible?

I have approx. 500 tags so I need a method with a call back when data changes.


N.

Please Log in or Create an account to join the conversation.

More
01 Aug 2014 12:12 - 01 Aug 2014 12:24 #2123 by support
I have prepared an example in VB.NET which reads OPC data and populates the ListView.

There are three items pre-populated in the ListView, with their Item IDs. Each item also has sub-items, for the VTQ (value-quality-timestamp), and a possible exception (error indication).
When the Read button is pressed, the code takes the OPC item IDs from the list view, assembles an array of arguments which allows all items be read in a single operation (for good performance), and then calls EasyDAClient.ReadMultipleItems. The resulting array is then used to update the sub-items in the list view.



The relevant pieces of code are here:
    Private Sub ReadButton_Click(sender As Object, e As EventArgs) Handles ReadButton.Click
 
        Dim count As Integer = ItemsListView.Items.Count
        Dim argumentsArray(count - 1) As DAReadItemArguments
 
        For i = 0 To count - 1
            Dim listViewItem As ListViewItem = ItemsListView.Items(i)
            Dim itemId As String = listViewItem.Text
            argumentsArray(i) = New DAReadItemArguments("OPCLabs.KitServer.2", itemId, 50)
        Next
 
        Dim resultsArray() As DAVtqResult = EasyDAClient1.ReadMultipleItems(argumentsArray)
 
        For i = 0 To count - 1
            Dim listViewItem As ListViewItem = ItemsListView.Items(i)
            Dim vtqResult As DAVtqResult = resultsArray(i)
 
            Dim vtqText As String = ""
            Dim exceptionText As String = ""
 
            If (vtqResult.Exception Is Nothing) Then
                vtqText = vtqResult.Vtq.ToString()
            Else
                exceptionText = vtqResult.Exception.Message
            End If
 
            listViewItem.SubItems(1).Text = vtqText
            listViewItem.SubItems(2).Text = exceptionText
        Next
 
    End Sub

The project (zipped) is attached.

File Attachment:

File Name: ListView1.zip
File Size:15 KB


We probably have to do this iteratively: If this is not quite what you wanted and does not give you enough to start on your own, let me know which parts are missing, and I will provide further examples or guidance.
One thing that may not be addressed in this version: You mentioned that you want it to operate “asynchronously”.

There are at least two possible interpretations:
1. You want that OPC methods for asynchronous reading/writing are used, between the OPC client and the OPC server. This is already taken care: We use asynchronous methods whenever possible, by default (can be changed by a parameters passed to EasyDAClient).
2. You want the OPC operation appears asynchronous to your application – e.g. the Read would be performed while the user interface stays responsive, and the list view is updates upon the arrival of the data. Currently we do not give you API to do this (besides subscriptions which is a bit of different story), but it can be done using a separate thread. Is this what you wanted?

Best regards
Attachments:
Last edit: 01 Aug 2014 12:24 by support.

Please Log in or Create an account to join the conversation.

More
01 Aug 2014 12:11 #2122 by support
From: N.
Sent: Monday, July 28, 2014 10:05 PM
To: Zbynek Zahradnik
Subject: Re: OPC Labs Contact Form - opc to listview

Hi

It's a list view for windows form !

Basically if you could do a simple example involving multiple tags reading async and value/quality/time stamp into a list view that would be nice, also several items writing async to the data source!

...

Please Log in or Create an account to join the conversation.

More
01 Aug 2014 12:10 - 01 Aug 2014 12:10 #2121 by support
On 28 Jul 2014, at 20:56, "Zbynek Zahradnik" <...> wrote:
Dear Sir,
Thank you for your interest in our products.

We probably do not have a ready-made example directly with a ListView (BTW, is that a ListView for Windows Forms, or Web Forms?), but I am ready to work with you to resolve any issues you run into, or even perhaps create an example for you, if you can describe a bit more about the requirements.

...

Best regards,
Last edit: 01 Aug 2014 12:10 by support.

Please Log in or Create an account to join the conversation.

More
01 Aug 2014 12:10 #2120 by support
From: OPC Labs Contact Form - n.
Sent: Sunday, July 27, 2014 9:50 PM
...
Subject: OPC Labs Contact Form - opc to listview

...

I am wondering fdo you have any VB.Net examples showing your SDK working with a ListView and reading/writing asynchronous ?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.066 seconds