using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using BPASmartClient.Helper; using BPASmartClient.Model; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.ViewModel { public class SystemSetViewModel : ObservableObject { public SystemSetViewModel() { if (SaveInfoCommand == null) { SaveInfoCommand = new Action(() => { List values = new List(); values.Clear(); List bools = new List(); bools.Clear(); for (int i = 0; i < Json.Data.parSets.Count; i++) { values.Clear(); values.Add(Json.Data.parSets[i].Minute); values.Add(Json.Data.parSets[i].Second); bools.Add(Json.Data.parSets[i].IsShield); //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (i * 6)}"), WriteType.HoldingRegisters, values.ToArray()); } //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M260.0"), WriteType.Coils, bools.ToArray()); }); } } public ObservableCollection parSets { get; set; } = Json.Data.parSets; public Action SaveInfoCommand { get; set; } } }