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

2 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 
  2. using BPASmartClient.EventBus;
  3. using BPASmartClient.Model;
  4. using BPASmartClient.Model.咖啡机.Enum;
  5. using BPASmartClient.SerialPort;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using static BPASmartClient.EventBus.EventBus;
  13. namespace BPASmartClient.DRCoffee
  14. {
  15. /// <summary>
  16. /// 指令封装
  17. /// </summary>
  18. internal class CommandHandler
  19. {
  20. byte[] cmdAsk;
  21. private SerialPortClient commProxy;
  22. private DrCoffeePackage drinksOrder = new DrCoffeePackage();
  23. public Action<bool> PauseAsk { get; set; }
  24. /// <summary>
  25. /// 初始化
  26. /// </summary>
  27. internal void Init(SerialPortClient commProxy)
  28. {
  29. this.commProxy = commProxy;
  30. DrCoffeePackage package = new DrCoffeePackage();
  31. package.CommCmd = DrCoffeeCommCmd.饮品制作指令;
  32. cmdAsk = DrCoffee.Packe(package);
  33. drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
  34. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_MakeCoffeeEvent>(0,MakeCoffeeEventHandle);
  35. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CancelMakeCoffeeEvent>(0, CancelMakeCoffeeEventHandle);
  36. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeeCommCmdEvent>(0, CoffeeCommCmdEventHandle);
  37. }
  38. private void CoffeeCommCmdEventHandle(IEvent @event, EventCallBackHandle callBack)
  39. {
  40. PauseAsk?.Invoke(true);
  41. Thread.Sleep(200);
  42. drinksOrder.CommCmd = ((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd;
  43. commProxy.SendData(DrCoffee.Packe(drinksOrder));
  44. Thread.Sleep(200);
  45. PauseAsk?.Invoke(false);
  46. }
  47. private void CancelMakeCoffeeEventHandle(IEvent @event, EventCallBackHandle callBack)
  48. {
  49. PauseAsk?.Invoke(true);
  50. Thread.Sleep(200);
  51. drinksOrder.CommCmd = DrCoffeeCommCmd.取消应用指令;
  52. drinksOrder.DrinksCode = 0;
  53. commProxy.SendData(DrCoffee.Packe(drinksOrder));
  54. Thread.Sleep(200);
  55. PauseAsk?.Invoke(false);
  56. }
  57. private void MakeCoffeeEventHandle(IEvent @event, EventCallBackHandle callBack)
  58. {
  59. PauseAsk?.Invoke(true);
  60. Thread.Sleep(200);
  61. drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
  62. drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).DrinkCode;
  63. commProxy.SendData(DrCoffee.Packe(drinksOrder));
  64. Thread.Sleep(200);
  65. PauseAsk?.Invoke(false);
  66. }
  67. /// <summary>
  68. /// 发送状态询问
  69. /// </summary>
  70. internal byte[] GetStatusAsk()
  71. {
  72. return cmdAsk;
  73. }
  74. }
  75. }