使用OPC集合 [英] Using OPC Collections

查看:81
本文介绍了使用OPC集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好......

我正在编写ac#应用程序,它与OPC服务器进行通信,以便在标签之间读写数据。



我的问题是每次我想与它通信时都会创建OPC项目。

例如:

 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);





我在阅读时这样做和写作..



我知道这是错误的,可能导致我的OPC项目增长。



我需要一些创建OPC集合的帮助,然后我可以查找标签/项目,如果它们已经存在我只是继续,如果不是我将它们添加到集合中。



感谢任何帮助

解决方案

设置一个标志来判断标签/项目是否存在。所以你必须走出去来自OPC Items的sigle变量(有时我们称之为Object.Value)。只是一个snipet,尝试它。


我知道这已经晚了但是这里:

使用列表Generic.List< opc.da.itemidentifier> MyOPCItems = new System.Collections.Generic.List< opc.da.itemidentifier>
现在您可以在init例程期间添加到列表中,或者如果需要,可以从列表中删除项目。然后将项目添加到您的订阅Subscriptions.AddRange(MyOPCItems.ToArray());

要读取或写入类似的方法可以应用,因为项目存在,您可以创建您的项目值或项目从这个列表中也可以。
每个Opc.Da.ItemIdentifier中的
MyOPCItems中的ItemID



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



另一个你可以做的是Server.Subscriptions [n] .Items [],看看它是否存在于集合中服务器

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.
Eg:

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

解决方案

set up a flag to judge whether tags/items exist.so you have to "get out" the sigle variable from the OPC Items(sometimes we call it "Object.Value"). Just a snipet,try on it.


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.


这篇关于使用OPC集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆