终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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.MorkTHQ.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. EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId });
  119. }
  120. private void Button_SetIceCreamModel()
  121. {
  122. MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
  123. new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.Publish();
  124. }
  125. #endregion
  126. #region 咖啡机
  127. /// <summary>
  128. /// 咖啡机连接状态
  129. /// </summary>
  130. public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
  131. private string _coffeeConnected { get; set; }
  132. /// <summary>
  133. /// 咖啡机状态
  134. /// </summary>
  135. public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
  136. private string _coffeeStatus { get; set; }
  137. /// <summary>
  138. /// 应用状态
  139. /// </summary>
  140. public string CoffeeAppStatus { get { return _coffeAappStatus; } set { _coffeAappStatus = value; OnPropertyChanged(); } }
  141. private string _coffeAappStatus { get; set; }
  142. /// <summary>
  143. /// 告警
  144. /// </summary>
  145. public string CoffeeWarning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
  146. private string _warning { get; set; }
  147. /// <summary>
  148. /// 故障信息
  149. /// </summary>
  150. public string CoffeeFault { get { return _coffeeFault; } set { _coffeeFault = value; OnPropertyChanged(); } }
  151. private string _coffeeFault { get; set; }
  152. public string Coffeeprogress { get { return _coffeeprogress; } set { _coffeeprogress = value; OnPropertyChanged(); } }
  153. private string _coffeeprogress { get; set; }
  154. public List<string> Coffees { get; set; } = new List<string>();
  155. public string SelectedCoffee { get; set; }
  156. public List<string> CoffeeCmds { get; set; } = new List<string>();
  157. public string SelectedCoffeeCmd { get; set; }
  158. /// <summary>
  159. /// 制作咖啡
  160. /// </summary>
  161. public RelayCommand Button_MakeCoffeeCommand { get; set; }
  162. /// <summary>
  163. /// 停止制作咖啡
  164. /// </summary>
  165. public RelayCommand Button_StopMakeCoffeCommand { get; set; }
  166. /// <summary>
  167. /// 咖啡模式设置
  168. /// </summary>
  169. public RelayCommand Button_CoffeeModeSetCommand { get; set; }
  170. private void Button_MakeCoffee()
  171. {
  172. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
  173. }
  174. private void Button_StopMakeCoffe()
  175. {
  176. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
  177. }
  178. private void Button_CoffeeModeSet()
  179. {
  180. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)});
  181. }
  182. #endregion
  183. #region 单片机
  184. /// <summary>
  185. /// 单片机连接状态
  186. /// </summary>
  187. public string SCChipIsConnect { get { return _sCChipIsConnect; } set { _sCChipIsConnect = value; OnPropertyChanged(); } }
  188. private string _sCChipIsConnect { get; set; }
  189. /// <summary>
  190. /// 咖啡杯或冰淇淋杯落杯
  191. /// </summary>
  192. public RelayCommand<object> Button_CupControlCommand { get; set; }
  193. /// <summary>
  194. /// 单片机冰淇淋机器制冷
  195. /// </summary>
  196. public RelayCommand Button_SCChipRefrigerationCommand { get; set; }
  197. /// <summary>
  198. /// 单片机冰淇淋机器打料
  199. /// </summary>
  200. public RelayCommand Button_SCChipDischargeCommand { get; set; }
  201. /// <summary>
  202. /// 模拟测试
  203. /// </summary>
  204. public RelayCommand Button_SCChipTestCommand { get; set; }
  205. private void Button_CupControl(object CupType)
  206. {
  207. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) });
  208. }
  209. private void Button_SCChipRefrigeration()
  210. {
  211. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  212. Thread.Sleep(500);
  213. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  214. }
  215. private void Button_SCChipDischarge()
  216. {
  217. EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
  218. }
  219. #endregion
  220. #region 果汁机
  221. /// <summary>
  222. /// 果汁机连接状态
  223. /// </summary>
  224. public string JuiceIsConnect { get { return _juiceIsConnect; } set { _juiceIsConnect = value; OnPropertyChanged(); } }
  225. private string _juiceIsConnect { get; set; }
  226. public List<string> Juice { get; set; } = new List<string>() { "果汁1", "果汁2", "果汁3", "果汁4" };
  227. public string SelectedJuice { get; set; } = "果汁1";
  228. public List<string> Temperature { get; set; } = new List<string>() { "冷", "热" };
  229. public string SelectedTemperature { get; set; } = "冷";
  230. public RelayCommand MakeJuiceCommand { get; set; }
  231. private void MakeJuice()
  232. {
  233. switch (SelectedJuice)
  234. {
  235. case "果汁1":
  236. if (SelectedTemperature == "冷")
  237. {
  238. MakeJuiceEvent(0x01);
  239. }
  240. else MakeJuiceEvent(0x00);
  241. break;
  242. case "果汁2":
  243. if (SelectedTemperature == "冷")
  244. {
  245. MakeJuiceEvent(0x03);
  246. }
  247. else MakeJuiceEvent(0x02);
  248. break;
  249. case "果汁3":
  250. if (SelectedTemperature == "冷")
  251. {
  252. MakeJuiceEvent(0x05);
  253. }
  254. else MakeJuiceEvent(0x04);
  255. break;
  256. case "果汁4":
  257. if (SelectedTemperature == "冷")
  258. {
  259. MakeJuiceEvent(0x07);
  260. }
  261. else MakeJuiceEvent(0x06);
  262. break;
  263. default:
  264. MakeJuiceEvent(0x00);
  265. break;
  266. }
  267. }
  268. private void MakeJuiceEvent(byte b)
  269. {
  270. EventBus.EventBus.GetInstance().Publish(new WriteJuicer { DeviceId = DeviceId, Value = b });
  271. }
  272. #endregion
  273. /// <summary>
  274. /// 设备ID
  275. /// </summary>
  276. public int DeviceId { get; set; }
  277. /// <summary>
  278. /// 设备数据
  279. /// </summary>
  280. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  281. public DebugViewModel()
  282. {
  283. Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
  284. Button_SetValueCommand = new RelayCommand(Button_SetValue);
  285. Button_MakeIceCreamCommand = new RelayCommand(Button_MakeIceCream);
  286. Button_SetIceCreamModelCommand = new RelayCommand(Button_SetIceCreamModel);
  287. Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
  288. Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
  289. Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
  290. Button_CupControlCommand = new RelayCommand<object>(Button_CupControl);
  291. Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration);
  292. Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge);
  293. Button_SCChipTestCommand = new RelayCommand(() =>
  294. {
  295. Button_SCChipRefrigeration();
  296. Thread.Sleep(50);
  297. Button_SCChipDischarge();
  298. });
  299. MakeJuiceCommand = new RelayCommand(MakeJuice);
  300. foreach (DrinkType code in Enum.GetValues(typeof(DrinkType)))
  301. {
  302. Coffees.Add(code.ToString());
  303. }
  304. SelectedCoffee = Coffees[0];
  305. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  306. {
  307. CoffeeCmds.Add(code.ToString());
  308. }
  309. SelectedCoffeeCmd = CoffeeCmds[0];
  310. foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
  311. {
  312. IceCreamModes.Add(code.ToString());
  313. }
  314. SelecteIceCreamdMode = IceCreamModes[0];
  315. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  316. {
  317. if (device.Name == "MorkTHQ") DeviceId = device.DeviceId
  318. ;
  319. });
  320. ThreadManage.GetInstance().StartLong(new Action(() =>
  321. {
  322. variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  323. if (variableMonitors != null && variableMonitors.Count > 0)
  324. {
  325. RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  326. IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  327. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  328. SCChipIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  329. JuiceIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  330. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  331. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  332. CoffeeAppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  333. CoffeeWarning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  334. CoffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  335. Coffeeprogress = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机制作进度").CurrentValue;
  336. YLWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器预冷温度").CurrentValue;
  337. HQWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器回气温度").CurrentValue;
  338. HJWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器环境温度").CurrentValue;
  339. DL = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电流").CurrentValue;
  340. DY = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电压").CurrentValue;
  341. CurrentMode = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器模式").CurrentValue;
  342. IceCreamFault = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器故障").CurrentValue;
  343. CXB = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器成型比").CurrentValue;
  344. DLCompleted = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器打料完成")?.CurrentValue == "True" ? "打料完成" : "打料中";
  345. }
  346. Thread.Sleep(500);
  347. }), "MorkT-状态刷新");
  348. }
  349. }
  350. }