终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

394 wiersze
17 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.MorkTHQ.ViewModel
  20. {
  21. public class DebugViewModel : NotifyBase
  22. {
  23. #region 乐白机器人
  24. /// <summary>
  25. /// 乐白机器人连接状态
  26. /// </summary>
  27. public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
  28. private string _robotConnected { get; set; }
  29. /// <summary>
  30. /// 乐白机器人的模式状态
  31. /// </summary>
  32. public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
  33. private string _robotMode { get; set; }
  34. /// <summary>
  35. /// 机器人控制指令
  36. /// </summary>
  37. public BPARelayCommand<object> Button_RobotControlCommand { get; set; }
  38. /// <summary>
  39. /// 机器人控制
  40. /// </summary>
  41. /// <param name="o"></param>
  42. public BPARelayCommand Button_SetValueCommand { get; set; }
  43. private void Button_SetValue()
  44. {
  45. EventBus.GetInstance.Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  46. }
  47. private void Button_RobotControl(object o)
  48. {
  49. EventBus.GetInstance.Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
  50. }
  51. #endregion
  52. #region 冰淇淋机器
  53. /// <summary>
  54. /// 制作冰淇淋
  55. /// </summary>
  56. public BPARelayCommand Button_MakeIceCreamCommand { get; set; }
  57. /// <summary>
  58. /// 选择冰淇淋模式
  59. /// </summary>
  60. public BPARelayCommand Button_SetIceCreamModelCommand { get; set; }
  61. /// <summary>
  62. /// 冰淇淋连接状态
  63. /// </summary>
  64. public string IceCreamConnected { get { return _iceCreamConnected; } set { _iceCreamConnected = value; OnPropertyChanged(); } }
  65. private string _iceCreamConnected { get; set; }
  66. /// <summary>
  67. /// 预冷温度
  68. /// </summary>
  69. public string YLWD { get { return _yLWD; } set { _yLWD = value; OnPropertyChanged(); } }
  70. private string _yLWD { get; set; }
  71. /// <summary>
  72. /// 回气温度
  73. /// </summary>
  74. public string HQWD { get { return _hQWD; } set { _hQWD = value; OnPropertyChanged(); } }
  75. private string _hQWD { get; set; }
  76. /// <summary>
  77. /// 环境温度
  78. /// </summary>
  79. public string HJWD { get { return _hJWD; } set { _hJWD = value; OnPropertyChanged(); } }
  80. private string _hJWD { get; set; }
  81. /// <summary>
  82. /// 电流
  83. /// </summary>
  84. public string DL { get { return _DL; } set { _DL = value; OnPropertyChanged(); } }
  85. private string _DL { get; set; }
  86. /// <summary>
  87. /// 电压
  88. /// </summary>
  89. public string DY { get { return _dy; } set { _dy = value; OnPropertyChanged(); } }
  90. private string _dy { get; set; }
  91. /// <summary>
  92. /// 当前模式
  93. /// </summary>
  94. public string CurrentMode { get { return _CurrentMode; } set { _CurrentMode = value; OnPropertyChanged(); } }
  95. private string _CurrentMode;
  96. /// <summary>
  97. /// 故障
  98. /// </summary>
  99. public string IceCreamFault { get { return _IceCreamFault; } set { _IceCreamFault = value; OnPropertyChanged(); } }
  100. private string _IceCreamFault { get; set; }
  101. /// <summary>
  102. /// 成型比
  103. /// </summary>
  104. public string CXB { get { return _cXB; } set { _cXB = value; OnPropertyChanged(); } }
  105. private string _cXB { get; set; }
  106. /// <summary>
  107. /// 打料完成状态
  108. /// </summary>
  109. public string DLCompleted { get { return _dLCompleted; } set { _dLCompleted = value; OnPropertyChanged(); } }
  110. private string _dLCompleted { get; set; }
  111. public List<string> IceCreamModes { get; set; } = new List<string>();
  112. public string SelecteIceCreamdMode { get; set; }
  113. private void Button_MakeIceCream()
  114. {
  115. EventBus.GetInstance.Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId });
  116. }
  117. private void Button_SetIceCreamModel()
  118. {
  119. MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
  120. new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.Publish();
  121. }
  122. #endregion
  123. #region 咖啡机
  124. /// <summary>
  125. /// 咖啡机连接状态
  126. /// </summary>
  127. public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
  128. private string _coffeeConnected { get; set; }
  129. /// <summary>
  130. /// 咖啡机状态
  131. /// </summary>
  132. public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
  133. private string _coffeeStatus { get; set; }
  134. /// <summary>
  135. /// 应用状态
  136. /// </summary>
  137. public string CoffeeAppStatus { get { return _coffeAappStatus; } set { _coffeAappStatus = value; OnPropertyChanged(); } }
  138. private string _coffeAappStatus { get; set; }
  139. /// <summary>
  140. /// 告警
  141. /// </summary>
  142. public string CoffeeWarning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
  143. private string _warning { get; set; }
  144. /// <summary>
  145. /// 故障信息
  146. /// </summary>
  147. public string CoffeeFault { get { return _coffeeFault; } set { _coffeeFault = value; OnPropertyChanged(); } }
  148. private string _coffeeFault { get; set; }
  149. public string Coffeeprogress { get { return _coffeeprogress; } set { _coffeeprogress = value; OnPropertyChanged(); } }
  150. private string _coffeeprogress { 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 BPARelayCommand Button_MakeCoffeeCommand { get; set; }
  159. /// <summary>
  160. /// 停止制作咖啡
  161. /// </summary>
  162. public BPARelayCommand Button_StopMakeCoffeCommand { get; set; }
  163. /// <summary>
  164. /// 咖啡模式设置
  165. /// </summary>
  166. public BPARelayCommand Button_CoffeeModeSetCommand { get; set; }
  167. private void Button_MakeCoffee()
  168. {
  169. EventBus.GetInstance.Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
  170. }
  171. private void Button_StopMakeCoffe()
  172. {
  173. EventBus.GetInstance.Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
  174. }
  175. private void Button_CoffeeModeSet()
  176. {
  177. 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 BPARelayCommand<object> Button_CupControlCommand { get; set; }
  190. /// <summary>
  191. /// 单片机冰淇淋机器制冷
  192. /// </summary>
  193. public BPARelayCommand Button_SCChipRefrigerationCommand { get; set; }
  194. /// <summary>
  195. /// 单片机冰淇淋机器打料
  196. /// </summary>
  197. public BPARelayCommand Button_SCChipDischargeCommand { get; set; }
  198. /// <summary>
  199. /// 模拟测试
  200. /// </summary>
  201. public BPARelayCommand Button_SCChipTestCommand { get; set; }
  202. private void Button_CupControl(object CupType)
  203. {
  204. 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.GetInstance.Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  209. Thread.Sleep(500);
  210. EventBus.GetInstance.Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  211. }
  212. private void Button_SCChipDischarge()
  213. {
  214. EventBus.GetInstance.Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
  215. }
  216. #endregion
  217. #region 果汁机
  218. /// <summary>
  219. /// 果汁机连接状态
  220. /// </summary>
  221. public string JuiceIsConnect { get { return _juiceIsConnect; } set { _juiceIsConnect = value; OnPropertyChanged(); } }
  222. private string _juiceIsConnect { get; set; }
  223. public List<string> Juice { get; set; } = new List<string>() { "果汁1", "果汁2", "果汁3", "果汁4" };
  224. public string SelectedJuice { get; set; } = "果汁1";
  225. public List<string> Temperature { get; set; } = new List<string>() { "冷", "热" };
  226. public string SelectedTemperature { get; set; } = "冷";
  227. public BPARelayCommand MakeJuiceCommand { get; set; }
  228. private void MakeJuice()
  229. {
  230. switch (SelectedJuice)
  231. {
  232. case "果汁1":
  233. if (SelectedTemperature == "冷")
  234. {
  235. MakeJuiceEvent(0x01);
  236. }
  237. else MakeJuiceEvent(0x00);
  238. break;
  239. case "果汁2":
  240. if (SelectedTemperature == "冷")
  241. {
  242. MakeJuiceEvent(0x03);
  243. }
  244. else MakeJuiceEvent(0x02);
  245. break;
  246. case "果汁3":
  247. if (SelectedTemperature == "冷")
  248. {
  249. MakeJuiceEvent(0x05);
  250. }
  251. else MakeJuiceEvent(0x04);
  252. break;
  253. case "果汁4":
  254. if (SelectedTemperature == "冷")
  255. {
  256. MakeJuiceEvent(0x07);
  257. }
  258. else MakeJuiceEvent(0x06);
  259. break;
  260. default:
  261. MakeJuiceEvent(0x00);
  262. break;
  263. }
  264. }
  265. private void MakeJuiceEvent(byte b)
  266. {
  267. EventBus.GetInstance.Publish(new WriteJuicer { DeviceId = DeviceId, Value = b });
  268. }
  269. #endregion
  270. /// <summary>
  271. /// 设备ID
  272. /// </summary>
  273. public int DeviceId { get; set; }
  274. /// <summary>
  275. /// 设备数据
  276. /// </summary>
  277. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  278. public DebugViewModel()
  279. {
  280. Button_RobotControlCommand = new BPARelayCommand<object>(Button_RobotControl);
  281. Button_SetValueCommand = new BPARelayCommand(Button_SetValue);
  282. Button_MakeIceCreamCommand = new BPARelayCommand(Button_MakeIceCream);
  283. Button_SetIceCreamModelCommand = new BPARelayCommand(Button_SetIceCreamModel);
  284. Button_MakeCoffeeCommand = new BPARelayCommand(Button_MakeCoffee);
  285. Button_StopMakeCoffeCommand = new BPARelayCommand(Button_StopMakeCoffe);
  286. Button_CoffeeModeSetCommand = new BPARelayCommand(Button_CoffeeModeSet);
  287. Button_CupControlCommand = new BPARelayCommand<object>(Button_CupControl);
  288. Button_SCChipRefrigerationCommand = new BPARelayCommand(Button_SCChipRefrigeration);
  289. Button_SCChipDischargeCommand = new BPARelayCommand(Button_SCChipDischarge);
  290. Button_SCChipTestCommand = new BPARelayCommand(() =>
  291. {
  292. Button_SCChipRefrigeration();
  293. Thread.Sleep(50);
  294. Button_SCChipDischarge();
  295. });
  296. MakeJuiceCommand = new BPARelayCommand(MakeJuice);
  297. foreach (DrinkType code in Enum.GetValues(typeof(DrinkType)))
  298. {
  299. Coffees.Add(code.ToString());
  300. }
  301. SelectedCoffee = Coffees[0];
  302. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  303. {
  304. CoffeeCmds.Add(code.ToString());
  305. }
  306. SelectedCoffeeCmd = CoffeeCmds[0];
  307. foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
  308. {
  309. IceCreamModes.Add(code.ToString());
  310. }
  311. SelecteIceCreamdMode = IceCreamModes[0];
  312. Plugin.GetInstance?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  313. {
  314. if (device.Name == "MorkTHQ") DeviceId = device.DeviceId
  315. ;
  316. });
  317. TaskManage.GetInstance.StartLong(new Action(() =>
  318. {
  319. variableMonitors = Plugin.GetInstance?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  320. if (variableMonitors != null && variableMonitors.Count > 0)
  321. {
  322. RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  323. IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  324. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  325. SCChipIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  326. JuiceIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  327. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  328. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  329. CoffeeAppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  330. CoffeeWarning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  331. CoffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  332. Coffeeprogress = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机制作进度").CurrentValue;
  333. YLWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器预冷温度").CurrentValue;
  334. HQWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器回气温度").CurrentValue;
  335. HJWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器环境温度").CurrentValue;
  336. DL = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电流").CurrentValue;
  337. DY = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电压").CurrentValue;
  338. CurrentMode = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器模式").CurrentValue;
  339. IceCreamFault = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器故障").CurrentValue;
  340. CXB = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器成型比").CurrentValue;
  341. DLCompleted = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器打料完成")?.CurrentValue == "True" ? "打料完成" : "打料中";
  342. }
  343. Thread.Sleep(500);
  344. }), "MorkT-状态刷新");
  345. }
  346. }
  347. }