终端一体化运控平台
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.
 
 
 

225 rivejä
9.4 KiB

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