终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DebugViewModel.cs 20 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. using BPASmartClient.Business;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.DRCoffee;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.LebaiRobot;
  7. using BPASmartClient.Message;
  8. using BPASmartClient.Model;
  9. using BPASmartClient.Model.乐白机器人;
  10. using BPASmartClient.Model.冰淇淋.Enum;
  11. using BPASmartClient.Model.单片机;
  12. using BPASmartClient.Model.单片机.Enum;
  13. using BPASmartClient.Model.咖啡机.Enum;
  14. using Microsoft.Toolkit.Mvvm.ComponentModel;
  15. using Microsoft.Toolkit.Mvvm.Input;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Collections.ObjectModel;
  19. using System.Linq;
  20. using System.Threading;
  21. namespace BPASmartClient.MorkT_BarCounter.ViewModel;
  22. public class DebugViewModel : ObservableObject
  23. {
  24. #region 乐白机器人
  25. /// <summary>
  26. /// 乐白机器人连接状态
  27. /// </summary>
  28. public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
  29. private string _robotConnected { get; set; }
  30. /// <summary>
  31. /// 乐白机器人的模式状态
  32. /// </summary>
  33. public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
  34. private string _robotMode { get; set; }
  35. /// <summary>
  36. /// 机器人控制指令
  37. /// </summary>
  38. public RelayCommand<object> Button_RobotControlCommand { get; set; }
  39. public RelayCommand Robot_DOutput { 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. private void Button_RobotDoutput()
  49. {
  50. bool DO_Value =int.Parse(Robot_DOutput_Value) == 0;
  51. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { Pin = int.Parse(Robot_DOutput_Pin), Value = DO_Value });
  52. }
  53. public string Robot_TCPDI0 { get { return _robot_TCPDI0; } set { _robot_TCPDI0 = value;OnPropertyChanged(); } }
  54. private string _robot_TCPDI0;
  55. public string Robot_DI0 { get { return _robot_DI0; } set { _robot_DI0 = value; OnPropertyChanged(); } }
  56. private string _robot_DI0;
  57. public string Robot_DI1 { get { return _robot_DI1; } set { _robot_DI1 = value; OnPropertyChanged(); } }
  58. private string _robot_DI1;
  59. public string Robot_DI2 { get { return _robot_DI2; } set { _robot_DI2 = value; OnPropertyChanged(); } }
  60. private string _robot_DI2;
  61. public string Robot_DI3 { get { return _robot_DI3; } set { _robot_DI3 = value; OnPropertyChanged(); } }
  62. private string _robot_DI3;
  63. public string Robot_DOutput_Pin { get { return _robot_DOutput_Pin; } set { _robot_DOutput_Pin = value; OnPropertyChanged(); } }
  64. private string _robot_DOutput_Pin { get; set; }
  65. public string Robot_DOutput_Value { get { return _robot_DOutput_Valuet; } set { _robot_DOutput_Valuet = value; OnPropertyChanged(); } }
  66. private string _robot_DOutput_Valuet { get; set; }
  67. #endregion
  68. #region 单片机
  69. public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } }
  70. private string _mcuConnected { get; set; }
  71. public string MCUDI0 { get { return _mCUDI0; } set { _mCUDI0 = value; OnPropertyChanged(); } }
  72. private string _mCUDI0 { get; set; }
  73. public string MCUDI1 { get { return _mCUDI1; } set { _mCUDI1 = value; OnPropertyChanged(); } }
  74. private string _mCUDI1 { get; set; }
  75. public string MCUDI2 { get { return _mCUDI2; } set { _mCUDI2 = value; OnPropertyChanged(); } }
  76. private string _mCUDI2 { get; set; }
  77. public string MCUDI3 { get { return _mCUDI3; } set { _mCUDI3 = value; OnPropertyChanged(); } }
  78. private string _mCUDI3 { get; set; }
  79. public string MCUDI4 { get { return _mCUDI4; } set { _mCUDI4 = value; OnPropertyChanged(); } }
  80. private string _mCUDI4 { get; set; }
  81. public string MCUDI5 { get { return _mCUDI5; } set { _mCUDI5 = value; OnPropertyChanged(); } }
  82. private string _mCUDI5 { get; set; }
  83. public string MCUDI6 { get { return _mCUDI6; } set { _mCUDI6 = value; OnPropertyChanged(); } }
  84. private string _mCUDI6 { get; set; }
  85. public string MCUDI7 { get { return _mCUDI7; } set { _mCUDI7 = value; OnPropertyChanged(); } }
  86. private string _mCUDI7 { get; set; }
  87. public RelayCommand Button_MCUOuputCommand { get; set; }
  88. public RelayCommand Button_MCUDOuputCommand { get; set; }
  89. public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
  90. private int _choosePWM = 1;
  91. public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
  92. private int _pwmInputNumber = 1;
  93. private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
  94. private int[] _diCH = new int[8];
  95. public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
  96. private int _mcuDO_CH = 1;
  97. public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } }
  98. private bool _mcu_DO_Valuer = true;
  99. private void Button_McuPWMOutput()
  100. {
  101. string sChoosePWM = Convert.ToString(MCU_PWM_CH + 1);
  102. new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish();
  103. }
  104. private void Button_McuDOutput()
  105. {
  106. string sChooseDO = Convert.ToString(MCU_DO_CH + 1);
  107. new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish();
  108. }
  109. #endregion
  110. #region 果汁机
  111. /// <summary>
  112. /// 果汁机的连接状态
  113. /// </summary>
  114. public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } }
  115. private string _JuicerConnected { get; set; }
  116. public string JuiceState_Heating { get { return _juiceState_Heating; } set { _juiceState_Heating = value;OnPropertyChanged(); } }
  117. public string _juiceState_Heating { get; set; }
  118. public string JuiceState_Cooling { get { return _juiceState_Cooling; } set { _juiceState_Cooling = value; OnPropertyChanged(); } }
  119. public string _juiceState_Cooling { get; set; }
  120. public string JuiceState_LackOfWater { get { return _juiceState_LackOfWater; } set { _juiceState_LackOfWater = value; OnPropertyChanged(); } }
  121. public string _juiceState_LackOfWater { get; set; }
  122. public string JuiceState_ChildLocks { get { return _juiceState_ChildLocks; } set { _juiceState_ChildLocks = value; OnPropertyChanged(); } }
  123. public string _juiceState_ChildLocks { get; set; }
  124. public string JuiceState_Using { get { return _juiceState_Using; } set { _juiceState_Using = value; OnPropertyChanged(); } }
  125. public string _juiceState_Using { get; set; }
  126. public string MakeJuice_Index { get { return _makeJuice_Index; } set { _makeJuice_Index = value; OnPropertyChanged(); } }
  127. public string _makeJuice_Index { get; set; }
  128. public RelayCommand Button_MakeJuiceCommand { get; set; }
  129. public void Button_MakeJuice()
  130. {
  131. new WriteJuicer() { Value = MakeJuice_Index }.Publish();
  132. }
  133. #endregion
  134. #region 制冰机
  135. public string IceMakerConnect { get { return _iceMakerConnect; } set { _iceMakerConnect = value;OnPropertyChanged(); } }
  136. private string _iceMakerConnect { get; set; }
  137. public string IceMakerState { get { return _iceMakerState; } set { _iceMakerState = value; OnPropertyChanged(); } }
  138. private string _iceMakerState { get; set; }
  139. public int IceMaker_IceTime { get { return _iceMaker_IceTime; } set { _iceMaker_IceTime = value; OnPropertyChanged(); } }
  140. private int _iceMaker_IceTime = 3;
  141. #region 订单模拟
  142. public RelayCommand SimOrderMakeCoffee { get; set; }
  143. public RelayCommand SimOrderMakeJuice { get; set; }
  144. public RelayCommand SimOrderMakeTea { get; set; }
  145. public RelayCommand SimOrderMakeWater { get; set; }
  146. public int SimOrder_JuiceList { get { return _simOrder_JuiceList; } set { _simOrder_JuiceList = value; OnPropertyChanged(); } }
  147. public int _simOrder_JuiceList { get; set; }
  148. public string SimOrder_JuiceMakeID { get { return _simOrder_JuiceMakeID; } set { _simOrder_JuiceMakeID = value; OnPropertyChanged(); } }
  149. public string _simOrder_JuiceMakeID { get; set; }
  150. #endregion
  151. public RelayCommand IceMaker_BtnPowerOn { get; set; }
  152. public RelayCommand IceMaker_BtnStandby { get; set;}
  153. public RelayCommand IceMaker_BtnPump { get; set;}
  154. public RelayCommand IceMaker_BtnStart { get; set; }
  155. public RelayCommand IceMaker_BtnEnd { get; set; }
  156. public RelayCommand IceMaker_BtnSetIceTime { get; set; }
  157. private void IceMaker_BtnPowerOnCommand()
  158. {
  159. new PowerOnMakeIce().Publish();
  160. }
  161. private void IceMaker_BtnStandbyCommand()
  162. {
  163. new StandbyMakeIce().Publish();
  164. }
  165. private void IceMaker_BtnPumpCommand()
  166. {
  167. new PumpMakeIce().Publish();
  168. }
  169. private void IceMaker_BtnStartCommand()
  170. {
  171. new StartMakeIce().Publish();
  172. }
  173. private void IceMaker_BtnEndCommand()
  174. {
  175. new StopMakeIce().Publish();
  176. }
  177. private void IceMaker_BtnSetIceTimeCommand()
  178. {
  179. new SetIceNumber{ Value= IceMaker_IceTime }.Publish();
  180. }
  181. #endregion
  182. #region 咖啡机
  183. /// <summary>
  184. /// 咖啡机连接状态
  185. /// </summary>
  186. public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
  187. private string _coffeeConnected { get; set; }
  188. /// <summary>
  189. /// 咖啡机状态
  190. /// </summary>
  191. public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
  192. private string _coffeeStatus { get; set; }
  193. /// <summary>
  194. /// 应用状态
  195. /// </summary>
  196. public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } }
  197. private string _appStatus { get; set; }
  198. /// <summary>
  199. /// 告警
  200. /// </summary>
  201. public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
  202. public string _warning { get; set; }
  203. /// <summary>
  204. /// 故障信息
  205. /// </summary>
  206. public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } }
  207. public string _caffeeFault { get; set; }
  208. public List<string> Coffees { get; set; } = new List<string>();
  209. public string SelectedCoffee { get { return _selectedCoffee; } set { _selectedCoffee = value; OnPropertyChanged(); } }
  210. public string _selectedCoffee { get; set; }
  211. public List<string> CoffeeCmds { get; set; } = new List<string>();
  212. public string SelectedCoffeeCmd { get; set; }
  213. public string SimOrderCoffeeList { get { return _simOrderCoffeeList; } set { _simOrderCoffeeList = value; OnPropertyChanged(); } }
  214. public string _simOrderCoffeeList { get; set; }
  215. /// <summary>
  216. /// 制作咖啡
  217. /// </summary>
  218. public RelayCommand Button_MakeCoffeeCommand { get; set; }
  219. /// <summary>
  220. /// 停止制作咖啡
  221. /// </summary>
  222. public RelayCommand Button_StopMakeCoffeCommand { get; set; }
  223. /// <summary>
  224. /// 咖啡模式设置
  225. /// </summary>
  226. public RelayCommand Button_CoffeeModeSetCommand { get; set; }
  227. private void Button_MakeCoffee()
  228. {
  229. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee) });
  230. }
  231. private void Button_StopMakeCoffe()
  232. {
  233. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
  234. }
  235. private void Button_CoffeeModeSet()
  236. {
  237. EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd) });
  238. }
  239. #endregion
  240. /// <summary>
  241. /// 设备ID
  242. /// </summary>
  243. public int DeviceId { get; set; }
  244. /// <summary>
  245. /// 设备数据
  246. /// </summary>
  247. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  248. public DebugViewModel()
  249. {
  250. SimOrderMakeCoffee = new RelayCommand(() =>
  251. {
  252. new MorkTSimOrder() { OrderNum = 1, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SimOrderCoffeeList) }.Publish();
  253. });
  254. SimOrderMakeJuice = new RelayCommand(() =>
  255. {
  256. new MorkTSimOrder() { OrderNum = 2, JuiceList = SimOrder_JuiceList, JuiceMakeID = SimOrder_JuiceMakeID }.Publish();
  257. });
  258. SimOrderMakeTea = new RelayCommand(() =>
  259. {
  260. new MorkTSimOrder() { OrderNum = 3 }.Publish();
  261. });
  262. SimOrderMakeWater = new RelayCommand(() =>
  263. {
  264. new MorkTSimOrder() { OrderNum = 4 }.Publish();
  265. });
  266. Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
  267. Robot_DOutput = new RelayCommand(Button_RobotDoutput);
  268. Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
  269. Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
  270. Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
  271. Button_MCUOuputCommand = new RelayCommand(Button_McuPWMOutput);
  272. Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput);
  273. Button_MakeJuiceCommand = new RelayCommand(Button_MakeJuice);
  274. IceMaker_BtnPowerOn = new RelayCommand(IceMaker_BtnPowerOnCommand);
  275. IceMaker_BtnStandby = new RelayCommand(IceMaker_BtnStandbyCommand);
  276. IceMaker_BtnPump = new RelayCommand(IceMaker_BtnPumpCommand);
  277. IceMaker_BtnStart = new RelayCommand(IceMaker_BtnStartCommand);
  278. IceMaker_BtnEnd = new RelayCommand(IceMaker_BtnEndCommand);
  279. IceMaker_BtnSetIceTime = new RelayCommand(IceMaker_BtnSetIceTimeCommand);
  280. foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
  281. {
  282. Coffees.Add(code.ToString());
  283. }
  284. SelectedCoffee = Coffees[0];
  285. SimOrderCoffeeList = Coffees[0];
  286. foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
  287. {
  288. CoffeeCmds.Add(code.ToString());
  289. }
  290. SelectedCoffeeCmd = CoffeeCmds[0];
  291. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  292. {
  293. if (device.Name == "MorkT") DeviceId = device.DeviceId
  294. ;
  295. });
  296. ThreadManage.GetInstance().StartLong(new Action(() =>
  297. {
  298. variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  299. if (variableMonitors != null && variableMonitors.Count > 0)
  300. {
  301. #region 机器人
  302. RobotConnected = variableMonitors.FirstOrDefault(p => p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  303. RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
  304. Robot_TCPDI0 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人TCP输入状态").CurrentValue;
  305. Robot_DI0 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入0状态").CurrentValue;
  306. Robot_DI1 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入1状态").CurrentValue;
  307. Robot_DI2 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入2状态").CurrentValue;
  308. Robot_DI3 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入3状态").CurrentValue;
  309. #endregion
  310. #region 咖啡机
  311. CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  312. CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
  313. AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
  314. Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
  315. CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
  316. #endregion
  317. #region 单片机
  318. MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  319. MCUDI0 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入0状态").CurrentValue;
  320. MCUDI1 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入1状态").CurrentValue;
  321. MCUDI2 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入2状态").CurrentValue;
  322. MCUDI3 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入3状态").CurrentValue;
  323. MCUDI4 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入4状态").CurrentValue;
  324. MCUDI5 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入5状态").CurrentValue;
  325. MCUDI6 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入6状态").CurrentValue;
  326. MCUDI7 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入7状态").CurrentValue;
  327. #endregion
  328. #region 制冰机
  329. IceMakerConnect = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  330. IceMakerState = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机设备状态").CurrentValue;
  331. #endregion
  332. #region 果汁机
  333. JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
  334. JuiceState_Heating = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制热").CurrentValue;
  335. JuiceState_Cooling = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制冷").CurrentValue;
  336. JuiceState_LackOfWater = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机缺水").CurrentValue;
  337. JuiceState_ChildLocks = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机童锁").CurrentValue;
  338. JuiceState_Using = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机使用").CurrentValue;
  339. #endregion
  340. }
  341. Thread.Sleep(500);
  342. }), "MorkT-状态刷新");
  343. }
  344. }