终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DebugViewModel.cs 12 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.MorkT.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 RelayCommand Button_LebaiDOuputCommand { get; set; }
  122. public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
  123. private int _pwmInputNumber = 1;
  124. public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
  125. private int _choosePWM = 1;
  126. public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
  127. private int _mcuDO_CH = 1;
  128. public int Lebai_DO_CH { get { return _lebaiDO_CH; } set { _lebaiDO_CH = value; OnPropertyChanged(); } }
  129. private int _lebaiDO_CH = 1;
  130. public int Lebai_DO_Value { get { return _lebaiDO_Value; } set { _lebaiDO_Value = value; OnPropertyChanged(); } }
  131. private int _lebaiDO_Value = 1;
  132. private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
  133. private int[] _diCH = new int[8];
  134. public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } }
  135. private bool _mcu_DO_Valuer = true;
  136. public bool MCU_DI0 { get { return _mcu_DI0; }set { _mcu_DI0 = value;OnPropertyChanged(); } }
  137. private bool _mcu_DI0 = true;
  138. public bool MCU_DI1 { get { return _mcu_DI1; } set { _mcu_DI1 = value; OnPropertyChanged(); } }
  139. private bool _mcu_DI1 = true;
  140. public bool MCU_DI2 { get { return _mcu_DI2; } set { _mcu_DI2 = value; OnPropertyChanged(); } }
  141. private bool _mcu_DI2 = true;
  142. public bool MCU_DI3 { get { return _mcu_DI3; } set { _mcu_DI3 = value; OnPropertyChanged(); } }
  143. private bool _mcu_DI3 = true;
  144. public bool MCU_DI4 { get { return _mcu_DI4; } set { _mcu_DI4 = value; OnPropertyChanged(); } }
  145. private bool _mcu_DI4 = true;
  146. public bool MCU_DI5 { get { return _mcu_DI5; } set { _mcu_DI5 = value; OnPropertyChanged(); } }
  147. private bool _mcu_DI5 = true;
  148. public bool MCU_DI6 { get { return _mcu_DI6; } set { _mcu_DI6 = value; OnPropertyChanged(); } }
  149. private bool _mcu_DI6 = true;
  150. public bool MCU_DI7 { get { return _mcu_DI7; } set { _mcu_DI7 = value; OnPropertyChanged(); } }
  151. private bool _mcu_DI7 = true;
  152. /// <summary>
  153. /// 单片机舵机输出
  154. /// </summary>
  155. private void Button_McuOutput()
  156. {
  157. string sChoosePWM =Convert.ToString(MCU_PWM_CH+1);
  158. new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish();
  159. }
  160. /// <summary>
  161. /// 单片机DO输出
  162. /// </summary>
  163. private void Button_McuDOutput()
  164. {
  165. string sChooseDO = Convert.ToString(MCU_DO_CH + 1);
  166. new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish();
  167. }
  168. /// <summary>
  169. /// 乐白的DO输出
  170. /// </summary>
  171. private void Button_LebaiDOutput()
  172. {
  173. int sChooseDO = Convert.ToInt16(Lebai_DO_CH);
  174. bool lebai_DO_Value = Convert.ToInt16(Lebai_DO_Value) == 0;
  175. new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = sChooseDO, Value = lebai_DO_Value }.Publish();
  176. }
  177. #endregion
  178. /// <summary>
  179. /// 设备ID
  180. /// </summary>
  181. public int DeviceId { get; set; }
  182. /// <summary>
  183. /// 设备数据
  184. /// </summary>
  185. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  186. public DebugViewModel()
  187. {
  188. Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
  189. Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
  190. Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
  191. Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
  192. Button_MCUOuputCommand = new RelayCommand(Button_McuOutput);
  193. Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput);
  194. Button_LebaiDOuputCommand = new RelayCommand(Button_LebaiDOutput);
  195. foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
  196. {
  197. Coffees.Add(code.ToString());
  198. }
  199. SelectedCoffee = Coffees[0];
  200. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  201. {
  202. CoffeeCmds.Add(code.ToString());
  203. }
  204. SelectedCoffeeCmd = CoffeeCmds[0];
  205. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  206. {
  207. if (device.Name == "MorkT") DeviceId = device.DeviceId
  208. ;
  209. });
  210. ThreadManage.GetInstance().StartLong(new Action(() =>
  211. {
  212. variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  213. if (variableMonitors != null && variableMonitors.Count > 0)
  214. {
  215. RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  216. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  217. JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  218. MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  219. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  220. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  221. AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  222. Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  223. CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  224. }
  225. Thread.Sleep(500);
  226. }), "MorkT-状态刷新");
  227. }
  228. }