终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

87 righe
2.7 KiB

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