终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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