iioter / iotgateway

A cross-platform IoT gateway based on .net6. Through visual configuration, you can easily connect to any of your devices and systems (such as PLC, barcode scanner, CNC, database, serial device, host computer, OPC Server, OPC UA Server, Mqtt Server, etc.), so as to interact with Thingsboard, IoTSharp or Your own IoT platform for two-way data communication. Provide a simple driver development interface; of course, edge computing can also be performed.

Home Page:http://iotgateway.net/docs/enterprise/intro/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

西门子S7驱动使用ReadMultipleVars代替Read方法

xiaodaidi1 opened this issue · comments

目前逻辑是按照DeviceVariables循环串行读取,在个数多的情况下,性能会明显变慢
可以使用ReadMultipleVars方法批量读取数据加快响应,提高吞吐量

                var pageSize = plcPageSize;
                var pages = (ioarg.Count / pageSize) + 1;
                for (int pageIndex = 0; pageIndex < pages; pageIndex++)
                {
                    var source = ioarg.Skip(pageIndex * pageSize).Take(pageSize).ToList();
                    var items = source.Select(x =>
                    {
                        var dataItem = S7.Net.Types.DataItem.FromAddress(x.arg.Address);
                        return dataItem;
                    }).ToList();
                    plc.ReadMultipleVars(items);
                    for (int i = 0; i < source.Count; i++)
                    {
                        source[i].Value = items[i].Value;
                    }
                }
commented

感谢你的建议。

  • 方便的话可以提交一个pr吗?