OPC-UaFx 采样速度极慢

OPC-UaFx Sampling speed is extremely slow

我需要使用 OPC-UA 客户端以 50 赫兹的速率从 PLC S7 1500 实时读取数据。 到目前为止,我已经尝试了 3 个不同的库。其中 2 个我不知道如何使用,一个在速度方面表现不佳。

我试过 OPC Foundation 的 OPCFoundation.NetStandard.Opc.Ua,但无法确定创建会话所需的所有参数。我找到的唯一指南是他们 GitHub 中的一些示例,这些示例非常复杂 windows 形式的示例,我没能弄清楚如何使用它们:https://github.com/OPCFoundation/UA-.NETStandard.

我也尝试过 OPC Labs 的 QuickOPC,但收到了一个在我看来像证书异常的异常,我在互联网上几乎找不到任何相关信息。

到目前为止,最后一个效果最好:Opc.UaFx.Client by Traeger.de (https://opcua.traeger.de/en/). I managed to read single data, multiple data, and read them in loops, but the amount of time it takes the application to preform each read of about 1kb of data is about 750ms, way above what I need. I've tried to work with subscriptions according to their guide in here: https://wiki.traeger.de/en/software/sdk/opc-ua/net/client.development.guide。但它每 1 秒对订阅的节点进行一次采样,即使我配置了 SamplingInterval 属性 正如他们在指南中所说的那样。我认为还有 2 个 "interval" 属性:SamplingInterval 用于我订阅的每个项目,PublishingInterval 用于订阅本身,还有CurrentPublishingInterval,估计也是为了订阅,但是除此之外我也改不了,一直在1000ms,只能改大PublishingInterval,但没有找到任何方法让它变小,我想这就是我需要的。

这是我在 OPC UaFx 中所做的代码:

private static Stopwatch stopwatch1 = new Stopwatch();

static void Main(string[] args)
{

    using (var client = new OpcClient("opc.tcp://192.168.0.1:4840/"))
    {
        client.Connect();
        var node = client.BrowseNode(new OpcNodeId("\"communication data\".\"int array to send\"", 3));

        List<OpcNodeId> nodeList = new List<OpcNodeId>();
        OpcNodeId[] nodes;
        Browse(node, nodeList);
        Debug.WriteLine("done loading");
        nodes = nodeList.ToArray();
        stopwatch1.Start();

        SampleaAndMessureWithSubscription(client, nodes);

        Console.Read();
    };

}

private static void SampleaAndMessureWithSubscription(OpcClient client, OpcNodeId[] nodes)
{
    OpcSubscription subscription = client.SubscribeNodes();
    for (int i = 0; i < nodes.Length; i++)
    {
        var item = new OpcMonitoredItem(nodes[i], OpcAttribute.Value);
        item.DataChangeReceived += HandleDataChanged;
        item.Tag = i;
        item.SamplingInterval = 20;                

        subscription.AddMonitoredItem(item);
    }
    subscription.PublishingInterval = 20;
    subscription.ApplyChanges();
}

非常感谢任何帮助,无论是好的 OPC 库和资源,还是 OPC UaFx 问题的解决方案。 非常感谢!

如果您尝试读取属于 PLC 中 UDT 一部分的标签,请确保您从 UDT 根部的节点读取结构化值,而不是每个单独节点的原子值。

我怀疑客户端库是您的问题所在。 S7-1500 中的 OPC UA 服务器速度不是很快。我不知道它是否能够进行 50hz 采样。检查您的订阅和项目创建后修改后的发布和采样间隔。