终端一体化运控平台
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.

преди 2 години
преди 1 година
преди 1 година
преди 2 години
преди 1 година
преди 1 година
преди 1 година
преди 2 години
преди 4 месеца
преди 2 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 
  2. using BPA.Helper;
  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 BPA.Helper.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.GetInstance.Subscribe<DRCoffee_MakeCoffeeEvent>(0, MakeCoffeeEventHandle);
  35. EventBus.GetInstance.Subscribe<DRCoffee_CancelMakeCoffeeEvent>(0, CancelMakeCoffeeEventHandle);
  36. 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. }