using HMI.Core.Setting; using PLCHelper; using Plugin.CurrentSensorControl.Entity; using System.Windows.Controls; namespace Plugin.CurrentSensorControl { /// /// BurnInOvenCollection.xaml 的交互逻辑 /// public partial class BurnInOvenCollection : UserControl { private int rowCount; private int colCount; private int cellCount; private BurnInOven[] ovens; private BaseConfig config; public BurnInOvenCollection() { config = BaseConfig.Instance; InitializeComponent(); InitMainGrid(); } public void InitMainGrid() { S7Context.Init(SystemSetting.Instance.PlcIp, SystemSetting.Instance.PlcPort); this.rowCount = config.Row; this.colCount = config.Column; ovens = new BurnInOven[this.rowCount * this.colCount]; if (config.CellCount < 0) { this.cellCount = rowCount * colCount; } else { this.cellCount = config.CellCount; } for (int r = 0; r < rowCount; r++) { RowDefinition row = new RowDefinition(); mainGrid.RowDefinitions.Add(row); } for (int c = 0; c < colCount; c++) { ColumnDefinition col = new ColumnDefinition(); mainGrid.ColumnDefinitions.Add(col); } string[] names = config.NameStr.Split(','); for (int n = 0; n < cellCount; n++) { string name = n < names.Length ? names[n] : ""; BurnInOven child = new BurnInOven(n); child.Header = name; mainGrid.Children.Add(child); ovens[n] = child; int row = n / colCount; int col = n % colCount; Grid.SetRow(child, row); Grid.SetColumn(child, col); } } public void Refresh() { try { for (int i = 0; i < ovens.Length; i++) { var oven = ovens[i]; oven.Refresh(); } //Task[] allTask = new Task[ovens.Length]; //for (int i = 0; i < ovens.Length; i++) //{ // var oven = ovens[i]; // var task = Task.Factory.StartNew(() => // { // oven.Refresh(); // }); // allTask[i] = task; //} //Task.WaitAll(allTask); } catch (Exception ex) { } } } }