终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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