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.
- Forum
- Discussions
- QuickOPC-Classic in .NET
- Reading, Writing, Subscriptions, Property Access
- VB.NET example - OPC data with ListView
VB.NET example - OPC data with ListView
Please Log in or Create an account to join the conversation.
- neilcooley
- Offline
- Platinum Member
- Posts: 33
- Thank you received: 3
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.
VS project (zipped):
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
Please Log in or Create an account to join the conversation.
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.
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.
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.
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
Please Log in or Create an account to join the conversation.
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.
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,
Please Log in or Create an account to join the conversation.
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.
- Forum
- Discussions
- QuickOPC-Classic in .NET
- Reading, Writing, Subscriptions, Property Access
- VB.NET example - OPC data with ListView