终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

157 lines
7.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BPASmartClient.CustomResource;
  8. using BPASmartClient.Helper;
  9. using BPASmartClient.Model;
  10. using BPASmartClient.MorkS.Model;
  11. using Microsoft.Toolkit.Mvvm.ComponentModel;
  12. using Microsoft.Toolkit.Mvvm.Input;
  13. using Org.BouncyCastle.Utilities;
  14. namespace BPASmartClient.MorkS.ViewModel
  15. {
  16. public class ParSetViewModel : ObservableObject
  17. {
  18. public ParSetViewModel()
  19. {
  20. SaveInfoCommand = new RelayCommand(SaveSettingData);
  21. SoupSootForwardCommand = new RelayCommand(SoupSootForward);
  22. SoupSootBackwardCommand = new RelayCommand(SoupSootBackward);
  23. SoupSootStopCommand = new RelayCommand(SoupSootStop);
  24. ActionManage.GetInstance.Register(SaveSettingData, "初始化设定煮面时间");
  25. CommandStart = new RelayCommand(async () =>
  26. {
  27. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M0.6", Value = true });
  28. await Task.Delay((int)DelayTime * 1000);
  29. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M0.6", Value = false });
  30. });
  31. if (Json<MorksPar>.Data.DishLibraryParSets.Count < 5)
  32. {
  33. Json<MorksPar>.Data.DishLibraryParSets.Clear();
  34. for (int i = 0; i < 5; i++)
  35. {
  36. Json<MorksPar>.Data.DishLibraryParSets.Add(new ParSet()
  37. {
  38. Minute = 2,
  39. Second = 0,
  40. TextBlockContext = $"{i + 1}"
  41. });
  42. }
  43. }
  44. //VoicePlayTest = new RelayCommand(() => {
  45. // VoiceAPI.Speak(new Random().Next(1,100).ToString());
  46. //});
  47. }
  48. public RelayCommand SaveInfoCommand { get; set; }
  49. public RelayCommand CommandStart { get; set; }
  50. public RelayCommand SoupSootForwardCommand { get; set; }
  51. public RelayCommand SoupSootBackwardCommand { get; set; }
  52. public RelayCommand SoupSootStopCommand { get; set; }
  53. #region 时间设定
  54. /// <summary>
  55. /// 间隔时间设定
  56. /// </summary>
  57. public ushort IntervalTime { get { return Json<MorksPar>.Data.IntervalTime; } set { Json<MorksPar>.Data.IntervalTime = value; OnPropertyChanged(); } }
  58. /// <summary>
  59. /// 反转抽汤时间设定
  60. /// </summary>
  61. public ushort BackwardSoupSootTime { get { return Json<MorksPar>.Data.BackwardSoupSootTime; } set { Json<MorksPar>.Data.BackwardSoupSootTime = value; OnPropertyChanged(); } }
  62. /// <summary>
  63. /// 反转过后再次出汤时间设定
  64. /// </summary>
  65. public ushort BackwardedOutSoupTime { get { return Json<MorksPar>.Data.BackwardedOutSoupTime; } set { Json<MorksPar>.Data.BackwardedOutSoupTime = value; OnPropertyChanged(); } }
  66. /// <summary>
  67. /// 未反转抽汤下时间设定
  68. /// </summary>
  69. public ushort UnBackwardSoupSootTime { get { return Json<MorksPar>.Data.UnBackwardSoupSootTime; } set { Json<MorksPar>.Data.UnBackwardSoupSootTime = value; OnPropertyChanged(); } }
  70. //public RelayCommand VoicePlayTest { get; set; }
  71. /// <summary>
  72. /// 加汤时间设置
  73. /// </summary>
  74. //public ushort AddSoup { get { return Json<MorksPar>.Data.AddSoupTime; } set { Json<MorksPar>.Data.AddSoupTime = value; OnPropertyChanged(); } }
  75. #endregion
  76. public ObservableCollection<ParSet> parSets { get; set; } = Json<MorksPar>.Data.parSets;
  77. public int OpenUseNumber { get { return Json<MorksPar>.Data.InvertedNoodles_OpenBusyNum; } set { Json<MorksPar>.Data.InvertedNoodles_OpenBusyNum = value; OnPropertyChanged(); } }
  78. public ObservableCollection<ParSet> DishLibraryParSets { get; set; } = Json<MorksPar>.Data.DishLibraryParSets;
  79. public float DelayTime { get { return _DelayTime; } set { _DelayTime = value; OnPropertyChanged(); } }
  80. private float _DelayTime;
  81. private void SaveSettingData()
  82. {
  83. List<ushort> values = new List<ushort>();
  84. values.Clear();
  85. List<bool> bools = new List<bool>();
  86. bools.Clear();
  87. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  88. {
  89. values.Clear();
  90. values.Add(Json<MorksPar>.Data.parSets[i].Minute);
  91. values.Add(Json<MorksPar>.Data.parSets[i].Second);
  92. bools.Add(Json<MorksPar>.Data.parSets[i].IsShield);
  93. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = $"VW{116 + (i * 6)}", Value = values.ToArray() });
  94. }
  95. //ushort times = Convert.ToUInt16(Json<MorksPar>.Data.AddSoupTime * 10);
  96. //ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = times });
  97. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = (ushort)(UnBackwardSoupSootTime * 10) });
  98. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2284", Value = (ushort)(IntervalTime * 10) });
  99. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2286", Value = (ushort)(BackwardSoupSootTime * 10) });
  100. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2288", Value = (ushort)(BackwardedOutSoupTime * 10) });
  101. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M260.0", Value = bools.ToArray() });
  102. Json<MorksPar>.Save();
  103. //WriteTimeSet(IntervalTime);
  104. //WriteTimeSet(BackwardSoupSootTime);
  105. //WriteTimeSet(BackwardedOutSoupTime);
  106. //WriteTimeSet(UnBackwardSoupSootTime);
  107. }
  108. private void WriteTimeSet(float TimePar)
  109. {
  110. ushort paras = Convert.ToUInt16(TimePar * 10);
  111. ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = "VW2282", Value = paras });
  112. }
  113. private async void SoupSootForward()
  114. {
  115. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.0", Value = true });
  116. await Task.Delay((int)DelayTime * 1000);
  117. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.0", Value = false });
  118. }
  119. private async void SoupSootBackward()
  120. {
  121. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.1", Value = true });
  122. await Task.Delay((int)DelayTime * 1000);
  123. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.1", Value = false });
  124. }
  125. private async void SoupSootStop()
  126. {
  127. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.2", Value = true });
  128. await Task.Delay((int)DelayTime * 1000);
  129. ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M1.2", Value = false });
  130. }
  131. }
  132. }