Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xiaodaidi1 opened this issue Apr 18, 2023 · 1 comment
Open

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

xiaodaidi1 opened this issue Apr 18, 2023 · 1 comment

Comments

@xiaodaidi1
Copy link

目前逻辑是按照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;
                    }
                }
@iioter
Copy link
Owner

iioter commented Aug 23, 2023

感谢你的建议。

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants