Click here to Skip to main content
15,796,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys...
I am coding a c# application which communicates with an OPC server to read and write data to and from tags.

My problem is that I create the OPC "items" each time I want to communicate with it.
OPCServer opcS = new OPCServer();
OPCGroups opcGx = opcS.OPCGroups;
OPCGroup opcG = opcGx.Add(Type.Missing);
OPCItems opcIx = opcG.OPCItems;
OPCItem opcI = opcIx.AddItem("Channel1.Device1.Tag1", 1);

I do this when reading and writing..

I know this is wrong and can cause my OPC items to "grow".

I need some help with creating an OPC collection, in which I can then look for the tags/items if they already exist i just continue, if they don't I add them into the collection.

Any assistance is appreciated
Updated 26-Jul-11 23:42pm
Marziyeh Eslampanah 4-Mar-13 2:07am    
how can i browse all leafs in opc server?by opcAutomation.dll?

set up a flag to judge whether tags/items you have to "get out" the sigle variable from the OPC Items(sometimes we call it "Object.Value"). Just a snipet,try on it.
Share this answer
I know this is late but here goes:
use a list Generic.List<opc.da.itemidentifier> MyOPCItems = new System.Collections.Generic.List<opc.da.itemidentifier>
now you can add to the list during an init routine, or remove items from the list if you want. Then to Add items to your subscription Subscriptions.AddRange(MyOPCItems.ToArray());
To read them or write them similar methods can be applied, because the items exist, you can create your itemvalues or items from this list as well.
for each Opc.Da.ItemIdentifier ItemID in MyOPCItems

Opc.Da.ItemValue myNewItemValue = new Opc.Da.ItemValue(ItemID);

The other you can do is Server.Subscriptions[n].Items[] , and see if it exists in the collection on the server.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900