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

327 linhas
14 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.MorkT.ViewModel
  23. {
  24. public class DebugViewModel : ObservableObject
  25. {
  26. #region 乐白机器人
  27. /// <summary>
  28. /// 乐白机器人连接状态
  29. /// </summary>
  30. public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
  31. private string _robotConnected { get; set; }
  32. /// <summary>
  33. /// 乐白机器人的模式状态
  34. /// </summary>
  35. public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
  36. private string _robotMode { get; set; }
  37. /// <summary>
  38. /// 机器人控制指令
  39. /// </summary>
  40. public RelayCommand<object> Button_RobotControlCommand { get; set; }
  41. /// <summary>
  42. /// 机器人控制
  43. /// </summary>
  44. /// <param name="o"></param>
  45. public RelayCommand Button_SetValueCommand { get; set; }
  46. private void Button_SetValue()
  47. {
  48. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  49. }
  50. private void Button_RobotControl(object o)
  51. {
  52. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
  53. }
  54. #endregion
  55. #region 冰淇淋机器
  56. /// <summary>
  57. /// 制作冰淇淋
  58. /// </summary>
  59. public RelayCommand Button_MakeIceCreamCommand { get; set; }
  60. /// <summary>
  61. /// 选择冰淇淋模式
  62. /// </summary>
  63. public RelayCommand Button_SetIceCreamModelCommand { get; set; }
  64. /// <summary>
  65. /// 冰淇淋连接状态
  66. /// </summary>
  67. public string IceCreamConnected { get { return _iceCreamConnected; } set { _iceCreamConnected = value; OnPropertyChanged(); } }
  68. private string _iceCreamConnected { get; set; }
  69. /// <summary>
  70. /// 预冷温度
  71. /// </summary>
  72. public string YLWD { get { return _yLWD; } set { _yLWD = value; OnPropertyChanged(); } }
  73. private string _yLWD { get; set; }
  74. /// <summary>
  75. /// 回气温度
  76. /// </summary>
  77. public string HQWD { get { return _hQWD; } set { _hQWD = value; OnPropertyChanged(); } }
  78. private string _hQWD { get; set; }
  79. /// <summary>
  80. /// 环境温度
  81. /// </summary>
  82. public string HJWD { get { return _hJWD; } set { _hJWD = value; OnPropertyChanged(); } }
  83. private string _hJWD { get; set; }
  84. /// <summary>
  85. /// 电流
  86. /// </summary>
  87. public string DL { get { return _DL; } set { _DL = value; OnPropertyChanged(); } }
  88. private string _DL { get; set; }
  89. /// <summary>
  90. /// 电压
  91. /// </summary>
  92. public string DY { get { return _dy; } set { _dy = value; OnPropertyChanged(); } }
  93. private string _dy { get; set; }
  94. /// <summary>
  95. /// 当前模式
  96. /// </summary>
  97. public string CurrentMode { get { return _CurrentMode; } set { _CurrentMode = value; OnPropertyChanged(); } }
  98. private string _CurrentMode;
  99. /// <summary>
  100. /// 故障
  101. /// </summary>
  102. public string IceCreamFault { get { return _IceCreamFault; } set { _IceCreamFault = value; OnPropertyChanged(); } }
  103. private string _IceCreamFault { get; set; }
  104. /// <summary>
  105. /// 成型比
  106. /// </summary>
  107. public string CXB { get { return _cXB; } set { _cXB = value; OnPropertyChanged(); } }
  108. private string _cXB { get; set; }
  109. /// <summary>
  110. /// 打料完成状态
  111. /// </summary>
  112. public string DLCompleted { get { return _dLCompleted; } set { _dLCompleted = value; OnPropertyChanged(); } }
  113. private string _dLCompleted { get; set; }
  114. public List<string> IceCreamModes { get; set; } = new List<string>();
  115. public string SelecteIceCreamdMode { get; set; }
  116. private void Button_MakeIceCream()
  117. {
  118. }
  119. private void Button_SetIceCreamModel()
  120. {
  121. MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
  122. new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.Publish();
  123. }
  124. #endregion
  125. #region 咖啡机
  126. /// <summary>
  127. /// 咖啡机连接状态
  128. /// </summary>
  129. public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
  130. private string _coffeeConnected { get; set; }
  131. /// <summary>
  132. /// 咖啡机状态
  133. /// </summary>
  134. public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
  135. private string _coffeeStatus { get; set; }
  136. /// <summary>
  137. /// 应用状态
  138. /// </summary>
  139. public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } }
  140. private string _appStatus { get; set; }
  141. /// <summary>
  142. /// 告警
  143. /// </summary>
  144. public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
  145. public string _warning { get; set; }
  146. /// <summary>
  147. /// 故障信息
  148. /// </summary>
  149. public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } }
  150. public string _caffeeFault { get; set; }
  151. public List<string> Coffees { get; set; } = new List<string>();
  152. public string SelectedCoffee { get; set; }
  153. public List<string> CoffeeCmds { get; set; } = new List<string>();
  154. public string SelectedCoffeeCmd { get; set; }
  155. /// <summary>
  156. /// 制作咖啡
  157. /// </summary>
  158. public RelayCommand Button_MakeCoffeeCommand { get; set; }
  159. /// <summary>
  160. /// 停止制作咖啡
  161. /// </summary>
  162. public RelayCommand Button_StopMakeCoffeCommand { get; set; }
  163. /// <summary>
  164. /// 咖啡模式设置
  165. /// </summary>
  166. public RelayCommand Button_CoffeeModeSetCommand { get; set; }
  167. private void Button_MakeCoffee()
  168. {
  169. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
  170. }
  171. private void Button_StopMakeCoffe()
  172. {
  173. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
  174. }
  175. private void Button_CoffeeModeSet()
  176. {
  177. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)});
  178. }
  179. #endregion
  180. #region 单片机
  181. /// <summary>
  182. /// 单片机连接状态
  183. /// </summary>
  184. public string SCChipIsConnect { get { return _sCChipIsConnect; } set { _sCChipIsConnect = value; OnPropertyChanged(); } }
  185. private string _sCChipIsConnect { get; set; }
  186. /// <summary>
  187. /// 咖啡杯或冰淇淋杯落杯
  188. /// </summary>
  189. public RelayCommand<object> Button_CupControlCommand { get; set; }
  190. /// <summary>
  191. /// 单片机冰淇淋机器制冷
  192. /// </summary>
  193. public RelayCommand Button_SCChipRefrigerationCommand { get; set; }
  194. /// <summary>
  195. /// 单片机冰淇淋机器打料
  196. /// </summary>
  197. public RelayCommand Button_SCChipDischargeCommand { get; set; }
  198. /// <summary>
  199. /// 模拟测试
  200. /// </summary>
  201. public RelayCommand Button_SCChipTestCommand { get; set; }
  202. private void Button_CupControl(object CupType)
  203. {
  204. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) });
  205. }
  206. private void Button_SCChipRefrigeration()
  207. {
  208. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  209. Thread.Sleep(500);
  210. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  211. }
  212. private void Button_SCChipDischarge()
  213. {
  214. EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
  215. }
  216. #endregion
  217. /// <summary>
  218. /// 设备ID
  219. /// </summary>
  220. public int DeviceId { get; set; }
  221. /// <summary>
  222. /// 设备数据
  223. /// </summary>
  224. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  225. public DebugViewModel()
  226. {
  227. Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
  228. Button_SetValueCommand = new RelayCommand(Button_SetValue);
  229. Button_MakeIceCreamCommand = new RelayCommand(Button_MakeIceCream);
  230. Button_SetIceCreamModelCommand = new RelayCommand(Button_SetIceCreamModel);
  231. Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
  232. Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
  233. Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
  234. Button_CupControlCommand = new RelayCommand<object>(Button_CupControl);
  235. Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration);
  236. Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge);
  237. Button_SCChipTestCommand = new RelayCommand(() =>
  238. {
  239. Button_SCChipRefrigeration();
  240. Thread.Sleep(50);
  241. Button_SCChipDischarge();
  242. });
  243. foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
  244. {
  245. Coffees.Add(code.ToString());
  246. }
  247. SelectedCoffee = Coffees[0];
  248. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  249. {
  250. CoffeeCmds.Add(code.ToString());
  251. }
  252. SelectedCoffeeCmd = CoffeeCmds[0];
  253. foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
  254. {
  255. IceCreamModes.Add(code.ToString());
  256. }
  257. SelecteIceCreamdMode = IceCreamModes[0];
  258. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  259. {
  260. if (device.Name == "MorkT") DeviceId = device.DeviceId
  261. ;
  262. });
  263. ThreadManage.GetInstance().StartLong(new Action(() =>
  264. {
  265. variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  266. if (variableMonitors != null && variableMonitors.Count > 0)
  267. {
  268. RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  269. IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  270. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  271. SCChipIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  272. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  273. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  274. AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  275. Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  276. CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  277. YLWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器预冷温度").CurrentValue;
  278. HQWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器回气温度").CurrentValue;
  279. HJWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器环境温度").CurrentValue;
  280. DL = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电流").CurrentValue;
  281. DY = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电压").CurrentValue;
  282. CurrentMode = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器模式").CurrentValue;
  283. IceCreamFault = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器故障").CurrentValue;
  284. CXB = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器成型比").CurrentValue;
  285. DLCompleted = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器打料完成")?.CurrentValue == "True" ? "打料完成" : "打料中";
  286. }
  287. Thread.Sleep(500);
  288. }), "MorkT-状态刷新");
  289. }
  290. }
  291. }