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.

using dynamic subscriptions in data grids

More
23 Sep 2010 13:06 #80 by support
I suggest you have a look at HmiScreen and SubscribeToMany projects in the <a href="/LinkClick.aspx?fileticket=4oAFG9G67Rs%3d&tabid=195">Bonus Pack. They both use similar techniques to those you need, except that the subscribe/unsubscribe is not that dynamic as you plan to do with the grid.
For example, the following snippet from SubscribeToMany illustrates a lot:
private void startButton_Click(object sender, EventArgs e)
{
int numberOfItems = (int)this.numberOfItemsNumericUpDown.Value;

this.startButton.Enabled = false;
this.numberOfItemsNumericUpDown.Enabled = false;

var argumentArray = new DAItemGroupArguments[numberOfItems];
for (int i = 0; i < numberOfItems; i++)
{
var listViewItem = new ListViewItem();
this.valuesListView.Items.Add(listViewItem);
int copy = (i / 100) + 1;
int phase = (i%100) + 1;
string itemID = String.Format("Simulation.Incrementing.Copy_{0}.Phase_{1}", copy, phase);
argumentArray = new DAItemGroupArguments("", "OPCLabs.KitServer.2", itemID, 50, listViewItem);
}

this.changeCount = 0;
this.startTickCount = Environment.TickCount;
this.timer1.Start();

this.easyDAClient1.SubscribeMultipleItems(argumentArray);

}

private void easyDAClient1_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
{
this.changeCount++;

var listViewItem = (ListViewItem)e.State;
string text;
if (e.Exception != null) text = "*Error*";
else text = e.Vtq.DisplayValue();
listViewItem.Text = text;
}


In startButton_Click, you can see how listViewItem is used as last ('state') argument of DAItemGroupArguments constructor; these objects then make up the array that is passed to SubscribeMultipleItems. In easyDAClient1_ItemChanged, you can see how the 'state' is typecasted back to the control reference (which, I suppose, will be a grid cell reference in your case), and the control is updated with the new value converted to string.

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

More
23 Sep 2010 12:45 #79 by support
Let's say you need to update data in each row of your grid. Whenever you add a row to the grid, you should call SubscribeMultipleItems, and subscribe to those 7 tags needed for that row. In order to make the event handling easy, you can pass a reference to the particular grid cells that need be updated to the SubscribeMultipleItems call (in the 'State' property of DAItemGroupArguments object). You will get back an array of handles that need be stored somewhere, possibly with the grid row, in case you want to delete the row later and consequently unsubscribe (you would use UnsubscribeMultipleItems method for this, passing it the handles).
Assuming that you have hooked an event handler for ItemChanged event, the handler code can then simply take the 'State' property from the event arguments passed in, take it as a reference to the grid cell that needs to be updated, and format the string form the value that came with the event.
I hope this helps. I currently do not have any readily available example code with System.Windows.Forms.DataGridView, but in case you run into real problems, we can make one. I also think that a similar example with different kind of WinForms control may also help you, and I will try to locate it and send to you a bit later.

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

More
23 Sep 2010 08:51 #78 by support
From: W.
Sent: Wed 9/22/2010 10:30 PM
To: Zbynek Zahradnik
Subject: RE: EasyOPC-DA.NET 5.0 - easyDAClient1.SubscribeMultipleItems




Hi Zbynek.

I have another question on functionality and I hope I can word it in an understandable way. [...]

We have various servers (machines) with varying numbers of meters. I need to grab a specific seven tags [...] for a subset of the meters on the different machines and display them all at once (preferably in a windows form data grid view control). Not knowing how many meters for each situation there might be, how can I subscribe to multiple items, in the data grid, all at once? For example, [...] there would be data (7 tags) for 12 meters displayed in my data grid, and this would need to be subscribed data so that it would update automatically.

I didn’t know if you might have any code examples using dynamic subscriptions in data grids (System.Windows.Forms.DataGridView).

Thanks very much.


W.


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

Moderators: support
Time to create page: 0.047 seconds