From b88d7c97db4326ffc28c3c617fc9ec3701d394ea Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Tue, 19 Apr 2022 17:50:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=92=96=E5=95=A1?= =?UTF-8?q?=E6=9C=BA=E3=80=81=E5=8D=95=E7=89=87=E6=9C=BA=E5=86=85=E9=83=A8?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.DRCoffee.csproj | 1 - BPASmartClient.DRCoffee/CoffeeMachine.cs | 164 ++++----- BPASmartClient.DRCoffee/MorkCStatus.cs | 76 ----- .../Protocal/SystemStatusModel.cs | 6 + BPASmartClient.Model/单片机/SCChipEvent.cs | 12 +- .../咖啡机/DRCoffeeEvent.cs | 3 +- .../BPASmartClient.SCChip.csproj | 2 +- BPASmartClient.SCChip/ChipStatus.cs | 128 ------- BPASmartClient.SCChip/CommandEvent.cs | 42 --- BPASmartClient.SCChip/CommandHandler.cs | 225 ------------ BPASmartClient.SCChip/ICChipMachine.cs | 322 ++++++++++++++++-- BPASmartClient/MainWindow.xaml | 2 +- BPASmartClient/MainWindow.xaml.cs | 3 + 13 files changed, 396 insertions(+), 590 deletions(-) delete mode 100644 BPASmartClient.DRCoffee/MorkCStatus.cs delete mode 100644 BPASmartClient.SCChip/ChipStatus.cs delete mode 100644 BPASmartClient.SCChip/CommandEvent.cs delete mode 100644 BPASmartClient.SCChip/CommandHandler.cs diff --git a/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj b/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj index 58a6fd19..7024144c 100644 --- a/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj +++ b/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj @@ -5,7 +5,6 @@ - diff --git a/BPASmartClient.DRCoffee/CoffeeMachine.cs b/BPASmartClient.DRCoffee/CoffeeMachine.cs index 541856ab..9d07749d 100644 --- a/BPASmartClient.DRCoffee/CoffeeMachine.cs +++ b/BPASmartClient.DRCoffee/CoffeeMachine.cs @@ -15,78 +15,33 @@ namespace BPASmartClient.DRCoffee /// /// 咖啡机 /// - public class CoffeeMachine: BasePeripheral + public class CoffeeMachine :BasePeripheral { //通讯代理 SerialPortClient commProxy = null; //数据仓库 private DataStorage dataStorage = new DataStorage(); - //主线程运行标识 - private bool running = false; //是否下发指令,主线程等待 - private bool free = true; - - private DrCoffeeStatus drCoffeeStatus; - /// - /// 咖啡机状态 - /// - public DrCoffeeStatus CurrentCoffeeStatus - { - get { return drCoffeeStatus; } - set - { - if (drCoffeeStatus != value) - { - drCoffeeStatus = value; - CoffeeStatusChanged?.Invoke(value); - } - } - } - private DrCoffeeAppStatus coffeeAppStatus; - /// - /// 应用状态 - /// - public DrCoffeeAppStatus CurrentCoffeeAppStatus - { - get { return coffeeAppStatus; } - set - { - if (coffeeAppStatus != value) - { - coffeeAppStatus = value; - CoffeeAppStatusChanged?.Invoke(value); - } - } - } - - public Action SendCallback; - public Action ReciveCallback; - - /// - /// 咖啡机状态改变回调 - /// - public Action CoffeeStatusChanged; - /// - /// 应用状态改变回调 - /// - public Action CoffeeAppStatusChanged; - /// - /// Dr咖啡机基础协议 - /// + private bool free = false; + //状态询问指令 + private byte[] cmdAsk; + //Dr咖啡机基础协议 private DrCoffeePackage drinksOrder = new DrCoffeePackage(); - - /// - /// 串口COM口 - /// + //串口COM口 public string PortName { get; set; } + //串口波特率 + public string BaudRate { get; set; } + //心跳时间 + private DateTime lastRefreshTime = DateTime.MinValue; /// - /// 串口波特率 + /// 是否在线 /// - public string BaudRate { get; set; } - + public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } public CoffeeMachine() { - + DrCoffeePackage package = new DrCoffeePackage(); + package.CommCmd = DrCoffeeCommCmd.饮品制作指令; + cmdAsk = DrCoffee.Packe(package); } /// @@ -94,10 +49,17 @@ namespace BPASmartClient.DRCoffee /// public override void Start() { - - commProxy.Start(); - running = true; - MainLoop(); + try + { + commProxy.Start(); + IsConnected = true; + free = false; + MainLoop(); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]"); + } } /// @@ -105,8 +67,16 @@ namespace BPASmartClient.DRCoffee /// public override void Stop() { - commProxy.Stop(); - running = false; + try + { + commProxy.Stop(); + IsConnected = false; + free = true; + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]"); + } } /// @@ -114,15 +84,14 @@ namespace BPASmartClient.DRCoffee /// private void MainLoop() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - // if (free) - // { - // commProxy.SendData(commandHandler.GetStatusAsk()); - // SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk())); - // } - // Thread.Sleep(200); - //}),"咖啡机询问线程"); + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (!free) + { + commProxy.SendData(cmdAsk); + } + Thread.Sleep(200); + }),"咖啡机询问线程"); ThreadManage.GetInstance.StartLong(new Action(() => { @@ -137,9 +106,8 @@ namespace BPASmartClient.DRCoffee { temp.Add(item); var package = DrCoffee.UnPack(temp.ToArray()); - ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray())); temp.Clear(); - MorkCStatus.GetInstance().ProcessPackage(package); + ProcessPackage(package); } else { @@ -159,14 +127,45 @@ namespace BPASmartClient.DRCoffee } } Thread.Sleep(5); - }), "咖啡机解析线程"); + }),"咖啡机解析线程"); } - protected override void InitStatus() + /// + /// 咖啡机状态解析 + /// + /// + public void ProcessPackage(DrCoffeePackage package) { - + if (((DrCoffeeStatus)status["CoffeeStatus"]) == DrCoffeeStatus.Running && package.Status != DrCoffeeStatus.Running) + { + status["CoffeeStatus"] = package.Status; + lastRefreshTime = DateTime.Now; + new DRCoffee_CoffeEndCookEvent() { Id = DeviceId }.Publish(); + } + else status["CoffeeStatus"] = package.Status; + status["AppStatus"] = package.ApplicationStatus; + status["Warning"] = package.Warning; + status["Fault"] = package.Fault; + + if ((DrCoffeeStatus)status["CoffeeStatus"] == DrCoffeeStatus.Warning + || (DrCoffeeStatus)status["CoffeeStatus"] == DrCoffeeStatus.Fault + || (DrCoffeeWarning)status["Warning"] != DrCoffeeWarning.无警告 + || (DrCoffeeFault)status["Fault"] != DrCoffeeFault.无故障 + ) + { + IsWork = false; + } + else + IsWork = true; } + protected override void InitStatus() + { + status["CoffeeStatus"] = DrCoffeeStatus.Wait; + status["AppStatus"] = DrCoffeeAppStatus.应用无状态; + status["Warning"] = DrCoffeeWarning.无警告; + status["Fault"] = DrCoffeeFault.无故障; + } public override void Init() { @@ -181,7 +180,7 @@ namespace BPASmartClient.DRCoffee free = true; Thread.Sleep(200); drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; - //drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).CommCmd; + drinksOrder.DrinksCode = (DrCoffeeDrinksCode)((DRCoffee_MakeCoffeeEvent)@event).DrinkCode; commProxy.SendData(DrCoffee.Packe(drinksOrder)); Thread.Sleep(200); free = false; @@ -218,7 +217,7 @@ namespace BPASmartClient.DRCoffee { free = true; Thread.Sleep(200); - //drinksOrder.CommCmd = (DrCoffeeCommCmd)int.Parse(e.obj_MessageObj.ToString()); + drinksOrder.CommCmd = (DrCoffeeCommCmd)((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd; commProxy.SendData(DrCoffee.Packe(drinksOrder)); Thread.Sleep(200); free = false; @@ -229,5 +228,6 @@ namespace BPASmartClient.DRCoffee } }); } + } } diff --git a/BPASmartClient.DRCoffee/MorkCStatus.cs b/BPASmartClient.DRCoffee/MorkCStatus.cs deleted file mode 100644 index 226aa9e7..00000000 --- a/BPASmartClient.DRCoffee/MorkCStatus.cs +++ /dev/null @@ -1,76 +0,0 @@ -using BPASmartClient.DRCoffee; -using BPASmartClient.MessageCommunication; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DRCoffee -{ - public class MorkCStatus - { - private volatile static MorkCStatus _Instance; - public static MorkCStatus GetInstance() => _Instance ?? (_Instance = new MorkCStatus()); - private MorkCStatus() { } - - private DateTime lastRefreshTime = DateTime.MinValue; - /// - /// 是否在线 - /// - public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } - /// - /// 咖啡机状态 - /// - public DrCoffeeStatus CoffeeStatus { get; set; } - /// - /// 应用状态 - /// - public DrCoffeeAppStatus AppStatus { get; set; } - /// - /// 警告信息 - /// - public DrCoffeeWarning Warning { get; set; } - /// - /// 故障信息 - /// - public DrCoffeeFault Fault { get; set; } - - public bool CanDo - { - get - - { - if (!OnLine) - return false; - if (Warning != DrCoffeeWarning.无警告) - return false; - if (Fault != DrCoffeeFault.无故障) - return false; - return true; - } - } - - /// - /// 咖啡机状态解析 - /// - /// - public void ProcessPackage(DrCoffeePackage package) - { - if (CoffeeStatus == DrCoffeeStatus.Running && package.Status != DrCoffeeStatus.Running) - { - CoffeeStatus = package.Status; - Class_InnerMessageBus.GetInstance().PostMessage(this,Class_MessageName.DRCoffee_CoffeEndCook,""); - } - else { - CoffeeStatus = package.Status; - } - - AppStatus = package.ApplicationStatus; - Warning = package.Warning; - Fault = package.Fault; - - lastRefreshTime = DateTime.Now; - } - } -} diff --git a/BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs b/BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs index 7702e89f..49ff81bf 100644 --- a/BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs +++ b/BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs @@ -12,26 +12,32 @@ namespace BPASmartClient.KLMCoffee.Protocal /// 系统状态 /// public K95SysTemStatus temStatus { get; set; } + /// /// 饮品类型 /// public DrinkType drinkType { get; set; } + /// /// 制作状态 /// public MakeStatus makeStatus { get; set; } + /// /// 当前任务 /// public TaskIndex taskIndex { get; set; } + /// /// 当前进度 10% /// public int progress { get; set; } + /// /// 故障信息 /// public FaultMessage faultMessage { get; set; } + /// /// 保养信息 /// diff --git a/BPASmartClient.Model/单片机/SCChipEvent.cs b/BPASmartClient.Model/单片机/SCChipEvent.cs index 6a76f911..44c618e5 100644 --- a/BPASmartClient.Model/单片机/SCChipEvent.cs +++ b/BPASmartClient.Model/单片机/SCChipEvent.cs @@ -17,7 +17,10 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_TakeCupEvent :BaseEvent { - + /// + /// 杯 + /// + public byte Cup { get; set; } } /// @@ -25,7 +28,7 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_MakeIceCreamEvent :BaseEvent { - + public byte SteeringEngine { get; set; } } /// @@ -33,7 +36,8 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_SESwitchCreamEvent :BaseEvent { - + public byte SteeringEngine { get; set; } + public bool IsOpen { get; set; } } /// @@ -41,6 +45,6 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_RotorSwitchEvent :BaseEvent { - + public bool TurnOn { get; set; } } } diff --git a/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs b/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs index 5d49b769..d0ddac8d 100644 --- a/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs +++ b/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs @@ -17,6 +17,7 @@ namespace BPASmartClient.Model /// public class DRCoffee_MakeCoffeeEvent :BaseEvent { + public byte DrinkCode { get; set; } } /// @@ -32,7 +33,7 @@ namespace BPASmartClient.Model /// public class DRCoffee_CoffeeCommCmdEvent :BaseEvent { - + public byte CommCmd { get; set; } } /// diff --git a/BPASmartClient.SCChip/BPASmartClient.SCChip.csproj b/BPASmartClient.SCChip/BPASmartClient.SCChip.csproj index 4bbee89a..7024144c 100644 --- a/BPASmartClient.SCChip/BPASmartClient.SCChip.csproj +++ b/BPASmartClient.SCChip/BPASmartClient.SCChip.csproj @@ -5,7 +5,7 @@ - + diff --git a/BPASmartClient.SCChip/ChipStatus.cs b/BPASmartClient.SCChip/ChipStatus.cs deleted file mode 100644 index 38f6a68f..00000000 --- a/BPASmartClient.SCChip/ChipStatus.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; - -namespace BPASmartClient.SCChip -{ - public class ChipStatus - { - private volatile static ChipStatus _Instance; - public static ChipStatus GetInstance() => _Instance ?? (_Instance = new ChipStatus()); - private ChipStatus() { } - - private DateTime lastRefreshTime = DateTime.MinValue; - /// - /// 是否在线 - /// - public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } - /// - /// 取冰淇淋杯完成 - /// - public bool CompletedTake_CPU_CUP_ICECREAM { get; set; } - /// - /// 取咖啡杯完成 - /// - public bool CompletedTake_CPU_CUP_COFFEE { get; set; } - /// - /// 1号舵机打开完成 - /// - public bool CompletedOpen_SE_1 { get; set; } - /// - /// 2号舵机打开完成 - /// - public bool CompletedOpen_SE_2 { get; set; } - /// - /// 3号舵机打开完成 - /// - public bool CompletedOpen_SE_3 { get; set; } - /// - /// 1号舵机关闭完成 - /// - public bool CompletedClose_SE_1 { get; set; } - /// - /// 2号舵机关闭完成 - /// - public bool CompletedClose_SE_2 { get; set; } - /// - /// 3号舵机关闭完成 - /// - public bool CompletedClose_SE_3 { get; set; } - /// - /// 是否存在物品 - /// - public bool ArticleExits { get; set; } - /// - /// 物品距离 - /// - public byte ArticleDist { get; set; } - - public bool CanDo - { - get - { - if (!OnLine) - return false; - return true; - } - } - - public void ProcessMsg(ICChipPackage data) - { - try - { - switch (data.Cmd) - { - case IC_CMD.HEART_BEAT: - lastRefreshTime = DateTime.Now; - break; - case IC_CMD.TAKE_CUP: - switch ((IC_CUP)data.Value) { - case IC_CUP.CUP_COFFEE: - CompletedTake_CPU_CUP_COFFEE = true; - break; - case IC_CUP.CUP_ICECREAM: - CompletedTake_CPU_CUP_ICECREAM = true; - break; - } - break; - case IC_CMD.OPEN_SE: - switch ((IC_SE)data.Value) - { - case IC_SE.SE_1: - CompletedOpen_SE_1 = true; - break; - case IC_SE.SE_2: - CompletedOpen_SE_2 = true; - break; - case IC_SE.SE_3: - CompletedOpen_SE_3 = true; - break; - } - break; - case IC_CMD.CLOSE_SE: - switch ((IC_SE)data.Value) - { - case IC_SE.SE_1: - CompletedClose_SE_1 = true; - break; - case IC_SE.SE_2: - CompletedClose_SE_2 = true; - break; - case IC_SE.SE_3: - CompletedClose_SE_3 = true; - break; - } - break; - case IC_CMD.ARTICLE_EXITS: - ArticleExits = data.Value > 0; - break; - case IC_CMD.ARTICLE_DIST: - ArticleDist = data.Value; - break; - } - } - catch (Exception ex) - { - - } - } - } -} diff --git a/BPASmartClient.SCChip/CommandEvent.cs b/BPASmartClient.SCChip/CommandEvent.cs deleted file mode 100644 index e7d500f8..00000000 --- a/BPASmartClient.SCChip/CommandEvent.cs +++ /dev/null @@ -1,42 +0,0 @@ -using BPASmartClient.SCChip; - -namespace BPASmartClient.SCChip -{ - public class TakeCupEvent - { - /// - /// 杯 - /// - public IC_CUP Cup { get; set; } - } - - public class MakeIceCreamEvent - { - public IC_SE SteeringEngine { get; set; } - } - - public class SESwitchCreamEvent - { - public IC_SE SteeringEngine { get; set; } - public bool IsOpen { get; set; } - } - - public class RotorSwitchEvent - { - public bool TurnOn { get; set; } - } - /// - /// 检测有无杯子 - /// - public class ArticleExitsEvent - { - - } - /// - /// 检测物品距离 - /// - public class ArticleDistEvent - { - - } -} diff --git a/BPASmartClient.SCChip/CommandHandler.cs b/BPASmartClient.SCChip/CommandHandler.cs deleted file mode 100644 index 157670ba..00000000 --- a/BPASmartClient.SCChip/CommandHandler.cs +++ /dev/null @@ -1,225 +0,0 @@ -using BPASmartClient.Message; -using BPASmartClient.MessageCommunication; -using BPASmartClient.MessageCommunication.MsgControl; -using BPASmartClient.SerialPort; -using System; -using System.Runtime.InteropServices; -using System.Threading; - -namespace BPASmartClient.SCChip -{ - /// - /// 指令封装 - /// - internal class CommandHandler - { - private SerialPortClient commProxy; - private ICChipPackage package = new ICChipPackage(); - - /// - /// 初始化 - /// - internal void Init(SerialPortClient commProxy) - { - this.commProxy = commProxy; - Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_TakeCup,"TakeCupHandler"); - Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_MakeIceCream,"MakeIceCreamHandler"); - Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_SESwitchCream,"SESwitchCreamHandler"); - Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_RotorSwitch,"RotorSwitchHandler"); - - } - - /// - /// STM32F103RCT6单片机舵机打开或者关闭 - /// - public void SESwitchCreamHandler(object sender,InnerMessageEventArgs e) - { - try - { - if (e.obj_MessageObj is TakeCupEvent) - { - ChipStatus.GetInstance().ArticleDist = 0; - package.Cmd = (e.obj_MessageObj as SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE; - package.Value = (byte)(e.obj_MessageObj as SESwitchCreamEvent).SteeringEngine; - commProxy.SendData(StructureToByte(package)); - } - } - catch (Exception ex) - { - MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,SESwitchCreamHandler 类,描述:[{ex.Message}]"); - } - } - - /// - /// STM32F103RCT6单片机控制冰淇淋机器转 - /// - public void RotorSwitchHandler(object sender,InnerMessageEventArgs e) - { - try - { - if (e.obj_MessageObj is RotorSwitchEvent) - { - package.Cmd = IC_CMD.ROTOR; - package.Value = (e.obj_MessageObj as RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.CLOSE_ROTOR; - commProxy.SendData(StructureToByte(package)); - } - } - catch (Exception ex) - { - MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,RotorSwitchHandler 类,描述:[{ex.Message}]"); - } - } - - /// - /// STM32F103RCT6单片机舵机打料 - /// - public void MakeIceCreamHandler(object sender,InnerMessageEventArgs e) - { - try - { - if (e.obj_MessageObj is MakeIceCreamEvent) - { - switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) - { - case IC_SE.SE_1: - ChipStatus.GetInstance().CompletedOpen_SE_1 = false; - break; - case IC_SE.SE_2: - ChipStatus.GetInstance().CompletedOpen_SE_2 = false; - break; - case IC_SE.SE_3: - ChipStatus.GetInstance().CompletedOpen_SE_3 = false; - break; - } - package.Cmd = IC_CMD.OPEN_SE; - package.Value = (byte)(e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine; - commProxy.SendData(StructureToByte(package)); - - bool wait = true; - DateTime waitTimeout = DateTime.Now.AddSeconds(3); - while (wait) - { - wait = DateTime.Now < waitTimeout; - if (wait) - { - switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) - { - case IC_SE.SE_1: - wait = !ChipStatus.GetInstance().CompletedOpen_SE_1; - break; - case IC_SE.SE_2: - wait = !ChipStatus.GetInstance().CompletedOpen_SE_2; - break; - case IC_SE.SE_3: - wait = !ChipStatus.GetInstance().CompletedOpen_SE_3; - break; - } - } - Thread.Sleep(10); - } - Thread.Sleep(2000); - package.Cmd = IC_CMD.CLOSE_SE; - package.Value = (byte)(e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine; - commProxy.SendData(StructureToByte(package)); - - wait = true; - waitTimeout = DateTime.Now.AddSeconds(3); - while (wait) - { - wait = DateTime.Now < waitTimeout; - if (wait) - { - switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) - { - case IC_SE.SE_1: - wait = !ChipStatus.GetInstance().CompletedClose_SE_1; - break; - case IC_SE.SE_2: - wait = !ChipStatus.GetInstance().CompletedClose_SE_2; - break; - case IC_SE.SE_3: - wait = !ChipStatus.GetInstance().CompletedClose_SE_3; - break; - } - } - Thread.Sleep(10); - } - } - } - catch (Exception ex) - { - MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,MakeIceCreamHandler 类,描述:[{ex.Message}]"); - } - } - - /// - /// STM32F103RCT6单片机下杯 - /// - public void TakeCupHandler(object sender,InnerMessageEventArgs e) - { - try - { - if (e.obj_MessageObj is TakeCupEvent) - { - switch ((e.obj_MessageObj as TakeCupEvent).Cup) - { - case IC_CUP.CUP_ICECREAM: - ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM = false; - break; - case IC_CUP.CUP_COFFEE: - ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE = false; - break; - } - package.Cmd = IC_CMD.TAKE_CUP; - package.Value = (byte)(e.obj_MessageObj as TakeCupEvent).Cup; - commProxy.SendData(StructureToByte(package)); - - bool wait = true; - var waitTimeout = DateTime.Now.AddSeconds(3); - while (wait) - { - wait = DateTime.Now < waitTimeout; - if (wait) - { - switch ((e.obj_MessageObj as TakeCupEvent).Cup) - { - case IC_CUP.CUP_ICECREAM: - wait = !ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM; - break; - case IC_CUP.CUP_COFFEE: - wait = !ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE; - break; - } - } - Thread.Sleep(10); - } - } - } - catch (Exception ex) - { - MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,TakeCupHandler 类,描述:[{ex.Message}]"); - } - } - - private byte[] StructureToByte(ICChipPackage structure) - { - structure.Header = 0xAA; - structure.Sender = IC_SENDER.CONSOLE; - structure.End = 0xBB; - - int size = Marshal.SizeOf(typeof(ICChipPackage)); - byte[] buffer = new byte[size]; - IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); - try - { - Marshal.StructureToPtr(structure, bufferIntPtr, true); - Marshal.Copy(bufferIntPtr, buffer, 0, size); - } - finally - { - Marshal.FreeHGlobal(bufferIntPtr); - } - return buffer; - } - } -} diff --git a/BPASmartClient.SCChip/ICChipMachine.cs b/BPASmartClient.SCChip/ICChipMachine.cs index e5eda44b..130436df 100644 --- a/BPASmartClient.SCChip/ICChipMachine.cs +++ b/BPASmartClient.SCChip/ICChipMachine.cs @@ -1,59 +1,85 @@ -using BPASmartClient.Helper; +using BPASmartClient.EventBus; +using BPASmartClient.Helper; +using BPASmartClient.Message; +using BPASmartClient.Model; +using BPASmartClient.Model.单片机; using BPASmartClient.Peripheral; using BPASmartClient.SerialPort; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading; +using static BPASmartClient.EventBus.EventBus; namespace BPASmartClient.SCChip { - public class ICChipMachine: BasePeripheral + public class ICChipMachine :BasePeripheral { - //指令组装 - private CommandHandler commandHandler = new CommandHandler(); //通讯代理 SerialPortClient commProxy = null; //数据仓库 private DataStorage dataStorage = new DataStorage(); - //主线程运行标识 - private bool running = false; - //是否下发指令,主线程等待 - public Action SendCallback; - public Action ReciveCallback; - - /// - /// 串口COM口 - /// + //单片机基础协议 + private ICChipPackage package = new ICChipPackage(); + //串口COM口 public string PortName { get; set; } + //串口波特率 + public string BaudRate { get; set; } + //心跳时间 + private DateTime lastRefreshTime = DateTime.MinValue; /// - /// 串口波特率 + /// 是否在线 /// - public string BaudRate { get; set; } + public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } public ICChipMachine() { - //commProxy = new SerialPortClient(portName, baud); - //commProxy.SetDataStorage(dataStorage); - //commandHandler.Init(commProxy); + } + /// + /// 主线程开始运行 + /// public override void Start() { - commProxy.Start(); - running = true; - MainLoop(); + try + { + commProxy.Start(); + IsConnected = true; + MainLoop(); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); + } + } - + /// + /// 停止运行 + /// + public override void Stop() + { + try + { + commProxy.Stop(); + IsConnected = false; + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); + } + } + /// + /// 主循环,循环询问状态 + /// private void MainLoop() { ThreadManage.GetInstance.StartLong(new Action(() => { ResolveMsg(); - //Thread.Sleep(2000); - }), "单片机解析线程"); + }),"单片机解析线程"); } private void ResolveMsg() @@ -74,7 +100,7 @@ namespace BPASmartClient.SCChip if (temp[4] == 0xBB) { var package = ByteToStructure(temp.ToArray()); - ChipStatus.GetInstance().ProcessMsg(package); + ProcessMsg(package); } temp.Clear(); } @@ -93,8 +119,8 @@ namespace BPASmartClient.SCChip IntPtr allocIntPtr = Marshal.AllocHGlobal(size); try { - Marshal.Copy(dataBuffer, 0, allocIntPtr, size); - structure = (ICChipPackage)Marshal.PtrToStructure(allocIntPtr, typeof(ICChipPackage)); + Marshal.Copy(dataBuffer,0,allocIntPtr,size); + structure = (ICChipPackage)Marshal.PtrToStructure(allocIntPtr,typeof(ICChipPackage)); } finally { @@ -103,16 +129,254 @@ namespace BPASmartClient.SCChip return structure; } - protected override void InitStatus() + private byte[] StructureToByte(ICChipPackage structure) { + structure.Header = 0xAA; + structure.Sender = IC_SENDER.CONSOLE; + structure.End = 0xBB; + + int size = Marshal.SizeOf(typeof(ICChipPackage)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure,bufferIntPtr,true); + Marshal.Copy(bufferIntPtr,buffer,0,size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; } - public override void Stop() + public void ProcessMsg(ICChipPackage data) + { + try + { + switch (data.Cmd) + { + case IC_CMD.HEART_BEAT: + lastRefreshTime = DateTime.Now; + status["OnLine"] = OnLine; + break; + case IC_CMD.TAKE_CUP: + switch ((IC_CUP)data.Value) + { + case IC_CUP.CUP_COFFEE: + status["CompletedTake_CPU_CUP_COFFEE"] = true; + break; + case IC_CUP.CUP_ICECREAM: + status["CompletedTake_CPU_CUP_ICECREAM"] = true; + break; + } + break; + case IC_CMD.OPEN_SE: + switch ((IC_SE)data.Value) + { + case IC_SE.SE_1: + status["CompletedOpen_SE_1"] = true; + break; + case IC_SE.SE_2: + status["CompletedOpen_SE_2"] = true; + break; + case IC_SE.SE_3: + status["CompletedOpen_SE_3"] = true; + break; + } + break; + case IC_CMD.CLOSE_SE: + switch ((IC_SE)data.Value) + { + case IC_SE.SE_1: + status["CompletedClose_SE_1"] = true; + break; + case IC_SE.SE_2: + status["CompletedClose_SE_2"] = true; + break; + case IC_SE.SE_3: + status["CompletedClose_SE_3"] = true; + break; + } + break; + } + if(!OnLine) IsWork = false; + else IsWork = true; + } + catch (Exception ex) + { + + } + } + + protected override void InitStatus() { + status["CompletedTake_CPU_CUP_ICECREAM"] = false; + status["CompletedTake_CPU_CUP_COFFEE"] = false; + status["CompletedOpen_SE_1"] = false; + status["CompletedOpen_SE_2"] = false; + status["CompletedOpen_SE_3"] = false; + status["CompletedClose_SE_1"] = false; + status["CompletedClose_SE_2"] = false; + status["CompletedClose_SE_3"] = false; } public override void Init() { + commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate)); + commProxy.SetDataStorage(dataStorage); + + //STM32F103RCT6单片机下杯 + EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) + { + try + { + switch ((IC_CUP)(@event as SCChip_TakeCupEvent).Cup) + { + case IC_CUP.CUP_ICECREAM: + status["CompletedTake_CPU_CUP_ICECREAM"] = false; + break; + case IC_CUP.CUP_COFFEE: + status["CompletedTake_CPU_CUP_COFFEE"] = false; + break; + } + package.Cmd = IC_CMD.TAKE_CUP; + package.Value = (byte)(@event as SCChip_TakeCupEvent).Cup; + commProxy.SendData(StructureToByte(package)); + + bool wait = true; + var waitTimeout = DateTime.Now.AddSeconds(3); + while (wait) + { + wait = DateTime.Now < waitTimeout; + if (wait) + { + switch ((IC_CUP)(@event as SCChip_TakeCupEvent).Cup) + { + case IC_CUP.CUP_ICECREAM: + wait = !(bool)status["CompletedTake_CPU_CUP_ICECREAM"]; + break; + case IC_CUP.CUP_COFFEE: + wait = !(bool)status["CompletedTake_CPU_CUP_COFFEE"]; + break; + } + } + Thread.Sleep(10); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); + } + }); + + //STM32F103RCT6单片机舵机打料 + EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) + { + try + { + switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) + { + case IC_SE.SE_1: + status["CompletedOpen_SE_1"] = false; + break; + case IC_SE.SE_2: + status["CompletedOpen_SE_2"] = false; + break; + case IC_SE.SE_3: + status["CompletedOpen_SE_3"] = false; + break; + } + package.Cmd = IC_CMD.OPEN_SE; + package.Value = (byte)(@event as SCChip_MakeIceCreamEvent).SteeringEngine; + commProxy.SendData(StructureToByte(package)); + + bool wait = true; + DateTime waitTimeout = DateTime.Now.AddSeconds(3); + while (wait) + { + wait = DateTime.Now < waitTimeout; + if (wait) + { + switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) + { + case IC_SE.SE_1: + wait = !(bool)status["CompletedOpen_SE_1"]; + break; + case IC_SE.SE_2: + wait = !(bool)status["CompletedOpen_SE_2"]; + break; + case IC_SE.SE_3: + wait = !(bool)status["CompletedOpen_SE_3"]; + break; + } + } + Thread.Sleep(10); + } + Thread.Sleep(2000); + package.Cmd = IC_CMD.CLOSE_SE; + package.Value = (byte)(@event as SCChip_MakeIceCreamEvent).SteeringEngine; + commProxy.SendData(StructureToByte(package)); + + wait = true; + waitTimeout = DateTime.Now.AddSeconds(3); + while (wait) + { + wait = DateTime.Now < waitTimeout; + if (wait) + { + switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) + { + case IC_SE.SE_1: + wait = !(bool)status["CompletedClose_SE_1"]; + break; + case IC_SE.SE_2: + wait = !(bool)status["CompletedClose_SE_2"]; + break; + case IC_SE.SE_3: + wait = !(bool)status["CompletedClose_SE_3"]; + break; + } + } + Thread.Sleep(10); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); + } + }); + + //STM32F103RCT6单片机舵机打开或者关闭 + EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) + { + try + { + package.Cmd = (@event as SCChip_SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE; + package.Value = (byte)(@event as SCChip_SESwitchCreamEvent).SteeringEngine; + commProxy.SendData(StructureToByte(package)); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeCommCmdHandler 类,描述:[{ex.Message}]"); + } + }); + + //STM32F103RCT6单片机控制冰淇淋机器转 + EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) + { + try + { + package.Cmd = IC_CMD.ROTOR; + package.Value = (@event as SCChip_RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.CLOSE_ROTOR; + commProxy.SendData(StructureToByte(package)); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); + } + }); + } } diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index 526bfc3b..20f0da1c 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -10,6 +10,6 @@ public class GSIceCream_ModeSetEvent :BaseEvent { - + public byte Mode { get; set; } } /// @@ -33,6 +33,9 @@ namespace BPASmartClient.Model /// public class GSIceCream_EndCookEvent :BaseEvent { - + /// + /// 状态:true 成功 false 失败 + /// + public bool Status { get; set; } } } From c4738d5ecf7abd1800bb2fcc3d583ad079109332 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Wed, 20 Apr 2022 09:52:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1.=E8=B0=83=E6=95=B4=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=9E=9A=E4=B8=BE=E5=88=B0Model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.DRCoffee/CoffeeMachine.cs | 5 +++-- BPASmartClient.DRCoffee/Protocal/DrCoffeePackage.cs | 3 ++- BPASmartClient.GSIceCream/IceCreamMachine.cs | 5 +++-- BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_DW.cs | 3 ++- BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_UP.cs | 3 ++- BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_DW.cs | 3 ++- BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_UP.cs | 3 ++- BPASmartClient.Model/BPASmartClient.Model.csproj | 2 +- .../冰淇淋/Enum}/MORKI_MODE.cs | 2 +- BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs | 5 +++-- .../单片机/Enum}/IC_CUP.cs | 2 +- .../单片机/Enum}/IC_SE.cs | 2 +- BPASmartClient.Model/单片机/SCChipEvent.cs | 9 +++++---- BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs | 7 ++++--- .../咖啡机/Enum}/DrCoffeeCommCmd.cs | 4 ++-- .../咖啡机/Enum}/DrCoffeeDrinksCode.cs | 4 ++-- BPASmartClient.SCChip/ICChipMachine.cs | 5 +++-- BPASmartClient/MainWindow.xaml.cs | 6 ++++-- 18 files changed, 43 insertions(+), 30 deletions(-) rename {BPASmartClient.GSIceCream/Protocal => BPASmartClient.Model/冰淇淋/Enum}/MORKI_MODE.cs (95%) rename {BPASmartClient.SCChip/Protocal => BPASmartClient.Model/单片机/Enum}/IC_CUP.cs (89%) rename {BPASmartClient.SCChip/Protocal => BPASmartClient.Model/单片机/Enum}/IC_SE.cs (91%) rename {BPASmartClient.DRCoffee/Protocal => BPASmartClient.Model/咖啡机/Enum}/DrCoffeeCommCmd.cs (93%) rename {BPASmartClient.DRCoffee/Protocal => BPASmartClient.Model/咖啡机/Enum}/DrCoffeeDrinksCode.cs (91%) diff --git a/BPASmartClient.DRCoffee/CoffeeMachine.cs b/BPASmartClient.DRCoffee/CoffeeMachine.cs index 9d07749d..db8e06cc 100644 --- a/BPASmartClient.DRCoffee/CoffeeMachine.cs +++ b/BPASmartClient.DRCoffee/CoffeeMachine.cs @@ -3,6 +3,7 @@ using BPASmartClient.EventBus; using BPASmartClient.Helper; using BPASmartClient.Message; using BPASmartClient.Model; +using BPASmartClient.Model.咖啡机.Enum; using BPASmartClient.Peripheral; using BPASmartClient.SerialPort; using System; @@ -180,7 +181,7 @@ namespace BPASmartClient.DRCoffee free = true; Thread.Sleep(200); drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; - drinksOrder.DrinksCode = (DrCoffeeDrinksCode)((DRCoffee_MakeCoffeeEvent)@event).DrinkCode; + drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).DrinkCode; commProxy.SendData(DrCoffee.Packe(drinksOrder)); Thread.Sleep(200); free = false; @@ -217,7 +218,7 @@ namespace BPASmartClient.DRCoffee { free = true; Thread.Sleep(200); - drinksOrder.CommCmd = (DrCoffeeCommCmd)((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd; + drinksOrder.CommCmd = ((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd; commProxy.SendData(DrCoffee.Packe(drinksOrder)); Thread.Sleep(200); free = false; diff --git a/BPASmartClient.DRCoffee/Protocal/DrCoffeePackage.cs b/BPASmartClient.DRCoffee/Protocal/DrCoffeePackage.cs index f1aafa02..563affe6 100644 --- a/BPASmartClient.DRCoffee/Protocal/DrCoffeePackage.cs +++ b/BPASmartClient.DRCoffee/Protocal/DrCoffeePackage.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.咖啡机.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; diff --git a/BPASmartClient.GSIceCream/IceCreamMachine.cs b/BPASmartClient.GSIceCream/IceCreamMachine.cs index 85e80e0a..79a66028 100644 --- a/BPASmartClient.GSIceCream/IceCreamMachine.cs +++ b/BPASmartClient.GSIceCream/IceCreamMachine.cs @@ -2,6 +2,7 @@ using BPASmartClient.Helper; using BPASmartClient.Message; using BPASmartClient.Model; +using BPASmartClient.Model.冰淇淋.Enum; using BPASmartClient.Peripheral; using BPASmartClient.SerialPort; using System; @@ -252,11 +253,11 @@ namespace BPASmartClient.GSIceCream { free = true; Thread.Sleep(200); - var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build((MORKI_MODE)((GSIceCream_ModeSetEvent)@event).Mode)); + var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((GSIceCream_ModeSetEvent)@event).Mode)); commProxy.SendData(data); Thread.Sleep(200); free = false; - MessageLog.GetInstance.Show(string.Format("设置模式[{0}]",Enum.GetName(typeof(MORKI_MODE),(MORKI_MODE)((GSIceCream_ModeSetEvent)@event).Mode))); + MessageLog.GetInstance.Show(string.Format("设置模式[{0}]",Enum.GetName(typeof(MORKI_MODE),((GSIceCream_ModeSetEvent)@event).Mode))); } catch (Exception ex) { diff --git a/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_DW.cs b/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_DW.cs index e3bb0f30..a7973bb6 100644 --- a/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_DW.cs +++ b/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_DW.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.冰淇淋.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; diff --git a/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_UP.cs b/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_UP.cs index 90a127fb..a2daf77e 100644 --- a/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_UP.cs +++ b/BPASmartClient.GSIceCream/Protocal/ICMSG_Heart_UP.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.冰淇淋.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; diff --git a/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_DW.cs b/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_DW.cs index eb0fb4a4..fd34abfb 100644 --- a/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_DW.cs +++ b/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_DW.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.冰淇淋.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; diff --git a/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_UP.cs b/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_UP.cs index 3f16a278..2a19b575 100644 --- a/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_UP.cs +++ b/BPASmartClient.GSIceCream/Protocal/ICMSG_MODE_UP.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using BPASmartClient.Model.冰淇淋.Enum; +using System.Runtime.InteropServices; using static BPASmartClient.GSIceCream.MessageDefine; namespace BPASmartClient.GSIceCream diff --git a/BPASmartClient.Model/BPASmartClient.Model.csproj b/BPASmartClient.Model/BPASmartClient.Model.csproj index 4de56856..df1a01f9 100644 --- a/BPASmartClient.Model/BPASmartClient.Model.csproj +++ b/BPASmartClient.Model/BPASmartClient.Model.csproj @@ -11,7 +11,7 @@ - + diff --git a/BPASmartClient.GSIceCream/Protocal/MORKI_MODE.cs b/BPASmartClient.Model/冰淇淋/Enum/MORKI_MODE.cs similarity index 95% rename from BPASmartClient.GSIceCream/Protocal/MORKI_MODE.cs rename to BPASmartClient.Model/冰淇淋/Enum/MORKI_MODE.cs index 85e40580..772556d8 100644 --- a/BPASmartClient.GSIceCream/Protocal/MORKI_MODE.cs +++ b/BPASmartClient.Model/冰淇淋/Enum/MORKI_MODE.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.GSIceCream +namespace BPASmartClient.Model.冰淇淋.Enum { /* * 模式 参数 diff --git a/BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs b/BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs index a4b413e9..ea9d0468 100644 --- a/BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs +++ b/BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.冰淇淋.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,7 +18,7 @@ namespace BPASmartClient.Model /// public class GSIceCream_ModeSetEvent :BaseEvent { - public byte Mode { get; set; } + public MORKI_MODE Mode { get; set; } } /// diff --git a/BPASmartClient.SCChip/Protocal/IC_CUP.cs b/BPASmartClient.Model/单片机/Enum/IC_CUP.cs similarity index 89% rename from BPASmartClient.SCChip/Protocal/IC_CUP.cs rename to BPASmartClient.Model/单片机/Enum/IC_CUP.cs index a85f0e58..695bb5e2 100644 --- a/BPASmartClient.SCChip/Protocal/IC_CUP.cs +++ b/BPASmartClient.Model/单片机/Enum/IC_CUP.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SCChip +namespace BPASmartClient.Model.单片机.Enum { /// /// 杯子 diff --git a/BPASmartClient.SCChip/Protocal/IC_SE.cs b/BPASmartClient.Model/单片机/Enum/IC_SE.cs similarity index 91% rename from BPASmartClient.SCChip/Protocal/IC_SE.cs rename to BPASmartClient.Model/单片机/Enum/IC_SE.cs index 5d3e073a..a22bcb59 100644 --- a/BPASmartClient.SCChip/Protocal/IC_SE.cs +++ b/BPASmartClient.Model/单片机/Enum/IC_SE.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SCChip +namespace BPASmartClient.Model.单片机.Enum { /// /// 冰淇淋舵机 diff --git a/BPASmartClient.Model/单片机/SCChipEvent.cs b/BPASmartClient.Model/单片机/SCChipEvent.cs index 44c618e5..a7e6f201 100644 --- a/BPASmartClient.Model/单片机/SCChipEvent.cs +++ b/BPASmartClient.Model/单片机/SCChipEvent.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.单片机.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -20,7 +21,7 @@ namespace BPASmartClient.Model.单片机 /// /// 杯 /// - public byte Cup { get; set; } + public IC_CUP Cup { get; set; } } /// @@ -28,7 +29,7 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_MakeIceCreamEvent :BaseEvent { - public byte SteeringEngine { get; set; } + public IC_SE SteeringEngine { get; set; } } /// @@ -36,7 +37,7 @@ namespace BPASmartClient.Model.单片机 /// public class SCChip_SESwitchCreamEvent :BaseEvent { - public byte SteeringEngine { get; set; } + public IC_SE SteeringEngine { get; set; } public bool IsOpen { get; set; } } diff --git a/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs b/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs index d0ddac8d..3df8ead2 100644 --- a/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs +++ b/BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.Model.咖啡机.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,7 +18,7 @@ namespace BPASmartClient.Model /// public class DRCoffee_MakeCoffeeEvent :BaseEvent { - public byte DrinkCode { get; set; } + public DrCoffeeDrinksCode DrinkCode { get; set; } } /// @@ -33,7 +34,7 @@ namespace BPASmartClient.Model /// public class DRCoffee_CoffeeCommCmdEvent :BaseEvent { - public byte CommCmd { get; set; } + public DrCoffeeCommCmd CommCmd { get; set; } } /// diff --git a/BPASmartClient.DRCoffee/Protocal/DrCoffeeCommCmd.cs b/BPASmartClient.Model/咖啡机/Enum/DrCoffeeCommCmd.cs similarity index 93% rename from BPASmartClient.DRCoffee/Protocal/DrCoffeeCommCmd.cs rename to BPASmartClient.Model/咖啡机/Enum/DrCoffeeCommCmd.cs index d58adee2..bed221c0 100644 --- a/BPASmartClient.DRCoffee/Protocal/DrCoffeeCommCmd.cs +++ b/BPASmartClient.Model/咖啡机/Enum/DrCoffeeCommCmd.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.DRCoffee +namespace BPASmartClient.Model.咖啡机.Enum { /// /// 通信指令 /// - public enum DrCoffeeCommCmd : byte + public enum DrCoffeeCommCmd :byte { 无指令 = 0x00, 饮品制作指令 = 0x01, diff --git a/BPASmartClient.DRCoffee/Protocal/DrCoffeeDrinksCode.cs b/BPASmartClient.Model/咖啡机/Enum/DrCoffeeDrinksCode.cs similarity index 91% rename from BPASmartClient.DRCoffee/Protocal/DrCoffeeDrinksCode.cs rename to BPASmartClient.Model/咖啡机/Enum/DrCoffeeDrinksCode.cs index fb7d67e7..a86926bc 100644 --- a/BPASmartClient.DRCoffee/Protocal/DrCoffeeDrinksCode.cs +++ b/BPASmartClient.Model/咖啡机/Enum/DrCoffeeDrinksCode.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.DRCoffee +namespace BPASmartClient.Model.咖啡机.Enum { /// /// 饮品编号 /// - public enum DrCoffeeDrinksCode : byte + public enum DrCoffeeDrinksCode :byte { 意式浓缩 = 1, 美式咖啡 = 2, diff --git a/BPASmartClient.SCChip/ICChipMachine.cs b/BPASmartClient.SCChip/ICChipMachine.cs index 130436df..4ef0958e 100644 --- a/BPASmartClient.SCChip/ICChipMachine.cs +++ b/BPASmartClient.SCChip/ICChipMachine.cs @@ -3,6 +3,7 @@ using BPASmartClient.Helper; using BPASmartClient.Message; using BPASmartClient.Model; using BPASmartClient.Model.单片机; +using BPASmartClient.Model.单片机.Enum; using BPASmartClient.Peripheral; using BPASmartClient.SerialPort; using System; @@ -231,7 +232,7 @@ namespace BPASmartClient.SCChip { try { - switch ((IC_CUP)(@event as SCChip_TakeCupEvent).Cup) + switch ((@event as SCChip_TakeCupEvent).Cup) { case IC_CUP.CUP_ICECREAM: status["CompletedTake_CPU_CUP_ICECREAM"] = false; @@ -251,7 +252,7 @@ namespace BPASmartClient.SCChip wait = DateTime.Now < waitTimeout; if (wait) { - switch ((IC_CUP)(@event as SCChip_TakeCupEvent).Cup) + switch ((@event as SCChip_TakeCupEvent).Cup) { case IC_CUP.CUP_ICECREAM: wait = !(bool)status["CompletedTake_CPU_CUP_ICECREAM"]; diff --git a/BPASmartClient/MainWindow.xaml.cs b/BPASmartClient/MainWindow.xaml.cs index 39082190..e518fb42 100644 --- a/BPASmartClient/MainWindow.xaml.cs +++ b/BPASmartClient/MainWindow.xaml.cs @@ -1,6 +1,8 @@ using BPASmartClient.Business; using BPASmartClient.EventBus; using BPASmartClient.Model; +using BPASmartClient.Model.冰淇淋.Enum; +using BPASmartClient.Model.咖啡机.Enum; using System; using System.Collections.Generic; using System.Linq; @@ -32,8 +34,8 @@ namespace BPASmartClient private void Button_Click(object sender, RoutedEventArgs e) { new Demo_MakeCoffeeEvent() { Id = "1" }.Publish(); - new DRCoffee_MakeCoffeeEvent() { Id = "1", DrinkCode=120 }.Publish(); - new DRCoffee_CoffeeCommCmdEvent() { Id = "1",CommCmd = 0x01 }.Publish(); + new DRCoffee_MakeCoffeeEvent() { Id = "1", DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish(); + new DRCoffee_CoffeeCommCmdEvent() { Id = "1",CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish(); } }