终端一体化运控平台
Você não pode selecionar mais de 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.
 
 
 

225 linhas
9.5 KiB

  1. using BPASmartClient.Business;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.DRCoffee;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.GSIceCream;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.LebaiRobot;
  8. using BPASmartClient.Message;
  9. using BPASmartClient.Model;
  10. using BPASmartClient.Model.乐白机器人;
  11. using BPASmartClient.Model.冰淇淋.Enum;
  12. using BPASmartClient.Model.单片机;
  13. using BPASmartClient.Model.单片机.Enum;
  14. using BPASmartClient.Model.咖啡机.Enum;
  15. using Microsoft.Toolkit.Mvvm.ComponentModel;
  16. using Microsoft.Toolkit.Mvvm.Input;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Collections.ObjectModel;
  20. using System.Linq;
  21. using System.Threading;
  22. namespace BPASmartClient.MorkTJAKAJC.ViewModel;
  23. public class DebugViewModel : ObservableObject
  24. {
  25. #region 乐白机器人
  26. /// <summary>
  27. /// 乐白机器人连接状态
  28. /// </summary>
  29. public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
  30. private string _robotConnected { get; set; }
  31. /// <summary>
  32. /// 乐白机器人的模式状态
  33. /// </summary>
  34. public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
  35. private string _robotMode { get; set; }
  36. /// <summary>
  37. /// 机器人控制指令
  38. /// </summary>
  39. public RelayCommand<object> Button_RobotControlCommand { get; set; }
  40. /// <summary>
  41. /// 机器人控制
  42. /// </summary>
  43. /// <param name="o"></param>
  44. private void Button_RobotControl(object o)
  45. {
  46. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
  47. }
  48. #endregion
  49. #region 果汁机
  50. /// <summary>
  51. /// 果汁机的连接状态
  52. /// </summary>
  53. public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } }
  54. private string _JuicerConnected { get; set; }
  55. /// <summary>
  56. /// 果汁机的状态
  57. /// </summary>
  58. public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } }
  59. private string _JuicerState { get; set; }
  60. #endregion
  61. #region 咖啡机
  62. /// <summary>
  63. /// 咖啡机连接状态
  64. /// </summary>
  65. public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
  66. private string _coffeeConnected { get; set; }
  67. /// <summary>
  68. /// 咖啡机状态
  69. /// </summary>
  70. public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
  71. private string _coffeeStatus { get; set; }
  72. /// <summary>
  73. /// 应用状态
  74. /// </summary>
  75. public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } }
  76. private string _appStatus { get; set; }
  77. /// <summary>
  78. /// 告警
  79. /// </summary>
  80. public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
  81. public string _warning { get; set; }
  82. /// <summary>
  83. /// 故障信息
  84. /// </summary>
  85. public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } }
  86. public string _caffeeFault { get; set; }
  87. public List<string> Coffees { get; set; } = new List<string>();
  88. public string SelectedCoffee { get; set; }
  89. public List<string> CoffeeCmds { get; set; } = new List<string>();
  90. public string SelectedCoffeeCmd { get; set; }
  91. /// <summary>
  92. /// 制作咖啡
  93. /// </summary>
  94. public RelayCommand Button_MakeCoffeeCommand { get; set; }
  95. /// <summary>
  96. /// 停止制作咖啡
  97. /// </summary>
  98. public RelayCommand Button_StopMakeCoffeCommand { get; set; }
  99. /// <summary>
  100. /// 咖啡模式设置
  101. /// </summary>
  102. public RelayCommand Button_CoffeeModeSetCommand { get; set; }
  103. private void Button_MakeCoffee()
  104. {
  105. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
  106. }
  107. private void Button_StopMakeCoffe()
  108. {
  109. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
  110. }
  111. private void Button_CoffeeModeSet()
  112. {
  113. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)});
  114. }
  115. #endregion
  116. #region 单片机
  117. public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } }
  118. private string _mcuConnected { get; set; }
  119. public RelayCommand Button_MCUOuputCommand { get; set; }
  120. public RelayCommand Button_MCUDOuputCommand { get; set; }
  121. public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
  122. private int _pwmInputNumber = 1;
  123. public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
  124. private int _choosePWM = 1;
  125. public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
  126. private int _mcuDO_CH = 1;
  127. private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
  128. private int[] _diCH = new int[8];
  129. public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } }
  130. private bool _mcu_DO_Valuer = true;
  131. private void Button_McuOutput()
  132. {
  133. string sChoosePWM =Convert.ToString(MCU_PWM_CH+1);
  134. new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish();
  135. }
  136. private void Button_McuDOutput()
  137. {
  138. string sChooseDO = Convert.ToString(MCU_DO_CH + 1);
  139. new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish();
  140. }
  141. #endregion
  142. /// <summary>
  143. /// 设备ID
  144. /// </summary>
  145. public int DeviceId { get; set; }
  146. /// <summary>
  147. /// 设备数据
  148. /// </summary>
  149. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  150. public DebugViewModel()
  151. {
  152. Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
  153. Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
  154. Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
  155. Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
  156. Button_MCUOuputCommand = new RelayCommand(Button_McuOutput);
  157. Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput);
  158. foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
  159. {
  160. Coffees.Add(code.ToString());
  161. }
  162. SelectedCoffee = Coffees[0];
  163. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  164. {
  165. CoffeeCmds.Add(code.ToString());
  166. }
  167. SelectedCoffeeCmd = CoffeeCmds[0];
  168. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  169. {
  170. if (device.Name == "MorkT") DeviceId = device.DeviceId
  171. ;
  172. });
  173. ThreadManage.GetInstance().StartLong(new Action(() =>
  174. {
  175. variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  176. if (variableMonitors != null && variableMonitors.Count > 0)
  177. {
  178. RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  179. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  180. JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  181. MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  182. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  183. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  184. AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  185. Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  186. CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  187. }
  188. Thread.Sleep(500);
  189. }), "MorkT-状态刷新");
  190. }
  191. }