|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
-
-
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPASmartClient.Model.咖啡机.Enum;
- using BPASmartClient.SerialPort;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using static BPA.Helper.EventBus;
-
- namespace BPASmartClient.DRCoffee
- {
- /// <summary>
- /// 指令封装
- /// </summary>
- internal class CommandHandler
- {
- byte[] cmdAsk;
- private SerialPortClient commProxy;
- private DrCoffeePackage drinksOrder = new DrCoffeePackage();
-
- public Action<bool> PauseAsk { get; set; }
- /// <summary>
- /// 初始化
- /// </summary>
- internal void Init(SerialPortClient commProxy)
- {
- this.commProxy = commProxy;
-
- DrCoffeePackage package = new DrCoffeePackage();
- package.CommCmd = DrCoffeeCommCmd.饮品制作指令;
- cmdAsk = DrCoffee.Packe(package);
- drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
-
- EventBus.GetInstance.Subscribe<DRCoffee_MakeCoffeeEvent>(0, MakeCoffeeEventHandle);
- EventBus.GetInstance.Subscribe<DRCoffee_CancelMakeCoffeeEvent>(0, CancelMakeCoffeeEventHandle);
- EventBus.GetInstance.Subscribe<DRCoffee_CoffeeCommCmdEvent>(0, CoffeeCommCmdEventHandle);
-
- }
-
- private void CoffeeCommCmdEventHandle(IEvent @event, EventCallBackHandle callBack)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- drinksOrder.CommCmd = ((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd;
- commProxy.SendData(DrCoffee.Packe(drinksOrder));
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- }
-
- private void CancelMakeCoffeeEventHandle(IEvent @event, EventCallBackHandle callBack)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- drinksOrder.CommCmd = DrCoffeeCommCmd.取消应用指令;
- drinksOrder.DrinksCode = 0;
- commProxy.SendData(DrCoffee.Packe(drinksOrder));
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- }
-
- private void MakeCoffeeEventHandle(IEvent @event, EventCallBackHandle callBack)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
- drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).DrinkCode;
- commProxy.SendData(DrCoffee.Packe(drinksOrder));
-
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- }
-
- /// <summary>
- /// 发送状态询问
- /// </summary>
- internal byte[] GetStatusAsk()
- {
- return cmdAsk;
- }
- }
- }
|