diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index 3c7b329..17ed84b 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -35,9 +35,8 @@ namespace HBLConsole.MORKIC GVL_MORIC mORKD = new GVL_MORIC(); //咖啡机主控程序 private CoffeeMachine coffeeMachine; + //单片机主控程序 private ICChipMachine icchipMachine; - //冰淇淋主控程序 - private IceCreamMachine iceCreamMachine; //物料存放位置 private Dictionary batchings = new Dictionary(); //容器位置 @@ -98,8 +97,7 @@ namespace HBLConsole.MORKIC } //咖啡机创建 coffeeMachine = new CoffeeMachine(com_Coffee, (BaudRates)Enum.Parse(typeof(BaudRates), baud_Coffee)); - //冰淇淋机创建 - iceCreamMachine = new IceCreamMachine(com_IceCream, (BaudRates)Enum.Parse(typeof(BaudRates), baud_IceCream)); + //单片机机创建 icchipMachine = new ICChipMachine(com_ICChip, (BaudRates)Enum.Parse(typeof(BaudRates), baud_ICChip)); Main(); @@ -171,23 +169,17 @@ namespace HBLConsole.MORKIC { //咖啡机开启主线程 coffeeMachine.Start(); - //冰淇淋机开启主线程 - iceCreamMachine.Start(); + //单片机开启主线程 icchipMachine.Start(); new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); //开始心跳刷新,根据咖啡机及冰淇淋机来判断 ThreadManage.GetInstance.StartLong(new Action(() => { - - //GeneralConfig.Healthy = true; - //GeneralConfig.Healthy = - // LebaiHelper.GetInstance.IsConnected && - // MorkIStatus.GetInstance().CanDo && - // MorkCStatus.GetInstance().CanDo; GeneralConfig.Healthy = LebaiHelper.GetInstance.IsConnected && - MorkCStatus.GetInstance().CanDo; + MorkCStatus.GetInstance().CanDo && + ChipStatus.GetInstance().CanDo; //GeneralConfig.Healthy = true; Thread.Sleep(100); }), "MORK-IC心跳刷新"); diff --git a/HBLDevice.ICChip/ChipStatus.cs b/HBLDevice.ICChip/ChipStatus.cs index 2c9c07a..0c347cf 100644 --- a/HBLDevice.ICChip/ChipStatus.cs +++ b/HBLDevice.ICChip/ChipStatus.cs @@ -47,6 +47,14 @@ namespace HBLDevice.ICChip /// 3号舵机关闭完成 /// public bool CompletedClose_SE_3 { get; set; } + /// + /// 是否存在物品 + /// + public bool ArticleExits { get; set; } + /// + /// 物品距离 + /// + public byte ArticleDist { get; set; } public bool CanDo { @@ -105,6 +113,12 @@ namespace HBLDevice.ICChip 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/HBLDevice.ICChip/CommandEvent.cs b/HBLDevice.ICChip/CommandEvent.cs index fe2076f..7866dc0 100644 --- a/HBLDevice.ICChip/CommandEvent.cs +++ b/HBLDevice.ICChip/CommandEvent.cs @@ -30,4 +30,14 @@ namespace HBLDevice.ICChip { public bool TurnOn { get; set; } } + + public class ArticleExitsEvent : IEvent + { + + } + + public class ArticleDistEvent : IEvent + { + + } } diff --git a/HBLDevice.ICChip/CommandHandler.cs b/HBLDevice.ICChip/CommandHandler.cs index eb23c40..b54882c 100644 --- a/HBLDevice.ICChip/CommandHandler.cs +++ b/HBLDevice.ICChip/CommandHandler.cs @@ -30,10 +30,26 @@ namespace HBLDevice.ICChip EventBus.GetInstance().Subscribe(MakeIceCreamEventHandle); EventBus.GetInstance().Subscribe(StopMakeIceCreamEventHandle); EventBus.GetInstance().Subscribe(RotorSwitchEventHandle); + EventBus.GetInstance().Subscribe(ArticleExitsEventHandle); + EventBus.GetInstance().Subscribe(ArticleDistEventHandle); + } + + private void ArticleDistEventHandle(IEvent @event, EventCallBackHandle callBack) + { + package.Cmd = IC_CMD.ARTICLE_DIST; + commProxy.SendData(StructureToByte(package)); + } + + private void ArticleExitsEventHandle(IEvent @event, EventCallBackHandle callBack) + { + ChipStatus.GetInstance().ArticleExits = false; + package.Cmd = IC_CMD.ARTICLE_EXITS; + commProxy.SendData(StructureToByte(package)); } private void StopMakeIceCreamEventHandle(IEvent @event, EventCallBackHandle callBack) { + ChipStatus.GetInstance().ArticleDist = 0; package.Cmd = (@event as SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE; package.Value = (byte)(@event as SESwitchCreamEvent).SteeringEngine; commProxy.SendData(StructureToByte(package)); diff --git a/HBLDevice.ICChip/Protocal/ICChipPackage.cs b/HBLDevice.ICChip/Protocal/ICChipPackage.cs index 3b23094..0383cd9 100644 --- a/HBLDevice.ICChip/Protocal/ICChipPackage.cs +++ b/HBLDevice.ICChip/Protocal/ICChipPackage.cs @@ -26,7 +26,7 @@ namespace HBLDevice.ICChip /// public IC_CMD Cmd; /// - /// 故障(咖啡机负责写,工控机负责读) + /// 值 /// public byte Value; /// diff --git a/HBLDevice.ICChip/Protocal/IC_CMD.cs b/HBLDevice.ICChip/Protocal/IC_CMD.cs index 776ed96..81cfb36 100644 --- a/HBLDevice.ICChip/Protocal/IC_CMD.cs +++ b/HBLDevice.ICChip/Protocal/IC_CMD.cs @@ -9,20 +9,20 @@ namespace HBLDevice.ICChip /// /// 命令 /// - public enum IC_CMD:byte + public enum IC_CMD : byte { /// /// 心跳 /// - HEART_BEAT=0x00, + HEART_BEAT = 0x00, /// /// 下杯(带上碗参数) /// - TAKE_CUP=0x01, + TAKE_CUP = 0x01, /// /// 打开舵机(带上舵机参数) /// - OPEN_SE=0x02, + OPEN_SE = 0x02, /// /// 关闭舵机(带上舵机参数) /// @@ -30,6 +30,14 @@ namespace HBLDevice.ICChip /// /// 使能冰淇淋转子(带上开关参数) /// - ROTOR=0x04, + ROTOR = 0x04, + /// + /// 检测是否有物品 + /// + ARTICLE_EXITS = 0x05, + /// + /// 检测物品距离 + /// + ARTICLE_DIST = 0x06 } }