【发布时间】:2019-09-11 02:49:56
【问题描述】:
我正在使用带有 C# .NET 的 OPCSiemensDAAutomation dll 从 OPC Server 检索标签的值。我设法使用 QueryAvailableProperties() 和 GetItemProperties() 检索了这些值,但目标是为每个请求检索 500k 个标签值。
我已经测试了 100 个标签,代码在 45 秒内完成,多线程导致 100 个标签的小幅改进为 30 秒。以当前速度达到目标标签量需要 4 个多小时。有什么方法可以批量检索标签值并具有更好的性能?谢谢。
var opcServer = new OPCSiemensDAAutomation.OPCServer();
opcServer.Connect("PCS7.OPCDAServer.1");
ConcurrentBag<DataRow> myBag = new ConcurrentBag<DataRow>(dt.AsEnumerable().ToList());
Parallel.ForEach(myBag, data =>
{
if (count <= num)
{
int cnt;
Array propertyIds, descriptions, dataTypes, errors, vals;
try
{
opcServer.QueryAvailableProperties(data[0].ToString(), out cnt, out propertyIds, out descriptions, out dataTypes);
opcServer.GetItemProperties(data[0].ToString(), cnt, propertyIds, out vals, out errors);
Tags tag = new Tags();
tag.Id = data[0].ToString();
tag.Value = vals.GetValue(2).ToString();
tags.Add(tag);
Interlocked.Increment(ref count);
}
catch
{ }
}
});
【问题讨论】:
-
在 OPC DA 中获取属性并不是为了快速而设计的。您实际上需要数千个项目的所有属性,这将是非常不寻常的。为了什么? OPC DA 旨在快速处理实际项目值/质量/时间戳,您应该不使用属性。相反,您订阅,或者,如果它们不适合,则一次性阅读。
-
@ZbynekZ 感谢您的建议,我现在已经使用 SyncRead 进行了编码,但我面临这个“1073479672- OpcInvalidItemID:项目 ID 不符合服务器的语法”。添加 OPC 项时返回错误。我检查了标签 ID 是否与 OPC Scout 或其他工具中显示的相同。你能帮忙吗?
标签: c# .net opc siemens opc-da