diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index d2e72496..a29b2e0c 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -20,6 +20,7 @@ + @@ -89,6 +90,7 @@ + @@ -183,6 +185,7 @@ + @@ -203,6 +206,7 @@ PreserveNewest + diff --git a/BPASmartClient.CustomResource/Fonts/Quartz Regular.ttf b/BPASmartClient.CustomResource/Fonts/Quartz Regular.ttf new file mode 100644 index 00000000..46560922 Binary files /dev/null and b/BPASmartClient.CustomResource/Fonts/Quartz Regular.ttf differ diff --git a/BPASmartClient.CustomResource/Image/圆角矩形 30 拷贝.png b/BPASmartClient.CustomResource/Image/圆角矩形 30 拷贝.png new file mode 100644 index 00000000..a0a49ad1 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/圆角矩形 30 拷贝.png differ diff --git a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml index c033fdb0..6f3f53a9 100644 --- a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml @@ -6,22 +6,280 @@ xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:BPASmartClient.CustomResource.UserControls"> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -126,57 +384,6 @@ - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + + + + - \ No newline at end of file diff --git a/BPASmartClient.CustomResource/Themes/MyStyle.xaml b/BPASmartClient.CustomResource/Themes/MyStyle.xaml index a6ed93e7..2fe1b462 100644 --- a/BPASmartClient.CustomResource/Themes/MyStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/MyStyle.xaml @@ -3,18 +3,33 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> - - - - - - - - + + + + + + + + + + + + + + - - - - - - + + - - + + + \ No newline at end of file diff --git a/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml b/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml index e456a4c7..b30d09af 100644 --- a/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml +++ b/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml @@ -22,14 +22,14 @@ - 14:48:30 + 14:48:30 - 星期一 + 星期一 2021-11-13 diff --git a/BPASmartClient.CustomResource/UserControls/Style3ArcConverter.cs b/BPASmartClient.CustomResource/UserControls/Style3ArcConverter.cs index 820667d6..0481aa25 100644 --- a/BPASmartClient.CustomResource/UserControls/Style3ArcConverter.cs +++ b/BPASmartClient.CustomResource/UserControls/Style3ArcConverter.cs @@ -46,7 +46,7 @@ namespace BPASmartClient.CustomResource.UserControls } else { - return PenLineCap.Round; + return PenLineCap.Flat; } } diff --git a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs index 2a18b52a..885f5031 100644 --- a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs +++ b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs @@ -32,17 +32,10 @@ namespace BPASmartClient.MorkTLebaiJC */ public class Control_MORKJC2 : BaseDevice { - //private CoffeEndCook coffeEndCook = new CoffeEndCook();//模拟咖啡制作成功 - //咖啡机主控程序 - //private CoffeeMachine coffeeMachine; //物料存放位置 private Dictionary batchings = new Dictionary(); //容器位置 private string holderLoc; - /// - /// 获取乐百机器人的数据 - /// - //SignalResult lebai = new SignalResult(); //主料位置 private string mainMaterialLoc; //子订单ID @@ -64,49 +57,9 @@ namespace BPASmartClient.MorkTLebaiJC ConcurrentQueue morkOrderPushes = new ConcurrentQueue(); public void Init() { - //ActionManage.GetInstance.Register(new Action((s) => - //{ - // if (s is DrCoffeeDrinksCode cf) - // { - // DoCoffee(); - // } - // else if (s is Dictionary ms) - // { - // if (ms.ContainsKey("Button")) - // { - // switch (ms["Button"]) - // { - // case "启动示教": - // JuicerModel.GetInstance.StartTeachMode(); - // break; - // case "停止示教": - // JuicerModel.GetInstance.EndtTeachMode(); - // break; - // case "启动机器人": - // JuicerModel.GetInstance.StartRobot(); - // break; - // case "急停": - // JuicerModel.GetInstance.EStopRobot(); - // break; - // default: - // break; - // } - // } - // } - //}), "SimCoffee"); - //构建所有商品物料信息 batchings = PolymerBatching.BuildAll(); - - EventBus.EventBus.GetInstance().Subscribe(DeviceId, CoffeEndCookHandle); - - System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); - //一系列外围基础配置 - var com_Coffee = config.AppSettings.Settings["COM_Coffee"].Value; - var baud_Coffee = config.AppSettings.Settings["BAUD_Coffee"].Value; - //咖啡机创建 - //coffeeMachine = new CoffeeMachine(com_Coffee, (BaudRates)Enum.Parse(typeof(BaudRates), baud_Coffee)); - + EventBus.EventBus.GetInstance().Subscribe(DeviceId, DRCoffee_CoffeEndCookEventHandle); Main(); ReadData(); ThreadManage.GetInstance().StartLong(new Action(() => @@ -116,7 +69,7 @@ namespace BPASmartClient.MorkTLebaiJC working = true; if (morkOrderPushes.TryDequeue(out MorkOrderPush order)) { - MessageLog.GetInstance.Show($"开始制作订单[{order.SortNum}]"); + DeviceProcessLogShow($"开始制作订单[{order.SortNum}]"); //商品类型 GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; //子订单ID @@ -134,7 +87,6 @@ namespace BPASmartClient.MorkTLebaiJC holderLoc = res.BatchingLoc; break; case BATCHING_CLASS.MAIN_MATERIAL: - // mainMaterialLoc ="1"; mainMaterialLoc = res.BatchingLoc; //验证商品是咖啡还是冰淇淋 if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER) @@ -164,7 +116,7 @@ namespace BPASmartClient.MorkTLebaiJC DoWater(); break; case GOODS_TYPE.NEITHER: - MessageLog.GetInstance.Show("未知的商品类型"); + DeviceProcessLogShow("未知的商品类型"); break; } } @@ -177,27 +129,12 @@ namespace BPASmartClient.MorkTLebaiJC public void Main() { - //咖啡机开启主线程 - //coffeeMachine.Start(); //开始心跳刷新,根据咖啡机及冰淇淋机来判断 ThreadManage.GetInstance().StartLong(new Action(() => { - //GeneralConfig.Healthy = - // JuicerModel.GetInstance.IsConnected && - // MorkCStatus.GetInstance().CanDo && - // JuicerHelper.GetInstance.IsOpen && - // MCUSerialHelper.GetInstance.IsOpen; - //GeneralConfig.Healthy = true; + IsHealth = GetStatus("JuicerIsConnected"); Thread.Sleep(100); }), "MORK-IC心跳刷新"); - //ThreadManage.GetInstance.Start(new Action(() => - //{ - // while (!JuicerModel.GetInstance.IsConnected) - // { - // Thread.Sleep(10); - // } - // //Sence(JuicerModel.SENCE_欢迎); - //}), "MORK-JC欢迎"); } private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) @@ -267,13 +204,12 @@ namespace BPASmartClient.MorkTLebaiJC /// private void DoCoffee() { - #region 接咖啡流程 are.Reset(); while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -281,7 +217,7 @@ namespace BPASmartClient.MorkTLebaiJC int resultTakeCup = takeCup(); if (resultTakeCup == 1) { - MessageLog.GetInstance.Show("咖啡杯取杯完成"); + DeviceProcessLogShow("咖啡杯取杯完成"); new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_接咖啡); Wait(); @@ -293,14 +229,14 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -308,8 +244,7 @@ namespace BPASmartClient.MorkTLebaiJC Sence(JuicerModel.JUICE2_放咖啡杯); Wait(); OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - MessageLog.GetInstance.Show("咖啡制作完成"); - + DeviceProcessLogShow("咖啡制作完成"); } else { @@ -326,7 +261,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -334,7 +269,7 @@ namespace BPASmartClient.MorkTLebaiJC int resultTakeCup = takeCup(); if (resultTakeCup == 1) { - MessageLog.GetInstance.Show("取茶杯完成"); + DeviceProcessLogShow("取茶杯完成"); new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_接茶叶); Wait(); @@ -368,7 +303,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -378,7 +313,7 @@ namespace BPASmartClient.MorkTLebaiJC OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - MessageLog.GetInstance.Show("茶水制作完成"); + DeviceProcessLogShow("茶水制作完成"); } else @@ -397,7 +332,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -425,7 +360,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -434,7 +369,7 @@ namespace BPASmartClient.MorkTLebaiJC Sence(JuicerModel.JUICE2_放水杯); Wait(); OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - MessageLog.GetInstance.Show("纯净水制作完成"); + DeviceProcessLogShow("纯净水制作完成"); } else @@ -457,7 +392,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); @@ -575,7 +510,7 @@ namespace BPASmartClient.MorkTLebaiJC while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) - MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } outCupCheck = false; @@ -584,7 +519,7 @@ namespace BPASmartClient.MorkTLebaiJC Wait(); OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - MessageLog.GetInstance.Show("果汁制作完成"); + DeviceProcessLogShow("果汁制作完成"); } ////模拟果汁 @@ -592,7 +527,7 @@ namespace BPASmartClient.MorkTLebaiJC //while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 //{ // if (!outCupCheck) - // MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!"); + // DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); // outCupCheck = true; //} //outCupCheck = false; @@ -601,7 +536,7 @@ namespace BPASmartClient.MorkTLebaiJC //Wait(); //OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - //MessageLog.GetInstance.Show("果汁制作完成"); + //DeviceProcessLogShow("果汁制作完成"); } else { @@ -625,22 +560,16 @@ namespace BPASmartClient.MorkTLebaiJC { try { - nCnt = 0; new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_初始位); Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_取纸杯); Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_纸杯检测); Wait(); - nCnt++; Thread.Sleep(2000); while (checkCnt < 3) @@ -663,7 +592,7 @@ namespace BPASmartClient.MorkTLebaiJC if (nCnt > 3) { nCnt = 0; - MessageLog.GetInstance.ShowEx("三次取杯失败,回原点"); + DeviceProcessLogShow("三次取杯失败,回原点"); new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_检测位回原点); Wait(); @@ -671,8 +600,6 @@ namespace BPASmartClient.MorkTLebaiJC } else { - - nCnt++; new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); Sence(JuicerModel.JUICE2_二次取杯); @@ -694,20 +621,17 @@ namespace BPASmartClient.MorkTLebaiJC { checkCnt = 0; return 1; - } checkCnt++; } - } Thread.Sleep(1000); } } catch (Exception ex) { - MessageLog.GetInstance.Show(ex.ToString()); + DeviceProcessLogShow(ex.ToString()); } - return 1; } /// @@ -736,7 +660,7 @@ namespace BPASmartClient.MorkTLebaiJC } catch (Exception ex) { - MessageLog.GetInstance.Show(ex.ToString()); + DeviceProcessLogShow(ex.ToString()); return 0; } } @@ -754,12 +678,12 @@ namespace BPASmartClient.MorkTLebaiJC Thread.Sleep(100); if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 1) return 2; } - MessageLog.GetInstance.Show("放杯位有杯子未取走,等待取走,最多等待60s,即跳出流程"); + DeviceProcessLogShow("放杯位有杯子未取走,等待取走,最多等待60s,即跳出流程"); return 1; } catch (Exception ex) { - MessageLog.GetInstance.Show(ex.ToString()); + DeviceProcessLogShow(ex.ToString()); return 0; } } @@ -823,7 +747,10 @@ namespace BPASmartClient.MorkTLebaiJC // } // } //} - + private void DRCoffee_CoffeEndCookEventHandle(IEvent @event, EventCallBackHandle callBack) + { + are.Set(); + } public override void DoMain() { } @@ -844,7 +771,6 @@ namespace BPASmartClient.MorkTLebaiJC public override void ResetProgram() { } - public override void SimOrder() { } diff --git a/BPASmartClient.MorkTJuicer/BPASmartClient.MorkTJuicer.csproj b/BPASmartClient.MorkTJuicer/BPASmartClient.MorkTJuicer.csproj new file mode 100644 index 00000000..5ca62444 --- /dev/null +++ b/BPASmartClient.MorkTJuicer/BPASmartClient.MorkTJuicer.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/BPASmartClient.MorkTJuicer/Control_MORKJC.cs b/BPASmartClient.MorkTJuicer/Control_MORKJC.cs new file mode 100644 index 00000000..e672cab0 --- /dev/null +++ b/BPASmartClient.MorkTJuicer/Control_MORKJC.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Threading; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Threading.Tasks; +using BPASmartClient.Device; +using BPA.Message.Enum; +using BPA.Message; +using BPASmartClient.Helper; +using BPASmartClient.Model.咖啡机.Enum; +using BPASmartClient.Model; +using BPASmartClient.EventBus; +using static BPASmartClient.EventBus.EventBus; +using BPASmartClient.Model.PLC; +using BPASmartClient.Model.单片机; + +namespace BPASmartClient.MorkTJuicer +{ + /* + * 冰淇淋咖啡机组合套装 + * 物料位置: + * 1:冰淇料 + * 2:冰淇淋杯 + * 5:咖啡 + * 6:咖啡杯 + * 9: 茶 + * 10: 茶杯 + */ + public class Control_MORKJC : BaseDevice + { + GVL_MORKJC mORKD = new GVL_MORKJC(); + //物料存放位置 + private Dictionary batchings = new Dictionary(); + //容器位置 + private string holderLoc; + //主料位置 + private string mainMaterialLoc; + //子订单ID + private string subOrderId; + + private bool enableFunny = false; + private DateTime lastRecvdOrder = DateTime.Now; + private bool working = false; + /// + /// 果汁机做法,true:热饮,false:冷饮 + /// + private bool GuMake = false; + + private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) + { + EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); + } + + //private SerialPortClient commProxy; + public void ConnectOk() + { + + } + ConcurrentQueue morkOrderPushes = new ConcurrentQueue(); + public void Init() + { + //构建所有商品物料信息 + batchings = PolymerBatching.BuildAll(); + Main(); + ReadData(); + ThreadManage.GetInstance().StartLong(new Action(() => + { + while (morkOrderPushes.Count > 0) + { + while (enableFunny) { Thread.Sleep(10); } + DeviceProcessLogShow("当前非自嗨模式,允许开工"); + working = true; + if (morkOrderPushes.TryDequeue(out MorkOrderPush order)) + { + DeviceProcessLogShow($"开始制作订单[{order.SortNum}]"); + //商品类型 + GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; + //子订单ID + subOrderId = order.SuborderId; + //遍历物料 + foreach (var item in order.GoodBatchings) + { + var res = Json.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingId == item.BatchingId); + if (res != null) + { + //获取主料和容器位置 + switch (batchings[res.BatchingLoc].BatchingClass) + { + case BATCHING_CLASS.HOLDER: + holderLoc = res.BatchingLoc; + break; + case BATCHING_CLASS.MAIN_MATERIAL: + // mainMaterialLoc ="1"; + mainMaterialLoc = res.BatchingLoc; + //验证商品是咖啡还是冰淇淋 + if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER) + { + //获取当前物料所属商品类型 + currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc); + } + break; + } + } + } + //根据商品类型执行具体制作流程 + switch (currentGoodsType) + { + case GOODS_TYPE.JUICE: + GuMake = order.MakeID == "2"; + DoJuicer(); + break; + case GOODS_TYPE.NEITHER: + DeviceProcessLogShow("未知的商品类型"); + break; + } + } + working = false; + lastRecvdOrder = DateTime.Now; + } + Thread.Sleep(1000); + }), "订单制作"); + } + + public void Main() + { + //开始心跳刷新,根据咖啡机及冰淇淋机来判断 + //ThreadManage.GetInstance().StartLong(new Action(() => + //{ + // Thread.Sleep(100); + //}), "MORK-IC心跳刷新"); + } + + public void DataParse(T order) + { + if (order is MorkOrderPush morkOrderPush) + { + morkOrderPushes.Enqueue(morkOrderPush); + } + } + + /// + /// + /// + /// 物料位置 + private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc) + { + if (batchings.ContainsKey(batchingLoc)) + return batchings[batchingLoc].GoodsType; + return GOODS_TYPE.NEITHER; + } + + private AutoResetEvent are = new AutoResetEvent(false); + + private T GetStatus(string key) + { + if (peripheralStatus.ContainsKey(key)) + { + if (peripheralStatus[key] != null) + { + return (T)(peripheralStatus[key]); + } + } + return default; + } + + private void Wait(int value) + { + while (!((GetStatus("Get_RobotAO1") == value) && GetStatus("GetProgramStatus") == 0))//判断文件是否已经执行结束 且 文件末端变量值==文件名 + { + Thread.Sleep(5); + } + } + int[] devStatusBy = new int[2] { 0, 0 }; + /// + /// 果汁机控制信号 + /// + private byte JuicerNum; + /// + /// 做果汁 + /// + private void DoJuicer() + { + #region 接果汁流程 + OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + try + { + int JuicerNum1 = int.Parse(mainMaterialLoc); + switch (JuicerNum1) + { + case 52: + if (GuMake) + { + JuicerNum = 0x00; + } + else + { + JuicerNum = 0x01; + } + break; + case 53: + if (GuMake) + { + JuicerNum = 0x02; + } + else + { + JuicerNum = 0x03; + } + break; + case 54: + if (GuMake) + { + JuicerNum = 0x04; + } + else + { + JuicerNum = 0x05; + } + break; + case 55: + if (GuMake) + { + JuicerNum = 0x06; + } + else + { + JuicerNum = 0x07; + } + break; + default: + JuicerNum = 0x00; + break; + } + var devStatus = GetStatus("GetDeviceStatus"); + var devStatus1 = Convert.ToString(devStatus[0], 2); + var devStatus2 = devStatus[1]; + + if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0) + { + new WriteJuicer() { Value = JuicerNum }.Publish(); + + Thread.Sleep(100); + devStatusBy = GetStatus("GetDeviceStatus"); + while (!(devStatusBy[1] == 0)) + { + Thread.Sleep(100); + devStatusBy = GetStatus("GetDeviceStatus"); + while (devStatusBy.Length != 2) + { + Thread.Sleep(100); + devStatusBy = GetStatus("GetDeviceStatus"); + } + } + devStatusBy = GetStatus("GetDeviceStatus"); + Thread.Sleep(5000); + OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + } + } + catch (Exception ex) + { + DeviceProcessLogShow("获取果汁机状态失败"); + } + #endregion + } + + public override DeviceClientType DeviceType => throw new NotImplementedException(); + + + private T McuRead(string tagName, object par) + { + new ReadMcu() { DeviceId = DeviceId, TagName = tagName, ReadPar = par }; + if (peripheralStatus.ContainsKey(tagName)) + { + if (peripheralStatus[tagName] != null) + { + return (T)peripheralStatus[tagName]; + } + } + return default; + } + + public void SimOrder(T simOrder) + { + + } + public override void DoMain() + { + + } + + public override void Stop() + { + + } + + public override void ReadData() + { + + } + + public override void MainTask() + { + + } + + public override void ResetProgram() + { + + } + public override void SimOrder() + { + } + } +} diff --git a/BPASmartClient.MorkTJuicer/GVL_MORKJC.cs b/BPASmartClient.MorkTJuicer/GVL_MORKJC.cs new file mode 100644 index 00000000..34ab7669 --- /dev/null +++ b/BPASmartClient.MorkTJuicer/GVL_MORKJC.cs @@ -0,0 +1,8 @@ +using BPASmartClient.Device; + +namespace BPASmartClient.MorkTJuicer +{ + public class GVL_MORKJC : IStatus + { + } +} diff --git a/BPASmartClient.MorkTJuicer/PolymerBatching.cs b/BPASmartClient.MorkTJuicer/PolymerBatching.cs new file mode 100644 index 00000000..95f11f0f --- /dev/null +++ b/BPASmartClient.MorkTJuicer/PolymerBatching.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkTJuicer +{ + internal enum GOODS_TYPE + { + /// + /// 未知 + /// + NEITHER, + /// + /// 果汁 + /// + JUICE + } + + internal enum BATCHING_CLASS + { + HOLDER, + MAIN_MATERIAL, + } + + internal class PolymerBatching + { + internal const string Juicer_MAIN_BATCHIN1_LOC = "52"; + internal const string Juicer_MAIN_BATCHIN2_LOC = "53"; + internal const string Juicer_MAIN_BATCHIN3_LOC = "54"; + internal const string Juicer_MAIN_BATCHIN4_LOC = "55"; + internal const string COFFEE_HOLDER_LOC = "30"; + internal const string TEA_HOLDER_LOC = "51"; + public static Dictionary GOODS_TYPES = new Dictionary() { + {Juicer_MAIN_BATCHIN1_LOC,GOODS_TYPE.JUICE}, + {Juicer_MAIN_BATCHIN2_LOC,GOODS_TYPE.JUICE}, + {Juicer_MAIN_BATCHIN3_LOC,GOODS_TYPE.JUICE}, + {Juicer_MAIN_BATCHIN4_LOC,GOODS_TYPE.JUICE}, + }; + + 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 TEA_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; + } + } +} diff --git a/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj b/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj index 8c21b75c..83fb3b7c 100644 --- a/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj +++ b/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj @@ -7,9 +7,13 @@ + + + + diff --git a/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs b/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs index 883aafa3..15ce6969 100644 --- a/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs +++ b/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs @@ -16,28 +16,13 @@ using BPASmartClient.EventBus; using static BPASmartClient.EventBus.EventBus; using BPASmartClient.Model.PLC; using BPASmartClient.Model.单片机; +using BPASmartClient.Message; namespace BPASmartClient.MorktJAKAJC { - /* - * 冰淇淋咖啡机组合套装 - * 物料位置: - * 1:冰淇料 - * 2:冰淇淋杯 - * 5:咖啡 - * 6:咖啡杯 - * 9: 茶 - * 10: 茶杯 - */ public class Control_MORKJC : BaseDevice { GVL_MORKJC mORKD = new GVL_MORKJC(); - //咖啡机主控程序 - //private CoffeeMachine coffeeMachine; - ////果汁机主控程序 - //private JuicerMachine juicerMachine; - ////单片机主控程序 - //private ICChipMachine icchipMachine; //物料存放位置 private Dictionary batchings = new Dictionary(); //容器位置 @@ -80,13 +65,6 @@ namespace BPASmartClient.MorktJAKAJC //构建所有商品物料信息 batchings = PolymerBatching.BuildAll(); EventBus.EventBus.GetInstance().Subscribe(DeviceId, DRCoffee_CoffeEndCookEventHandle); - - System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); - //一系列外围基础配置 - var com_Coffee = config.AppSettings.Settings["COM_Coffee"].Value; - var baud_Coffee = config.AppSettings.Settings["BAUD_Coffee"].Value; - //咖啡机创建 - //coffeeMachine = new CoffeeMachine(com_Coffee, (BaudRates)Enum.Parse(typeof(BaudRates), baud_Coffee)); Main(); ReadData(); ThreadManage.GetInstance().StartLong(new Action(() => @@ -99,9 +77,6 @@ namespace BPASmartClient.MorktJAKAJC if (morkOrderPushes.TryDequeue(out MorkOrderPush order)) { DeviceProcessLogShow($"开始制作订单[{order.SortNum}]"); - - - //商品类型 GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; //子订单ID @@ -131,7 +106,6 @@ namespace BPASmartClient.MorktJAKAJC } } } - //根据商品类型执行具体制作流程 switch (currentGoodsType) { @@ -162,8 +136,6 @@ namespace BPASmartClient.MorktJAKAJC public void Main() { - //咖啡机开启主线程 - //coffeeMachine.Start(); //开始心跳刷新,根据咖啡机及冰淇淋机来判断 ThreadManage.GetInstance().StartLong(new Action(() => { @@ -175,14 +147,6 @@ namespace BPASmartClient.MorktJAKAJC //GeneralConfig.Healthy = true; Thread.Sleep(100); }), "MORK-IC心跳刷新"); - //ThreadManage.GetInstance().Start(new Action(() => - //{ - // while (!Write.IsConnected) - // { - // Thread.Sleep(10); - // } - // //LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_欢迎); - //}), "MORK-JC欢迎"); } public void DataParse(T order) @@ -242,14 +206,12 @@ namespace BPASmartClient.MorktJAKAJC { #region 接咖啡流程 are.Reset(); - // OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); int resultTakeCup = takeCup(); if (resultTakeCup == 1) { DeviceProcessLogShow("咖啡杯取杯完成"); new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡 }.Publish(); - // Write("JaKaProgramName",JakaModel.SENCE_接咖啡); Wait(int.Parse(JakaModel.SENCE_接咖啡)); new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水 are.WaitOne(1000 * 180); @@ -351,7 +313,6 @@ namespace BPASmartClient.MorktJAKAJC int resultTakeCup = takeCup(); if (resultTakeCup == 1) { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接水 }.Publish(); Wait(int.Parse(JakaModel.SENCE_接水)); @@ -616,13 +577,6 @@ namespace BPASmartClient.MorktJAKAJC new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish(); Wait(int.Parse(JakaModel.SENCE_取杯检测)); bSensorInput = sensor_Sign(1); - /*delayTimeOut = DateTime.Now; - bSensorInput = sensor_Sign(1); - while (bSensorInput == 3) - { - Thread.Sleep(100); - bSensorInput = sensor_Sign(1); - }*/ while (getCup_cnt < 4 && (bSensorInput == 2 || bSensorInput == 3)) { DeviceProcessLogShow($"第{getCup_cnt}次取杯失败"); @@ -654,7 +608,7 @@ namespace BPASmartClient.MorktJAKAJC } catch (Exception ex) { - DeviceProcessLogShow(ex.ToString()); + MessageLog.GetInstance.ShowEx(ex.ToString()); return 0; } } @@ -697,7 +651,7 @@ namespace BPASmartClient.MorktJAKAJC } catch (Exception ex) { - DeviceProcessLogShow(ex.ToString()); + MessageLog.GetInstance.ShowEx(ex.ToString()); return 0; } } @@ -713,7 +667,6 @@ namespace BPASmartClient.MorktJAKAJC { try { - //cnt_Check = 0; bSensorInput = sensor_Sign(2); if (bSensorInput == 2) { @@ -729,7 +682,7 @@ namespace BPASmartClient.MorktJAKAJC } catch (Exception ex) { - DeviceProcessLogShow(ex.ToString()); + MessageLog.GetInstance.ShowEx(ex.ToString()); return 0; } } diff --git a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml new file mode 100644 index 00000000..a1e6ee6b --- /dev/null +++ b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml @@ -0,0 +1,397 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 制热 + 制冷 + 缺水 + 童锁 + 使用 + + + + + + + + 果汁 + + 饮品1 + 饮品2 + 饮品3 + 饮品4 + + + 冷饮 + 热饮 + + + + + 1 + + + + + + + + + + + + + + DI输入 + + + + + + + + + + + + + + + DI0 + + + DI1 + + + DI2 + + + DI3 + + + DI4 + + + DI5 + + + DI6 + + + DI7 + + + + + + + + + + + + + + + + + + DO输出 + + + + DO0 + DO1 + DO2 + DO3 + DO4 + DO5 + DO6 + DO7 + + + + + + + True + false + + + + + + diff --git a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs new file mode 100644 index 00000000..9a5f1480 --- /dev/null +++ b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs @@ -0,0 +1,35 @@ +using BPASmartClient.Helper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkTJAKAJC.View +{ + /// + /// DebugView.xaml 的交互逻辑 + /// + public partial class DebugView : UserControl + { + public DebugView() + { + InitializeComponent(); + } + + private void Dubug_Unloaded(object sender, RoutedEventArgs e) + { + ThreadManage.GetInstance().StopTask("MorkT-状态刷新"); + ThreadManage.GetInstance().StopTask("MorkT-传感器监视"); + } + } +} diff --git a/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs b/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs new file mode 100644 index 00000000..9b0c3763 --- /dev/null +++ b/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs @@ -0,0 +1,237 @@ +using BPASmartClient.Business; +using BPASmartClient.Device; +using BPASmartClient.DRCoffee; +using BPASmartClient.EventBus; +using BPASmartClient.GSIceCream; +using BPASmartClient.Helper; +using BPASmartClient.LebaiRobot; +using BPASmartClient.Message; +using BPASmartClient.Model; +using BPASmartClient.Model.乐白机器人; +using BPASmartClient.Model.冰淇淋.Enum; +using BPASmartClient.Model.单片机; +using BPASmartClient.Model.单片机.Enum; +using BPASmartClient.Model.咖啡机.Enum; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; + +namespace BPASmartClient.MorkTJAKAJC.ViewModel; + public class DebugViewModel : ObservableObject + { + + #region 乐白机器人 + /// + /// 乐白机器人连接状态 + /// + public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } } + private string _robotConnected { get; set; } + /// + /// 乐白机器人的模式状态 + /// + public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } } + private string _robotMode { get; set; } + /// + /// 机器人控制指令 + /// + public RelayCommand Button_RobotControlCommand { get; set; } + /// + /// 机器人控制 + /// + /// + private void Button_RobotControl(object o) + { + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() }); + } + + #endregion + + + + #region 果汁机 + /// + /// 果汁机的连接状态 + /// + public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } } + private string _JuicerConnected { get; set; } + + /// + /// 果汁机的状态 + /// + public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } } + private string _JuicerState { get; set; } + + #endregion + + #region 咖啡机 + /// + /// 咖啡机连接状态 + /// + public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } } + private string _coffeeConnected { get; set; } + /// + /// 咖啡机状态 + /// + public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } } + private string _coffeeStatus { get; set; } + /// + /// 应用状态 + /// + public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } } + private string _appStatus { get; set; } + /// + /// 告警 + /// + public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } } + public string _warning { get; set; } + /// + /// 故障信息 + /// + public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } } + public string _caffeeFault { get; set; } + + public List Coffees { get; set; } = new List(); + public string SelectedCoffee { get; set; } + + public List CoffeeCmds { get; set; } = new List(); + public string SelectedCoffeeCmd { get; set; } + /// + /// 制作咖啡 + /// + public RelayCommand Button_MakeCoffeeCommand { get; set; } + /// + /// 停止制作咖啡 + /// + public RelayCommand Button_StopMakeCoffeCommand { get; set; } + /// + /// 咖啡模式设置 + /// + public RelayCommand Button_CoffeeModeSetCommand { get; set; } + + private void Button_MakeCoffee() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)}); + } + private void Button_StopMakeCoffe() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId }); + } + private void Button_CoffeeModeSet() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)}); + } + #endregion + + #region 单片机 + /// + /// 咖啡杯或冰淇淋杯落杯 + /// + public RelayCommand Button_CupControlCommand { get; set; } + /// + /// 单片机冰淇淋机器制冷 + /// + public RelayCommand Button_SCChipRefrigerationCommand { get; set; } + /// + /// 单片机冰淇淋机器打料 + /// + public RelayCommand Button_SCChipDischargeCommand { get; set; } + /// + /// 模拟测试 + /// + public RelayCommand Button_SCChipTestCommand { get; set; } + + private void Button_CupControl(object CupType) + { + EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) }); + } + + private void Button_SCChipRefrigeration() + { + EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true }); + Thread.Sleep(500); + EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false }); + + } + + private void Button_SCChipDischarge() + { + EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 }); + } + + #endregion + + /// + /// 设备ID + /// + public int DeviceId { get; set; } + /// + /// 设备数据 + /// + public ObservableCollection variableMonitors { get; set; } + + public DebugViewModel() + { + Button_RobotControlCommand = new RelayCommand(Button_RobotControl); + Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee); + Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe); + Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet); + + Button_CupControlCommand = new RelayCommand(Button_CupControl); + Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration); + Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge); + Button_SCChipTestCommand = new RelayCommand(() => + { + Button_SCChipRefrigeration(); + Thread.Sleep(50); + Button_SCChipDischarge(); + }); + + foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode))) + { + Coffees.Add(code.ToString()); + } + SelectedCoffee = Coffees[0]; + foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd))) + { + CoffeeCmds.Add(code.ToString()); + } + SelectedCoffeeCmd = CoffeeCmds[0]; + + Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device => + { + if (device.Name == "MorkT") DeviceId = device.DeviceId + ; + }); + + + + ThreadManage.GetInstance().StartLong(new Action(() => + { + + variableMonitors = Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors; + + if (variableMonitors != null && variableMonitors.Count > 0) + { + RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + + RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue; + + CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue; + AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue; + Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue; + CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue; + + + } + + Thread.Sleep(500); + }), "MorkT-状态刷新"); + } + } + diff --git a/BPASmartClient.Morkt.JAKA.JC/ViewModel/MonitorViewModel.cs b/BPASmartClient.Morkt.JAKA.JC/ViewModel/MonitorViewModel.cs new file mode 100644 index 00000000..78dd38bf --- /dev/null +++ b/BPASmartClient.Morkt.JAKA.JC/ViewModel/MonitorViewModel.cs @@ -0,0 +1,94 @@ +using BPASmartClient.Business; +using BPASmartClient.Helper; +using BPASmartClient.Model.乐白机器人; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace BPASmartClient.MorkTJAKAJC.ViewModel +{ + + public class MonitorViewModel: ObservableObject + { + #region 传感器 + /// + /// 机器人夹爪传感器 + /// + public bool RobotSenser { get { return _robotSenser; } set { _robotSenser = value; OnPropertyChanged(); } } + private bool _robotSenser; + /// + /// 冰淇淋出口传感器 + /// + public bool IceCreamSenser { get { return _iceCreamSenser; } set { _iceCreamSenser = value; OnPropertyChanged(); } } + private bool _iceCreamSenser; + /// + /// 取餐口检测传感器 + /// + public bool TakeMealSenser { get { return _takeMealSenser; } set { _takeMealSenser = value; OnPropertyChanged(); } } + private bool _takeMealSenser; + + #endregion + + + /// + /// 设备ID + /// + int DeviceId; + public MonitorViewModel() + { + Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device => + { + if (device.Name == "MorkT") DeviceId = device.DeviceId; + + }); + ThreadManage.GetInstance().StartLong(new Action(() => + { + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 1 },(res)=> + { + if(res != null&& res.Length>0&& res[0] is bool b) + { + RobotSenser = b; + } + }); + + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (res) => + { + if (res != null && res.Length > 0 && res[0] is bool b) + { + TakeMealSenser = b; + } + }); + + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 3 }, (res) => + { + if (res != null && res.Length > 0 && res[0] is bool b) + { + IceCreamSenser = b; + } + }); + Thread.Sleep(500); + }), "MorkT-传感器监视"); + } + } + + public class BoolToColorConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return (bool) value? new SolidColorBrush(Color.FromRgb(144, 238, 144)) : new SolidColorBrush(Color.FromRgb(178, 34, 34)); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + +} diff --git a/BPASmartClient/BPASmartClient.csproj b/BPASmartClient/BPASmartClient.csproj index e648479b..bba8ce8f 100644 --- a/BPASmartClient/BPASmartClient.csproj +++ b/BPASmartClient/BPASmartClient.csproj @@ -35,6 +35,7 @@ + diff --git a/BPASmartClient/Control/VersionView.xaml b/BPASmartClient/Control/VersionView.xaml index de474be6..e2f3dec5 100644 --- a/BPASmartClient/Control/VersionView.xaml +++ b/BPASmartClient/Control/VersionView.xaml @@ -23,7 +23,7 @@ -