diff --git a/BPASmartClient.DRCoffee/CommandHandler.cs b/BPASmartClient.DRCoffee/CommandHandler.cs
new file mode 100644
index 00000000..7e05e827
--- /dev/null
+++ b/BPASmartClient.DRCoffee/CommandHandler.cs
@@ -0,0 +1,85 @@
+
+using BPASmartClient.EventBus;
+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 BPASmartClient.EventBus.EventBus;
+
+namespace BPASmartClient.DRCoffee
+{
+ ///
+ /// 指令封装
+ ///
+ internal class CommandHandler
+ {
+ byte[] cmdAsk;
+ private SerialPortClient commProxy;
+ private DrCoffeePackage drinksOrder = new DrCoffeePackage();
+
+ public Action PauseAsk { get; set; }
+ ///
+ /// 初始化
+ ///
+ internal void Init(SerialPortClient commProxy)
+ {
+ this.commProxy = commProxy;
+
+ DrCoffeePackage package = new DrCoffeePackage();
+ package.CommCmd = DrCoffeeCommCmd.饮品制作指令;
+ cmdAsk = DrCoffee.Packe(package);
+ drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
+
+ EventBus.EventBus.GetInstance().Subscribe(0,MakeCoffeeEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, CancelMakeCoffeeEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(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);
+ }
+
+ ///
+ /// 发送状态询问
+ ///
+ internal byte[] GetStatusAsk()
+ {
+ return cmdAsk;
+ }
+ }
+}
diff --git a/BPASmartClient.DRCoffee/MorkCStatus.cs b/BPASmartClient.DRCoffee/MorkCStatus.cs
new file mode 100644
index 00000000..3c4555d8
--- /dev/null
+++ b/BPASmartClient.DRCoffee/MorkCStatus.cs
@@ -0,0 +1,76 @@
+using BPASmartClient.DRCoffee;
+using BPASmartClient.EventBus;
+using BPASmartClient.Helper;
+using BPASmartClient.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DRCoffee
+{
+ public class MorkCStatus : Singleton
+ {
+ private DRCoffee_CoffeEndCookEvent coffeEndCook = new DRCoffee_CoffeEndCookEvent();
+ 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;
+ coffeEndCook.Publish();
+ }
+ else
+ {
+ CoffeeStatus = package.Status;
+ }
+
+ AppStatus = package.ApplicationStatus;
+ Warning = package.Warning;
+ Fault = package.Fault;
+
+ lastRefreshTime = DateTime.Now;
+ }
+ }
+}
diff --git a/BPASmartClient.GSIceCream/CommandHandler.cs b/BPASmartClient.GSIceCream/CommandHandler.cs
new file mode 100644
index 00000000..1f58587b
--- /dev/null
+++ b/BPASmartClient.GSIceCream/CommandHandler.cs
@@ -0,0 +1,118 @@
+
+using BPASmartClient.EventBus;
+using BPASmartClient.GSIceCream;
+using BPASmartClient.Message;
+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 BPASmartClient.EventBus.EventBus;
+
+namespace BPASmartClient.DRCoffee
+{
+ ///
+ /// 指令封装
+ ///
+ internal class CommandHandler
+ {
+ byte[] cmdHeartDW;
+
+ private SerialPortClient commProxy;
+ private GSIceCream_EndCookEvent iceCreamEndCook = new GSIceCream_EndCookEvent();
+ public Action PauseAsk { get; set; }
+
+ ///
+ /// 初始化
+ ///
+ internal void Init(SerialPortClient commProxy)
+ {
+ this.commProxy = commProxy;
+ ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW();
+ cmdHeartDW = IcPack.StructureToByte(heartDW);
+ EventBus.EventBus.GetInstance().Subscribe(0, ModeSetEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0,DischargeEventHandle);
+ }
+ ///
+ /// 发送心跳
+ ///
+ internal byte[] GetHeartDW()
+ {
+ return cmdHeartDW;
+ }
+
+
+ public void ModeSetEventHandle(IEvent @event, EventCallBackHandle callBack = null)
+ {
+ PauseAsk?.Invoke(true);
+ Thread.Sleep(200);
+ var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((GSIceCream_ModeSetEvent)@event).Mode));
+ commProxy.SendData(data);
+ Thread.Sleep(200);
+ PauseAsk?.Invoke(false);
+ MessageLog.GetInstance.Show(string.Format("设置模式[{0}]", ((GSIceCream_ModeSetEvent)@event).Mode));
+ }
+
+ public void DischargeEventHandle(IEvent @event, EventCallBackHandle callBack = null)
+ {
+ if (MorkIStatus.GetInstance().Fault != MORKI_FAULT.未发生故障)
+ {
+ MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作", MorkIStatus.GetInstance().Fault));
+ callBack?.Invoke(false);
+ return;
+ }
+ if (MorkIStatus.GetInstance().CXB <= 86)
+ {
+ MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作", MorkIStatus.GetInstance().CXB));
+ callBack?.Invoke(false);
+ return;
+ }
+
+ bool modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
+
+ if (!modeRight)
+ {
+ PauseAsk?.Invoke(true);
+ Thread.Sleep(200);
+
+ var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
+ commProxy.SendData(temp);
+
+ Thread.Sleep(200);
+ PauseAsk?.Invoke(false);
+ MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.制冷模式));
+
+ DateTime freeTime = DateTime.Now.AddSeconds(5);
+ while (DateTime.Now < freeTime)
+ {
+ Thread.Sleep(10);
+ modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
+ if (modeRight)
+ break;
+ }
+ }
+
+ if (modeRight)
+ {
+ PauseAsk?.Invoke(true);
+ Thread.Sleep(200);
+ var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
+ commProxy.SendData(data);
+ Thread.Sleep(200);
+ PauseAsk?.Invoke(false);
+ iceCreamEndCook.Publish();
+ MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.打料));
+ callBack?.Invoke(true);
+ }
+ else
+ {
+ MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料", MorkIStatus.GetInstance().CurrentMode));
+ callBack?.Invoke(false);
+ }
+ }
+ }
+}
diff --git a/BPASmartClient.GSIceCream/MorkIStatus.cs b/BPASmartClient.GSIceCream/MorkIStatus.cs
new file mode 100644
index 00000000..717a1b4d
--- /dev/null
+++ b/BPASmartClient.GSIceCream/MorkIStatus.cs
@@ -0,0 +1,131 @@
+using BPASmartClient.GSIceCream;
+using BPASmartClient.Helper;
+using BPASmartClient.Message;
+using BPASmartClient.Model.冰淇淋.Enum;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static BPASmartClient.GSIceCream.MessageDefine;
+
+namespace BPASmartClient.GSIceCream
+{
+ public class MorkIStatus : Singleton
+ {
+ private DateTime lastRefreshTime = DateTime.MinValue;
+ ///
+ /// 是否在线
+ ///
+ public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } }
+ ///
+ /// 预冷温度
+ ///
+ public short YLWD { get; set; }
+ ///
+ /// 回气温度
+ ///
+ public short HQWD { get; set; }
+ ///
+ /// 环境温度
+ ///
+ public short HJWD { get; set; }
+ ///
+ /// 电流
+ ///
+ public short DL { get; set; }
+ ///
+ /// 电压
+ ///
+ public short DY { get; set; }
+ ///
+ /// 当前模式
+ ///
+ public MORKI_MODE CurrentMode { get; set; }
+ ///
+ /// 故障
+ ///
+ public MORKI_FAULT Fault { get; set; }
+ ///
+ /// 成型比
+ ///
+ public byte CXB { get; set; }
+ ///
+ /// 成型比(门限)
+ ///
+ public byte CXB_Threshold { get; set; }
+ ///
+ /// 打料完成(完成为true,正在打料为false)
+ ///
+ public bool DLCompleted { get; set; }
+
+
+ public bool CanDo
+ {
+ get
+ {
+ if (!OnLine)
+ return false;
+ if (Fault != MORKI_FAULT.未发生故障)
+ return false;
+ if (CXB < CXB_Threshold)
+ return false;
+ return true;
+ }
+ }
+
+ private void ProcessHeart(ICMSG_Heart_UP heartUpMsg)
+ {
+ CurrentMode = heartUpMsg.MS;
+ YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0);
+ HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0);
+ HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0);
+ DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0);
+ Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
+ CXB = heartUpMsg.CXB;
+ DLCompleted = (heartUpMsg.DLTJ >> 4 & 1) == 1;
+
+ if (RTrig.GetInstance("打料完成检测").Start(DLCompleted))
+ {
+ MessageLog.GetInstance.Show("打料完成");
+ }
+
+ if (RTrig.GetInstance("打料中检测").Start(!DLCompleted))
+ {
+ MessageLog.GetInstance.Show("打料中");
+ }
+ //MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
+
+ }
+
+ private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)
+ {
+ MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode));
+ }
+
+ public void ProcessMsg(byte[] data)
+ {
+ lastRefreshTime = DateTime.Now;
+ try
+ {
+ if (data.Length < 5)
+ return;
+ switch (data[2])
+ {
+ case (byte)IC_CMD.HEART:
+ var msg = IcPack.ByteToStructure(data.ToArray());
+ ProcessHeart(msg);
+ break;
+ case (byte)IC_CMD.MODE:
+ var modeUp = IcPack.ByteToStructure(data.ToArray());
+ ProcessModeUp(modeUp);
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+ }
+}
diff --git a/BPASmartClient.Lebai/LebaiRobot.cs b/BPASmartClient.Lebai/LebaiRobot.cs
index 8042c40f..58953747 100644
--- a/BPASmartClient.Lebai/LebaiRobot.cs
+++ b/BPASmartClient.Lebai/LebaiRobot.cs
@@ -67,6 +67,12 @@ namespace BPASmartClient.Lebai
public const int SENCE_接3号冰淇淋 = 10041;
public const int SENCE_放咖啡位置 = 10042;
public const int SENCE_放冰淇淋位置 = 10043;
+
+ //add 新加场景
+ public const int SENCE_接咖啡_新 = 10051;
+ public const int SENCE_咖啡杯回原点 = 10050;
+ public const int SENCE_冰淇淋杯回原点 = 10049;
+ public const int SENCE_取咖啡出餐 = 10052;
#endregion
///
@@ -82,6 +88,10 @@ namespace BPASmartClient.Lebai
///
public int OutputSingalValue { get; set; }
+
+ private volatile static LebaiRobot _Instance;
+ public static LebaiRobot GetInstance => _Instance ?? (_Instance = new LebaiRobot());
+ private LebaiRobot() { }
private LebaiRobotClient client;
private RobotData robotData;
public bool IsIdle { get; set; } = false;
@@ -110,6 +120,74 @@ namespace BPASmartClient.Lebai
StartRobot();
MessageLog.GetInstance.Show("乐百机器人连接成功!");
}
+ ///
+ /// 机器人重连检测
+ ///
+ ///
+ public void Reconnect(string ip)
+ {
+ if (client == null)
+ {
+ try
+ {
+ client = new LebaiRobotClient(ip);
+ }
+ catch (Exception)
+ {
+
+ // throw;
+ }
+ }
+ check:
+ while (robotData != null)
+ {
+
+ try
+ {
+ robotData = client.GetRobotData().Result;
+ }
+ catch (Exception)
+ {
+ robotData = null;
+ // throw;
+ }
+ }
+ MessageLog.GetInstance.Show("乐白机器人断开连接,准备重连");
+ int num = 0;
+ while (num < 6 && robotData == null)
+ {
+ try
+ {
+
+ robotData = client.GetRobotData().Result;
+ }
+ catch (Exception ex)
+ {
+ if (num == 5)
+ {
+ MessageLog.GetInstance.ShowEx(ex.ToString());
+ }
+ }
+
+ if (num < 5 && robotData == null)
+ {
+ Thread.Sleep(1000);
+ MessageLog.GetInstance.Show($"乐白机器人正在尝试第{num + 1}次重连....");
+ }
+ else if (num >= 5 && robotData == null)
+ {
+ MessageLog.GetInstance.Show("乐白机器人重连失败,请检查硬件连接");
+ //return;
+ }
+ num++;
+ }
+ if (robotData != null)
+ {
+ StartRobot();
+ MessageLog.GetInstance.Show("乐白机器人重连成功");
+ }
+ goto check;
+ }
public void GetRobotModeStatus()
{
@@ -143,6 +221,63 @@ namespace BPASmartClient.Lebai
}
}
+ ///
+ /// 启动示教
+ ///
+ public async void StartTeachMode()
+ {
+ try
+ {
+ if (robotData != null)
+ {
+ await client.TeachMode();
+ MessageLog.GetInstance.Show("机器人切换为示教模式.");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.ShowEx(ex.ToString());
+ }
+ }
+
+ ///
+ /// 结束示教
+ ///
+ public async void EndtTeachMode()
+ {
+ try
+ {
+ if (robotData != null)
+ {
+ await client.EndTeachMode();
+ MessageLog.GetInstance.Show("机器人切换为停止示教模式.");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.ShowEx(ex.ToString());
+ }
+ }
+
+ ///
+ /// 机器人急停
+ ///
+ public async void EStopRobot()
+ {
+ try
+ {
+ if (robotData != null)
+ {
+ await client.EStop();
+ MessageLog.GetInstance.Show("机器人急停");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.ShowEx(ex.ToString());
+ }
+ }
+
///
/// 获取抓手重量
///
diff --git a/BPASmartClient.Model/BatchingInfoPar.cs b/BPASmartClient.Model/BatchingInfoPar.cs
new file mode 100644
index 00000000..dd56d51b
--- /dev/null
+++ b/BPASmartClient.Model/BatchingInfoPar.cs
@@ -0,0 +1,21 @@
+using BPA.Message;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.Model
+{
+ public class BatchingInfoPar
+ {
+ ///
+ /// 订单物料信息
+ ///
+ public OrderMaterialDelivery orderMaterialDelivery { get; set; } = new OrderMaterialDelivery();
+ ///
+ /// 配方数据信息
+ ///
+ public RecipeBoms recipeBoms { get; set; } = new RecipeBoms();
+ }
+}
diff --git a/BPASmartClient.Model/Book.cs b/BPASmartClient.Model/Book.cs
new file mode 100644
index 00000000..e6e5bbda
--- /dev/null
+++ b/BPASmartClient.Model/Book.cs
@@ -0,0 +1,43 @@
+using Microsoft.Toolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.Model
+{
+ public class Book
+ {
+ public string Name { get; set; }
+ public string Tag { get; set; }
+ }
+ public class BookEx : ObservableObject
+ {
+ public Book BookN { get; private set; }
+
+ private bool _isChecked=false;
+
+ public bool IsChecked
+ {
+ get
+ {
+ return _isChecked;
+ }
+ set
+ {
+ if (_isChecked != value)
+ {
+ _isChecked = value;
+
+ OnPropertyChanged("IsChecked");
+ }
+ }
+ }
+
+ public BookEx(Book book)
+ {
+ BookN = book;
+ }
+ }
+}
diff --git a/BPASmartClient.Model/单片机/SCChipEvent.cs b/BPASmartClient.Model/单片机/SCChipEvent.cs
index a7e6f201..270d4e88 100644
--- a/BPASmartClient.Model/单片机/SCChipEvent.cs
+++ b/BPASmartClient.Model/单片机/SCChipEvent.cs
@@ -48,4 +48,18 @@ namespace BPASmartClient.Model.单片机
{
public bool TurnOn { get; set; }
}
+ ///
+ /// 检测有无杯子
+ ///
+ public class ArticleExitsEvent : BaseEvent
+ {
+
+ }
+ ///
+ /// 检测物品距离
+ ///
+ public class ArticleDistEvent : BaseEvent
+ {
+
+ }
}
diff --git a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj
index 0acaaf42..288c5e34 100644
--- a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj
+++ b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj
@@ -6,6 +6,7 @@
+
diff --git a/BPASmartClient.MorkT/Control_MorkT.cs b/BPASmartClient.MorkT/Control_MorkT.cs
new file mode 100644
index 00000000..cfacd727
--- /dev/null
+++ b/BPASmartClient.MorkT/Control_MorkT.cs
@@ -0,0 +1,164 @@
+using BPASmartClient.Device;
+using BPASmartClient.EventBus;
+using BPASmartClient.Lebai;
+using BPASmartClient.Message;
+using BPASmartClient.Model;
+using BPASmartClient.Peripheral;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static BPASmartClient.EventBus.EventBus;
+
+namespace BPASmartClient.MorkT
+{
+ public class Control_MorkT : BaseDevice
+ {
+ public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKIC; } }
+
+ GLV_MorkT morkT = new GLV_MorkT();
+
+
+
+ public override void DoMain()
+ {
+ ServerInit();
+ DataParse();
+ EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
+ {
+ if (morkT.MakeCoffeeOrder != null)
+ morkT.MakeCoffeeOrder.OrderStatus = 1;
+ });
+ MessageLog.GetInstance.Show("MORKF 设备初始化完成");
+ }
+
+ public override void ResetProgram()
+ {
+ morkT = null;
+ morkT = new GLV_MorkT();
+ }
+
+ public override void MainTask()
+ {
+ }
+
+ public override void ReadData()
+ {
+ morkT.lebai = LebaiRobot.GetInstance.GetValueAsync();
+ LebaiRobot.GetInstance.GetRobotModeStatus();
+ }
+
+
+
+ public override void Stop()
+ {
+ }
+
+
+ private void ServerInit()
+ {
+ //物料信息
+ EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
+ {
+ if (@event == null) return;
+ if (@event is MaterialDeliveryEvent material)
+ {
+ orderMaterialDelivery = material.orderMaterialDelivery;
+ }
+ });
+
+ //配方数据信息
+ EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
+ {
+ if (@event == null) return;
+ if (@event is RecipeBomEvent recipe)
+ {
+ recipeBoms = recipe.recipeBoms;
+ }
+ });
+ }
+
+ ///
+ /// 数据解析
+ ///
+ private void DataParse()
+ {
+ EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
+ {
+ if (@event == null) return;
+ if (@event is DoOrderEvent order)
+ {
+ if (order.MorkOrder.GoodBatchings == null) return;
+ OrderCount++;
+ DeviceProcessLogShow($"接收到{OrderCount}次订单");
+ //构建所有商品物料信息
+ morkT.batchings = PolymerBatching.BuildAll();
+ //商品类型
+ GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
+ string loc_Goods = string.Empty;
+ foreach (var item in order.MorkOrder.GoodBatchings)
+ {
+ var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
+ if (res != null)
+ {
+ //验证商品是咖啡还是冰淇淋
+ if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
+ {
+ //获取当前物料所属商品类型
+ currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
+ }
+
+ //获取主料和容器位置
+ if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
+
+ switch (currentGoodsType)
+ {
+ case GOODS_TYPE.COFFEE:
+ if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
+ {
+ morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
+ {
+ SuborderId = order.MorkOrder.SuborderId,
+ BatchingId = res.BatchingId,
+ Loc = loc_Goods
+ });
+ }
+ break;
+ case GOODS_TYPE.ICECREAM:
+ if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
+ {
+ morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
+ {
+ SuborderId = order.MorkOrder.SuborderId,
+ BatchingId = res.BatchingId,
+ Loc = loc_Goods
+ });
+ }
+ break;
+ case GOODS_TYPE.NEITHER:
+ DeviceProcessLogShow("未知的商品类型");
+ break;
+ }
+ }
+ }
+
+ }
+ });
+ }
+
+ ///
+ /// 验证当前是做咖啡还是做冰淇淋
+ ///
+ /// 物料位置
+ private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
+ {
+ if (morkT.batchings.ContainsKey(batchingLoc))
+ return morkT.batchings[batchingLoc].GoodsType;
+ return GOODS_TYPE.NEITHER;
+ }
+
+
+
+ }
+}
diff --git a/BPASmartClient.MorkT/Device_MorkT.cs b/BPASmartClient.MorkT/Device_MorkT.cs
deleted file mode 100644
index 268cdf05..00000000
--- a/BPASmartClient.MorkT/Device_MorkT.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using BPASmartClient.Device;
-using BPASmartClient.Peripheral;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.MorkT
-{
- public class Device_MorkT : BaseDevice
- {
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKIC; } }
-
- public override void DoMain()
- {
-
- }
-
- public override void MainTask()
- {
- }
-
- public override void ReadData()
- {
- }
-
- public override void ResetProgram()
- {
- }
-
- public override void Stop()
- {
- }
- }
-}
diff --git a/BPASmartClient.MorkT/GLV_MorkT.cs b/BPASmartClient.MorkT/GLV_MorkT.cs
new file mode 100644
index 00000000..8a09f07a
--- /dev/null
+++ b/BPASmartClient.MorkT/GLV_MorkT.cs
@@ -0,0 +1,37 @@
+using Robotc;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.MorkT
+{
+ public class GLV_MorkT
+ {
+ ///
+ /// 咖啡订单队列
+ ///
+ public ConcurrentQueue morkOrderPushesCoffee = new ConcurrentQueue();
+
+ ///
+ /// 冰淇淋订单队列
+ ///
+ public ConcurrentQueue morkOrderPushesIceCream = new ConcurrentQueue();
+ ///
+ /// 物料存放位置
+ ///
+ public Dictionary batchings = new Dictionary();
+
+ ///
+ /// 当前正在制作咖啡
+ ///
+ public OrderLocInfo MakeCoffeeOrder = new OrderLocInfo();
+
+ ///
+ /// 获取乐百机器人的数据
+ ///
+ public SignalResult lebai = new SignalResult();
+ }
+}
diff --git a/BPASmartClient.MorkT/OrderLocInfo.cs b/BPASmartClient.MorkT/OrderLocInfo.cs
new file mode 100644
index 00000000..6199c5b3
--- /dev/null
+++ b/BPASmartClient.MorkT/OrderLocInfo.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.MorkT
+{
+ public class OrderLocInfo
+ {
+ public string SuborderId { get; set; }
+ public string Loc { get; set; }
+ public ushort RecipeNumber { get; set; }
+ public int BatchingId { get; set; }
+
+ public int OrderStatus { get; set; }
+ public OrderLocInfo()
+ {
+ OrderStatus = 0;
+ }
+ }
+}
diff --git a/BPASmartClient.MorkT/PolymerBatching.cs b/BPASmartClient.MorkT/PolymerBatching.cs
new file mode 100644
index 00000000..79fd574d
--- /dev/null
+++ b/BPASmartClient.MorkT/PolymerBatching.cs
@@ -0,0 +1,122 @@
+
+using BPASmartClient.Lebai;
+using BPASmartClient.Model.单片机.Enum;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.MorkT
+{
+ public enum GOODS_TYPE
+ {
+ NEITHER,
+ COFFEE,
+ ICECREAM,
+ }
+
+ public enum BATCHING_CLASS
+ {
+ HOLDER,
+ MAIN_MATERIAL,
+ }
+
+ public class PolymerBatching
+ {
+ internal const string ICE_MAIN_BATCHIN1_LOC = "52";
+ internal const string ICE_MAIN_BATCHIN2_LOC = "53";
+ internal const string ICE_MAIN_BATCHIN3_LOC = "54";
+ internal const string COFFEE_HOLDER_LOC = "30";
+ internal const string ICE_HOLDER_LOC = "51";
+ public static Dictionary GOODS_TYPES = new Dictionary() {
+ {"1", GOODS_TYPE.COFFEE},
+ {"2", GOODS_TYPE.COFFEE},
+ {"3", GOODS_TYPE.COFFEE},
+ {"4", GOODS_TYPE.COFFEE},
+ {"5", GOODS_TYPE.COFFEE},
+ {"6", GOODS_TYPE.COFFEE},
+ {"7", GOODS_TYPE.COFFEE},
+ {"8", GOODS_TYPE.COFFEE},
+ {"9", GOODS_TYPE.COFFEE},
+ {"10",GOODS_TYPE.COFFEE},
+ {"11",GOODS_TYPE.COFFEE},
+ {"12",GOODS_TYPE.COFFEE},
+ {"13",GOODS_TYPE.COFFEE},
+ {"14",GOODS_TYPE.COFFEE},
+ {"15",GOODS_TYPE.COFFEE},
+ {"16",GOODS_TYPE.COFFEE},
+ {"17",GOODS_TYPE.COFFEE},
+ {"18",GOODS_TYPE.COFFEE},
+ {"19",GOODS_TYPE.COFFEE},
+ {"20",GOODS_TYPE.COFFEE},
+ {"21",GOODS_TYPE.COFFEE},
+ {"22",GOODS_TYPE.COFFEE},
+ {"23",GOODS_TYPE.COFFEE},
+ {"24",GOODS_TYPE.COFFEE},
+ {"25",GOODS_TYPE.COFFEE},
+ {"30",GOODS_TYPE.COFFEE},
+ {"51",GOODS_TYPE.ICECREAM},
+ {ICE_MAIN_BATCHIN1_LOC,GOODS_TYPE.ICECREAM},
+ {ICE_MAIN_BATCHIN2_LOC,GOODS_TYPE.ICECREAM},
+ {ICE_MAIN_BATCHIN3_LOC,GOODS_TYPE.ICECREAM},
+ };
+
+ public GOODS_TYPE GoodsType { get; set; }
+ public BATCHING_CLASS BatchingClass { get; set; }
+ private string loc;
+
+ public string Loc
+ {
+ get { return loc; }
+ set
+ {
+ loc = value;
+ if (GOODS_TYPES.ContainsKey(loc))
+ GoodsType = GOODS_TYPES[loc];
+ switch (loc)
+ {
+ case COFFEE_HOLDER_LOC:
+ case ICE_HOLDER_LOC:
+ BatchingClass = BATCHING_CLASS.HOLDER;
+ break;
+ default:
+ BatchingClass = BATCHING_CLASS.MAIN_MATERIAL;
+ break;
+ }
+ }
+ }
+
+ internal static Dictionary BuildAll()
+ {
+ Dictionary temp = new Dictionary();
+ foreach (var item in GOODS_TYPES)
+ {
+ temp.Add(item.Key, new PolymerBatching() { Loc = item.Key });
+ }
+ return temp;
+ }
+
+ internal static IC_SE GetIceCreamSE(string loc, out int sence)
+ {
+ switch (loc)
+ {
+ case ICE_MAIN_BATCHIN1_LOC:
+ sence = LebaiRobot.SENCE_接1号冰淇淋;
+ return IC_SE.SE_1;
+
+ case ICE_MAIN_BATCHIN2_LOC:
+ sence = LebaiRobot.SENCE_接2号冰淇淋;
+ return IC_SE.SE_2;
+
+ case ICE_MAIN_BATCHIN3_LOC:
+ sence = LebaiRobot.SENCE_接3号冰淇淋;
+ return IC_SE.SE_3;
+
+ default:
+ sence = LebaiRobot.SENCE_接1号冰淇淋;
+ return IC_SE.SE_1;
+ }
+ }
+ }
+}
diff --git a/BPASmartClient.SCChip/ChipStatus.cs b/BPASmartClient.SCChip/ChipStatus.cs
new file mode 100644
index 00000000..9189085b
--- /dev/null
+++ b/BPASmartClient.SCChip/ChipStatus.cs
@@ -0,0 +1,132 @@
+using BPASmartClient.Helper;
+using BPASmartClient.Model.单片机.Enum;
+using BPASmartClient.SCChip;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.SCChip
+{
+ public class ChipStatus : Singleton
+ {
+ 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/CommandHandler.cs b/BPASmartClient.SCChip/CommandHandler.cs
new file mode 100644
index 00000000..e46f40e6
--- /dev/null
+++ b/BPASmartClient.SCChip/CommandHandler.cs
@@ -0,0 +1,197 @@
+
+using BPASmartClient.EventBus;
+using BPASmartClient.Model.单片机;
+using BPASmartClient.Model.单片机.Enum;
+using BPASmartClient.SCChip;
+using BPASmartClient.SerialPort;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using static BPASmartClient.EventBus.EventBus;
+
+namespace BPASmartClient.SCChip
+{
+ ///
+ /// 指令封装
+ ///
+ internal class CommandHandler
+ {
+ private SerialPortClient commProxy;
+ private ICChipPackage package = new ICChipPackage();
+
+ ///
+ /// 初始化
+ ///
+ internal void Init(SerialPortClient commProxy)
+ {
+ this.commProxy = commProxy;
+ EventBus.EventBus.GetInstance().Subscribe(0,TakeCupEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, MakeIceCreamEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, StopMakeIceCreamEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, RotorSwitchEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, ArticleExitsEventHandle);
+ EventBus.EventBus.GetInstance().Subscribe(0, 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 SCChip_SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE;
+ package.Value = (byte)(@event as SCChip_SESwitchCreamEvent).SteeringEngine;
+ commProxy.SendData(StructureToByte(package));
+ }
+
+ private void RotorSwitchEventHandle(IEvent @event, EventCallBackHandle callBack)
+ {
+ 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));
+ }
+
+ private void MakeIceCreamEventHandle(IEvent @event, EventCallBackHandle callBack)
+ {
+ switch ((@event as SCChip_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)(@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 ((@event as SCChip_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)(@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 ((@event as SCChip_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);
+ }
+ }
+
+ private void TakeCupEventHandle(IEvent @event, EventCallBackHandle callBack)
+ {
+ switch ((@event as SCChip_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)(@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 ((@event as SCChip_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);
+ }
+ }
+
+
+ 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.ViewModel/BPASmartClient.ViewModel.csproj b/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj
index 41b62ed4..b99aa4f8 100644
--- a/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj
+++ b/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj
@@ -12,6 +12,7 @@
+
diff --git a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs
index bc48b94a..4e097ed9 100644
--- a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs
+++ b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs
@@ -1,11 +1,20 @@
-using BPASmartClient.Helper;
+using BPASmartClient.CustomResource.UserControls;
+using BPASmartClient.CustomResource.UserControls.MessageShow;
+using BPASmartClient.Helper;
+using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Data;
+using System.IO;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using System.Windows.Media;
namespace BPASmartClient.ViewModel
{
@@ -24,25 +33,22 @@ namespace BPASmartClient.ViewModel
#endregion
#region 变量
- ///
- /// 选中变量
- ///
- private string _SelectCombox;
- public string SelectCombox
+ string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}LogDir\\HBL.LogDir2022_5_13.log";
+ private string _SelectedText = "";
+ public string SelectedText
{
get
{
- return _SelectCombox;
+ return _SelectedText;
}
set
{
- if (_SelectCombox == value)
+ if (_SelectedText == value)
return;
- _SelectCombox = value;
- OnPropertyChanged("SelectCombox");
+ _SelectedText = value;
+ OnPropertyChanged("SelectedText");
}
}
-
///
/// 时间条件
///
@@ -61,6 +67,54 @@ namespace BPASmartClient.ViewModel
OnPropertyChanged("DateTimeStr");
}
}
+ public ObservableCollection SelectBookExs { set; get; }
+ private ObservableCollection _books;
+ public ObservableCollection BookExs
+ {
+ get
+ {
+ if (_books == null)
+ {
+ _books = new ObservableCollection();
+
+ _books.CollectionChanged += (sender, e) =>
+ {
+ if (e.OldItems != null)
+ {
+ foreach (BookEx bookEx in e.OldItems)
+ {
+ bookEx.PropertyChanged -= ItemPropertyChanged;
+ }
+ }
+
+ if (e.NewItems != null)
+ {
+ foreach (BookEx bookEx in e.NewItems)
+ {
+ bookEx.PropertyChanged += ItemPropertyChanged;
+ }
+ }
+ };
+ }
+
+ return _books;
+ }
+ }
+
+ private ObservableCollection _LogModels; public ObservableCollection LogDataGrid
+ {
+ get
+ {
+ return _LogModels;
+ }
+ set
+ {
+ if (_LogModels == value)
+ return;
+ _LogModels = value;
+ OnPropertyChanged("LogDataGrid");
+ }
+ }
#endregion
#region Command
@@ -71,23 +125,148 @@ namespace BPASmartClient.ViewModel
#region 函数
public void Init()
{
+ LogDataGrid = new ObservableCollection();
DateTimeStr = DateTime.Now;
+ BookExs.Add(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true });
+ BookExs.Add(new BookEx(new Book() { Name = "设备日志条件", Tag = "DeviceLog" }));
+ BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" }));
+ BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" }));
+ SelectedText = "一般日志条件";
+ SelectBookExs = new ObservableCollection();
+ SelectBookExs.Add(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true });
+
+ //查询
QueryCommand = new RelayCommand(() =>
{
-
+ string sql = string.Empty;
+ if (SelectBookExs.Count <= 0)
+ {
+ NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"至少选中一个条件!");
+ return;
+ }
+ SelectBookExs?.ToList().ForEach(par =>
+ {
+ if (string.IsNullOrEmpty(sql))
+ sql += $"LOGGER='{par.BookN.Tag}'";
+ else
+ sql += $" OR LOGGER='{par.BookN.Tag}'";
+ });
+ //1.找到某天的文件
+ string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}LogDir\\HBL.LogDir{DateTimeStr.ToString("yyyy_M_d")}.log";
+ if (File.Exists(path))
+ {
+ LogDataGrid.Clear();
+ //2.根据选中查询日志
+ DataTable dataTable = ReadFile(path);
+ DataRow[] datas = dataTable.Select(sql);
+ if (datas.Count() <= 0)
+ {
+ NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"查询结果为空!");
+ return;
+ }
+ foreach (DataRow item in datas)
+ {
+ LogDataGrid.Add(new LogModel
+ {
+ time = item["TIME"].ToString(),
+ type = item["LOGGER"].ToString(),
+ message = item["MESSAGE"].ToString(),
+ foreground = (item["LOGGER"].ToString() == "Error" || item["LOGGER"].ToString() == "DeviceAlarm") ? new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032")) : new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e"))
+ });
+ }
+ }
+ else
+ {
+ NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"文件不存在,{path}!");
+ }
});
-
+ //打开文件目录
OpenCommand = new RelayCommand(() =>
{
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File);
- //logHelper.GetLogConfigInstance().OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File);
+ logHelper.GetLogConfigInstance().OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File);
});
}
- #endregion
+ ///
+ /// 查询告警或日志
+ ///
+ ///
+ ///
+ public void QueryLogOrAlarm(DateTime time, string info)
+ {
+ }
+ ///
+ /// 读取文件
+ ///
+ ///
+ public DataTable ReadFile(string path)
+ {
+ DataTable dt = new DataTable();
+ dt.Columns.AddRange(new[]
+ {
+ new DataColumn("TIME"),
+ new DataColumn("LOGGER"),
+ new DataColumn("NAME"),
+ new DataColumn("PRIORITY"),
+ new DataColumn("MESSAGE"),
+ });
+ //读取文件
+ string s = "";
+ using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ {
+ using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default))
+ {
+ s = sr.ReadToEnd();
+ }
+ }
+
+ //正则表达式匹配,注意RegexOptions.RightToLeft
+ var matches = Regex.Matches(s, @"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([A-Z, ]{0,15}) ([A-Z,a-z]{0,20}) (\[\d{1}\]) (.*)", RegexOptions.RightToLeft);
+ foreach (Match m in matches)
+ {
+ var time = m.Groups[1].Value;
+ var logger = m.Groups[2].Value;
+ var name = m.Groups[3].Value;
+ var priority = m.Groups[4].Value;
+ var msg = m.Groups[5].Value;
+ var dr = dt.NewRow();
+ dr.ItemArray = new[] { time, logger, name, priority, msg };
+ dt.Rows.InsertAt(dr, 0);
+ }
+ return dt;
+ }
+
+ ///
+ /// 选中改变
+ ///
+ ///
+ ///
+ private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == "IsChecked")
+ {
+ BookEx bookEx = sender as BookEx;
+
+ if (bookEx != null)
+ {
+ IEnumerable bookExs = BookExs.Where(b => b.IsChecked == true);
+
+ StringBuilder builder = new StringBuilder();
+ SelectBookExs.Clear();
+ foreach (BookEx item in bookExs)
+ {
+ builder.Append(item.BookN.Name + " ");
+ SelectBookExs.Add((BookEx)item);
+ }
+ SelectedText = builder == null ? string.Empty : builder.ToString();
+ }
+ }
+ }
+ #endregion
}
diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs
index 17a11b4e..0088abaa 100644
--- a/BPASmartClient.ViewModel/LogViewModel.cs
+++ b/BPASmartClient.ViewModel/LogViewModel.cs
@@ -236,6 +236,7 @@ namespace BPASmartClient.ViewModel
if (_type == "Error") foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032"));
OnPropertyChanged("type");
+ OnPropertyChanged("foreground");
}
}
public string message { get; set; }
diff --git a/BPASmartClient.ViewModel/MainViewModel.cs b/BPASmartClient.ViewModel/MainViewModel.cs
index 595671c8..60990cc7 100644
--- a/BPASmartClient.ViewModel/MainViewModel.cs
+++ b/BPASmartClient.ViewModel/MainViewModel.cs
@@ -42,9 +42,13 @@ namespace BPASmartClient.ViewModel
/// 是否告警
///
public AlarmModel IsAlarm { get; set; }
-
+ public System.Windows.Window window;
public DispatcherTimer dispatcherTimer;
+ #region 单一
+ private volatile static MainViewModel _Instance;
+ public static MainViewModel GetInstance() => _Instance ?? (_Instance = new MainViewModel());
+ #endregion
public MainViewModel()
{
diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml b/BPASmartClient/Control/LogOrAlarmView.xaml
index 809221bf..4a690f85 100644
--- a/BPASmartClient/Control/LogOrAlarmView.xaml
+++ b/BPASmartClient/Control/LogOrAlarmView.xaml
@@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.Control"
+ xmlns:k="clr-namespace:BPASmartClient.Model;assembly=BPASmartClient.Model"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
@@ -25,11 +26,14 @@
-
- 一般日志
- 设备日志
- 错误日志
- 设备告警
+
+
+
+
+
+
+
+
@@ -38,95 +42,41 @@
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
-
+
-
+
+
diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml.cs b/BPASmartClient/Control/LogOrAlarmView.xaml.cs
index fb589b30..cae385b9 100644
--- a/BPASmartClient/Control/LogOrAlarmView.xaml.cs
+++ b/BPASmartClient/Control/LogOrAlarmView.xaml.cs
@@ -26,5 +26,15 @@ namespace BPASmartClient.Control
InitializeComponent();
this.DataContext = LogOrAlarmViewModel.GetInstance();
}
+
+ private void CheckBox_Checked(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
+ {
+
+ }
}
}
diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml
index f68747fa..4bb5b7a4 100644
--- a/BPASmartClient/MainWindow.xaml
+++ b/BPASmartClient/MainWindow.xaml
@@ -25,9 +25,7 @@
-
-
-
+
diff --git a/BPASmartClient/MainWindow.xaml.cs b/BPASmartClient/MainWindow.xaml.cs
index 8832020d..54d473c1 100644
--- a/BPASmartClient/MainWindow.xaml.cs
+++ b/BPASmartClient/MainWindow.xaml.cs
@@ -10,6 +10,7 @@ using BPASmartClient.Message;
using BPASmartClient.Model;
using BPASmartClient.Model.冰淇淋.Enum;
using BPASmartClient.Model.咖啡机.Enum;
+using BPASmartClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -35,7 +36,9 @@ namespace BPASmartClient
{
public MainWindow()
{
- InitializeComponent();
+ InitializeComponent();
+ MainViewModel.GetInstance().window = this;
+ this.DataContext = MainViewModel.GetInstance();
Initialize();
}
diff --git a/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj b/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj
new file mode 100644
index 00000000..e444219e
--- /dev/null
+++ b/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj
@@ -0,0 +1,23 @@
+
+
+
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs
new file mode 100644
index 00000000..090b8a61
--- /dev/null
+++ b/HBLConsole.MORKIC/Control_MORKIC.cs
@@ -0,0 +1,647 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Threading;
+using BPA.Message;
+using Robotc;
+using System.Collections.Concurrent;
+using System.Diagnostics;
+using BPA.Message.IOT;
+using System.Threading.Tasks;
+using BPASmartClient.Device;
+using BPA.Message.Enum;
+using BPASmartClient.DRCoffee;
+using BPASmartClient.GSIceCream;
+using BPASmartClient.Helper;
+using BPASmartClient.Lebai;
+using BPASmartClient.EventBus;
+using BPASmartClient.Model.咖啡机.Enum;
+using BPASmartClient.Message;
+using BPASmartClient.Model.冰淇淋.Enum;
+using BPASmartClient.Model.单片机.Enum;
+using BPASmartClient.SCChip;
+using BPASmartClient.Model;
+using BPASmartClient.Model.单片机;
+using static BPASmartClient.EventBus.EventBus;
+
+namespace BPASmartClient.MORKIC
+{
+ /*
+ * 冰淇淋咖啡机组合套装
+ * 物料位置:
+ * 1:冰淇料
+ * 2:冰淇淋杯
+ * 5:咖啡
+ * 6:咖啡杯
+ */
+ public class Control_MORKIC : BaseDevice
+ {
+
+ //咖啡机主控程序
+ private CoffeeMachine coffeeMachine;
+ //单片机主控程序
+ private ICChipMachine icchipMachine;
+ //广绅单口冰淇淋机
+ private IceCreamMachine iceCreamMachine;
+ //物料存放位置
+ private Dictionary batchings = new Dictionary();
+ ///
+ /// 获取乐百机器人的数据
+ ///
+ SignalResult lebai = new SignalResult();
+ ///
+ /// 咖啡位置是否有东西
+ ///
+ private bool IsCoffeeMake=false;
+
+ private bool enableFunny = false;
+ private DateTime lastRecvdOrder = DateTime.Now;
+ private bool working = false;
+ private bool IceIsOK = true;
+
+ public void ConnectOk()
+ {
+
+ }
+ ///
+ /// 当前正在制作咖啡
+ ///
+ SimOrderData MakeCoffeeOrder = new SimOrderData();
+ ///
+ /// 咖啡订单队列
+ ///
+ ConcurrentQueue morkOrderPushesCoffee = new ConcurrentQueue();
+ ///
+ /// 冰淇淋订单队列
+ ///
+ ConcurrentQueue morkOrderPushesIceCream = new ConcurrentQueue();
+ ///
+ /// 等待取餐的订单,只有一个
+ ///
+ ConcurrentQueue WaitTakeMealOrder= new ConcurrentQueue();
+
+ public void Init()
+ {
+
+ ActionManage.GetInstance.Register(new Action