终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

387 líneas
20 KiB

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