using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using BPASmartClient.CustomResource; using BPASmartClient.Helper; using BPASmartClient.Model; using BPASmartClient.MorkS.Model; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using Org.BouncyCastle.Utilities; namespace BPASmartClient.MorkS.ViewModel { public class ParSetViewModel : ObservableObject { public ParSetViewModel() { SaveInfoCommand = new RelayCommand(SaveSettingData); SoupSootForwardCommand = new RelayCommand(SoupSootForward); SoupSootBackwardCommand = new RelayCommand(SoupSootBackward); SoupSootStopCommand = new RelayCommand(SoupSootStop); ActionManage.GetInstance.Register(SaveSettingData, "初始化设定煮面时间"); CommandStart = new RelayCommand(async () => { ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M0.6", Value = true }); await Task.Delay((int)DelayTime * 1000); ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M0.6", Value = false }); }); if (Json.Data.DishLibraryParSets.Count < 5) { Json.Data.DishLibraryParSets.Clear(); for (int i = 0; i < 5; i++) { Json.Data.DishLibraryParSets.Add(new ParSet() { Minute = 2, Second = 0, TextBlockContext = $"{i + 1}" }); } } //VoicePlayTest = new RelayCommand(() => { // VoiceAPI.Speak(new Random().Next(1,100).ToString()); //}); } public RelayCommand SaveInfoCommand { get; set; } public RelayCommand CommandStart { get; set; } public RelayCommand SoupSootForwardCommand { get; set; } public RelayCommand SoupSootBackwardCommand { get; set; } public RelayCommand SoupSootStopCommand { get; set; } #region 时间设定 /// /// 间隔时间设定 /// public ushort IntervalTime { get { return Json.Data.IntervalTime; } set { Json.Data.IntervalTime = value; OnPropertyChanged(); } } /// /// 反转抽汤时间设定 /// public ushort BackwardSoupSootTime { get { return Json.Data.BackwardSoupSootTime; } set { Json.Data.BackwardSoupSootTime = value; OnPropertyChanged(); } } /// /// 反转过后再次出汤时间设定 /// public ushort BackwardedOutSoupTime { get { return Json.Data.BackwardedOutSoupTime; } set { Json.Data.BackwardedOutSoupTime = value; OnPropertyChanged(); } } /// /// 未反转抽汤下时间设定 /// public ushort UnBackwardSoupSootTime { get { return Json.Data.UnBackwardSoupSootTime; } set { Json.Data.UnBackwardSoupSootTime = value; OnPropertyChanged(); } } //public RelayCommand VoicePlayTest { get; set; } /// /// 加汤时间设置 /// //public ushort AddSoup { get { return Json.Data.AddSoupTime; } set { Json.Data.AddSoupTime = value; OnPropertyChanged(); } } #endregion public ObservableCollection parSets { get; set; } = Json.Data.parSets; public int OpenUseNumber { get { return Json.Data.InvertedNoodles_OpenBusyNum; } set { Json.Data.InvertedNoodles_OpenBusyNum = value; OnPropertyChanged(); } } public ObservableCollection DishLibraryParSets { get; set; } = Json.Data.DishLibraryParSets; public float DelayTime { get { return _DelayTime; } set { _DelayTime = value; OnPropertyChanged(); } } private float _DelayTime; private void SaveSettingData() { 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); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = $"VW{116 + (i * 6)}", Value = values.ToArray() }); } //ushort times = Convert.ToUInt16(Json.Data.AddSoupTime * 10); //ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = times }); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = (ushort)(UnBackwardSoupSootTime * 10) }); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2284", Value = (ushort)(IntervalTime * 10) }); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2286", Value = (ushort)(BackwardSoupSootTime * 10) }); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2288", Value = (ushort)(BackwardedOutSoupTime * 10) }); ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M260.0", Value = bools.ToArray() }); Json.Save(); //WriteTimeSet(IntervalTime); //WriteTimeSet(BackwardSoupSootTime); //WriteTimeSet(BackwardedOutSoupTime); //WriteTimeSet(UnBackwardSoupSootTime); } private void WriteTimeSet(float TimePar) { ushort paras = Convert.ToUInt16(TimePar * 10); ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = paras }); } private async void SoupSootForward() { ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.0", Value = true }); await Task.Delay((int)DelayTime * 1000); ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.0", Value = false }); } private async void SoupSootBackward() { ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.1", Value = true }); await Task.Delay((int)DelayTime * 1000); ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.1", Value = false }); } private async void SoupSootStop() { ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.2", Value = true }); await Task.Delay((int)DelayTime * 1000); ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.2", Value = false }); } } }