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.
 
 

82 lines
2.6 KiB

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