终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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