|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- 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.单片机;
- using BPASmartClient.Message;
-
- namespace BPASmartClient.MorktJAKAJC
- {
- public class Control_MORKJC : BaseDevice
- {
- GVL_MORKJC morkTJakaJC = new GVL_MORKJC();
- //物料存放位置
- private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
- //容器位置
- private string holderLoc;
- //主料位置
- private string mainMaterialLoc;
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
- /// <summary>
- /// 果汁机做法,true:热饮,false:冷饮
- /// </summary>
- 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 });
- }
- public override void DoMain()
- {
- if (Json<KeepDataBase>.Data.IsVerify)
- {
- IsHealth = true;
- }
- IsHealth = true;
- serverInit();
- DataParse();
- }
-
- private void serverInit()
- {
- EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is MaterialDeliveryEvent material)
- {
- orderMaterialDelivery = material.orderMaterialDelivery;
- }
- });
- }
-
- private void DataParse()
- {
- EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
- {
- if (@event == null) return;
- if (@event is DoOrderEvent order)
- {
- if (order.MorkOrder.GoodBatchings == null) return;
- OrderCount++;
- DeviceProcessLogShow($"接收到{OrderCount}次订单");
- batchings = PolymerBatching.BuildAll();
-
- //商品类型
- GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
-
- 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);
- }
- //
- switch (batchings[res.BatchingLoc].BatchingClass)
- {
- case BATCHING_CLASS.HOLDER:
- holderLoc = res.BatchingLoc;
- break;
- case BATCHING_CLASS.MAIN_MATERIAL:
- mainMaterialLoc = res.BatchingLoc;
- break;
- }
- //根据商品类型执行具体制作流程
- switch (currentGoodsType)
- {
- case GOODS_TYPE.COFFEE:
- if (morkTJakaJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTJakaJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.JUICE:
- GuMake = order.MorkOrder.MakeID == "2";//判断果汁的冷热
- if (morkTJakaJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTJakaJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.TEA:
- if (morkTJakaJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTJakaJC.morkOrderPushesTea.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.WATER:
- if (morkTJakaJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTJakaJC.morkOrderPushesWater.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.NEITHER:
- DeviceProcessLogShow("未知的商品类型");
- break;
- }
- }
- }
- }
- });
- }
- private bool bFirstTrig_TeaWater = false;
- private bool bFirstTrig_Coffee = false;
- DateTime delayTimeOut_Coffee;
- private bool bFirstTrig_Juice = false;
- DateTime delayTimeOut_Juice;
- /// <summary>
- /// 判断接咖啡的位置是否有杯子
- /// </summary>
- bool pickUpCoffeeHaveCup = false;
- /// <summary>
- /// 判断接果汁的位置是否有杯子
- /// </summary>
- bool pickUpJuiceHaveCup = false;
- /// <summary>
- /// 判断接开水的位置是否有杯子
- /// </summary>
- bool pickUpHotWaterHaveCup = false;
- public override void MainTask()
- {
- EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (morkTJakaJC.IsHaveCoffeeCup)
- morkTJakaJC.MakeCoffeeEnd = true;
- });
- if (pickUpCoffeeHaveCup)
- {
- if (!bFirstTrig_Coffee)
- {
- bFirstTrig_Coffee = true;
- delayTimeOut_Coffee = DateTime.Now;
- }
- else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true)
- {
- bFirstTrig_Coffee = false;
- if (morkTJakaJC.IsHaveCoffeeCup)
- morkTJakaJC.MakeCoffeeEnd = true;
- }
- }
- if (morkTJakaJC.IsHaveJuiceCup)
- {
- var Juicestate = GetStatus<int[]>("GetDeviceStatus");
- if (Juicestate != null)
- {
- if (Juicestate.Length > 0)
- {
- var Juicestate1 = Convert.ToString(Juicestate[0], 2);
- var Juicestate2 = Juicestate[1];
- if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0)
- {
- morkTJakaJC.MakeJuiceEnd = true;
- }
- }
- }
- //若无状态返回 则加延迟
- if (!bFirstTrig_Juice)
- {
- bFirstTrig_Juice = true;
- delayTimeOut_Juice = DateTime.Now;
- }
- else if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 30 && bFirstTrig_Juice == true)
- {
- bFirstTrig_Juice = false;
- morkTJakaJC.MakeJuiceEnd = true;
- }
- }
- if (morkTJakaJC.IsHaveTeaWaterCup)
- {
- if (!bFirstTrig_TeaWater)
- {
- bFirstTrig_TeaWater = true;
- delayTimeOut = DateTime.Now;
- }
- else if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 50 && bFirstTrig_TeaWater == true)
- {
- bFirstTrig_TeaWater = false;
- morkTJakaJC.MakeTeaEnd = true;
- }
- }
- DoCoffee();
- DoJuice();
- DoBoiledTea();
- DoBoiledWater();
- }
- /// <summary>
- /// 验证当前是做咖啡还是做冰淇淋
- /// </summary>
- /// <param name="batchingLoc">物料位置</param>
- 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<T>(string key)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- return (T)(peripheralStatus[key]);
- }
- }
- return default;
- }
-
- private void Wait(int value)
- {
- while (!((GetStatus<int>("Get_RobotAO1") == value) && GetStatus<int>("GetProgramStatus") == 0))//判断文件是否已经执行结束 且 文件末端变量值==文件名
- {
- Thread.Sleep(5);
- }
- }
- int[] devStatusBy = new int[2] { 0, 0 };
- private bool IsMakeCoffee()
- {
- bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesCoffee.Count > 0 && !morkTJakaJC.IsHaveCoffeeCup) ? true : false;
- return bMake;
- }
- private bool IsMakeJuice()
- {
- bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesJuicer.Count > 0 && !morkTJakaJC.IsHaveJuiceCup) ? true : false;
- return bMake;
- }
- private bool IsMakeTeaWater()
- {
- bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesTea.Count > 0 && !morkTJakaJC.IsHaveTeaWaterCup) ? true : false;
- return bMake;
- }
- private bool IsMakeWater()
- {
- bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesWater.Count > 0 && !morkTJakaJC.IsHaveTeaWaterCup) ? true : false;
- return bMake;
- }
- /// <summary>
- /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
- /// </summary>
- int bSensorInput;
- /// <summary>
- /// 延迟的超时时间
- /// </summary>
- DateTime delayTimeOut;
- /// <summary>
- /// 做咖啡
- /// </summary>
- private void DoCoffee()
- {
- if (IsMakeCoffee())
- {
- if (morkTJakaJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
- {
- PickUpCoffee();//接咖啡
- morkTJakaJC.IsHaveCoffeeCup = true;
- }
- }
- else if (morkTJakaJC.MakeCoffeeEnd)
- {
- PutCoffeeCup();
- pickUpCoffeeHaveCup = false;
- morkTJakaJC.IsHaveCoffeeCup = false;
- }
- }
- private void DoJuice()
- {
- if (IsMakeJuice())
- {
- if (morkTJakaJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc))
- {
- PickUpJuicer();
- morkTJakaJC.IsHaveJuiceCup = true;
- }
- }
- else if (morkTJakaJC.MakeJuiceEnd)
- {
- Thread.Sleep(5000);//延迟五秒,防止接饮料口滴饮料
- putJuice();
- pickUpJuiceHaveCup = false;
- morkTJakaJC.IsHaveJuiceCup = false;
- morkTJakaJC.MakeJuiceEnd = false;
- }
- }
- private void DoBoiledTea()
- {
- if (IsMakeTeaWater())
- {
- if (morkTJakaJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc))
- {
- PickUpTea();
- morkTJakaJC.IsHaveTeaWaterCup = true;
- }
- }
- else if (morkTJakaJC.MakeTeaEnd)
- {
- PutWaterCup();
- pickUpHotWaterHaveCup = false;
- morkTJakaJC.IsHaveTeaWaterCup = false;
- morkTJakaJC.MakeTeaEnd = false;
- }
- }
- private void DoBoiledWater()
- {
- if (IsMakeWater())
- {
- if (morkTJakaJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc))
- {
- PickUpWater();
- }
- }
- else if (morkTJakaJC.MakeTeaEnd)
- {
- PutWaterCup();
- pickUpHotWaterHaveCup = false;
- morkTJakaJC.IsHaveTeaWaterCup = false;
- morkTJakaJC.MakeTeaEnd = false;
- }
- }
- private void PickUpCoffee()
- {
- if (!pickUpCoffeeHaveCup)
- {
- OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- DeviceProcessLogShow("咖啡杯取杯完成");
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接咖啡));
-
- new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
- are.WaitOne(1000 * 180);
- }
- else
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- }
- private void PutCoffeeCup()
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放咖啡杯 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放咖啡杯));
- int resultputCup = putCup();
- if (resultputCup == 1)
- {
- //订单状态改变:完成
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- }
- else
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- /// <summary>
- /// 接开水
- /// </summary>
- private void PickUpWater()
- {
- #region 接水流程
- if (!pickUpHotWaterHaveCup)
- {
- OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接水 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接水));
-
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
-
-
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish();
- Thread.Sleep(100);
- new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish();
- Thread.Sleep(3000);
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish();
- Thread.Sleep(100);
-
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
- Thread.Sleep(100);
- new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish();
- Thread.Sleep(500);
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
- }
- else if (resultTakeCup == 2 || resultTakeCup == 3)
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- #endregion
- }
- /// <summary>
- /// 放水杯
- /// </summary>
- private void PutWaterCup()
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放茶水杯 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放茶水杯));
- int resultputCup = putCup();
- if (resultputCup == 1)
- {
- //订单状态改变:完成
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- }
- else
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- /// <summary>
- /// 做茶
- /// </summary>
- private void PickUpTea()
- {
- #region 接茶流程
- if (!pickUpHotWaterHaveCup)
- {
- OrderChange(morkTJakaJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- DeviceProcessLogShow("取茶杯完成");
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接茶));
-
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish();
- Thread.Sleep(1000);
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 130 }.Publish();
- Thread.Sleep(1000);
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish();
-
- Thread.Sleep(3000);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶_接水 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接茶_接水));
-
-
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish();
-
- Thread.Sleep(100);
- new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish();
- Thread.Sleep(3000);
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish();
- Thread.Sleep(100);
-
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
- Thread.Sleep(100);
- new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish();
- Thread.Sleep(500);
- new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish();
- }
- else if (resultTakeCup == 2 || resultTakeCup == 3)
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- #endregion
- }
- /// <summary>
- /// 果汁机控制信号
- /// </summary>
- private byte JuicerNum;
- private int JuiceCH;
- private void PickUpJuicer()
- {
- #region 接果汁流程
- if (!pickUpJuiceHaveCup)
- {
- OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- JuiceCH = int.Parse(mainMaterialLoc);
- if (resultTakeCup == 1)
- {
- switch (JuiceCH)
- {
- case 52:
- if (GuMake)
- {
- JuicerNum = 0x00;
- }
- else
- {
- JuicerNum = 0x01;
- }
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接果汁1));
- break;
- case 53:
- if (GuMake)
- {
- JuicerNum = 0x02;
- }
- else
- {
- JuicerNum = 0x03;
- }
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁2 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接果汁2));
- break;
- case 54:
- if (GuMake)
- {
- JuicerNum = 0x04;
- }
- else
- {
- JuicerNum = 0x05;
- }
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁3 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接果汁3));
- break;
- case 55:
- if (GuMake)
- {
- JuicerNum = 0x06;
- }
- else
- {
- JuicerNum = 0x07;
- }
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁4 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接果汁4));
- break;
- default:
- JuicerNum = 0x00;
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_接果汁1));
- break;
- }
- new WriteJuicer() { Value = JuicerNum }.Publish();
- pickUpJuiceHaveCup = true;
- }
- else
- {
- return;
- }
- }
- #endregion
- }
- private void putJuice()
- {
- switch (JuiceCH)
- {
- case 52:
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放果汁杯1));
- break;
- case 53:
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯2 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放果汁杯2));
- break;
- case 54:
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯3 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放果汁杯3));
- break;
- case 55:
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯4 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放果汁杯4));
- break;
- default:
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放果汁杯1));
- break;
- }
- int resultputCup = putCup();
- if (resultputCup == 1)
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- }
- else
- {
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- }
- }
- private int getCup_cnt;
- /// <summary>
- /// 取杯流程
- /// </summary>
- /// <returns>0:无意义,1:取杯成功 2:机构有杯子,取杯失败 3:机构没有杯子</returns>
- private int takeCup()
- {
- #region 单片机控制的IO
- //try
- //{
- // getCup_cnt = 0;//取杯次数复位
- // new WriteJaka() { TagName = "Set_RobotAO1", Value = 0 }.Publish();
- // Wait(0);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_初始位));
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish();
- // Thread.Sleep(10);
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish();
- // new WriteJaka() { TagName = "Set_RobotAO1", Value = 0 }.Publish();
- // Wait(0);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_取杯));
- // bSensorInput = sensor_Sign(1);
- // if (bSensorInput == 2)
- // {
- // Thread.Sleep(100);
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // Thread.Sleep(100);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_取杯检测));
- // DeviceProcessLogShow("落杯器没有纸杯了");
- // return 3;
- // }
- // if (bSensorInput == 1)
- // {
- // Thread.Sleep(100);
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // Thread.Sleep(100);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_取杯检测));
- // bSensorInput = sensor_Sign(1);
- // while (getCup_cnt < 4 && (bSensorInput == 2 || bSensorInput == 3))
- // {
- // DeviceProcessLogShow($"第{getCup_cnt}次取杯失败");
- // Thread.Sleep(100);
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish();
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish();
- // Thread.Sleep(100);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_取杯));
- // getCup_cnt = getCup_cnt + 1;
- // Thread.Sleep(100);
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish();
- // Thread.Sleep(100);
- // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- // Wait(int.Parse(JakaModel.SENCE_取杯检测));
- // bSensorInput = sensor_Sign(1);
- // }
- // if (bSensorInput == 1)
- // {
- // return 1;
- // }
- // else
- // {
- // return 2;
- // }
- // }
- // return 1;
- //}
- //catch (Exception ex)
- //{
- // MessageLog.GetInstance.ShowEx(ex.ToString());
- // return 0;
- //}
- #endregion
- try
- {
- getCup_cnt = 0;//取杯次数复位
- new WriteJaka() { TagName = "Set_RobotAO1", Value = 0 }.Publish();
- Wait(0);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- new WriteJaka() { TagName = "JakaDOutput", DO_Index=0, Value = true }.Publish();
- Thread.Sleep(100);
- new WriteJaka() { TagName = "Set_RobotAO1", Value = 0 }.Publish();
- Wait(0);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_取杯));
- //取杯到位,使用落杯器
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 1, Value = true }.Publish();
- if (sensor_Sign(1)==1 )
- {
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 1, Value = false }.Publish();
- Thread.Sleep(2000);
- bSensorInput = sensor_Sign(0);
- if (bSensorInput == 2)
- {
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 0, Value = false }.Publish();
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_取杯检测));
- DeviceProcessLogShow("落杯器没有纸杯了");
- return 3;
- }
- if (bSensorInput == 1)
- {
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 0, Value = false }.Publish();
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_取杯检测));
- bSensorInput = sensor_Sign(1);
- while (getCup_cnt < 4 && (bSensorInput == 2 || bSensorInput == 3))
- {
- DeviceProcessLogShow($"第{getCup_cnt}次取杯失败");
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 0, Value = true }.Publish();
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_取杯));
- getCup_cnt = getCup_cnt + 1;
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 0, Value = false }.Publish();
- Thread.Sleep(100);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯检测 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_取杯检测));
- bSensorInput = sensor_Sign(1);
- }
- if (bSensorInput == 1)
- {
- return 1;
- }
- else
- {
- return 2;
- }
- }
- }
-
- return 1;
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- return 0;
- }
- }
- /// <summary>
- /// 放杯
- /// </summary>
- /// <returns>0:无意义 1:执行成功 2:执行失败(传感器还有信号)</returns>
- private int putCup()
- {
- try
- {
- while (checkCup() == 2)
- {
- Thread.Sleep(100);
- }
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放杯));
- Thread.Sleep(10);
- new WriteJaka() { TagName = "JakaDOutput", DO_Index = 0, Value = true }.Publish();
- Thread.Sleep(10);
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯检测 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_放杯检测));
- bSensorInput = sensor_Sign(3);
- delayTimeOut = DateTime.Now;
- while (bSensorInput == 2)
- {
- Thread.Sleep(100);
- bSensorInput = sensor_Sign(3);
- if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 2) return 2;
- }
- if (bSensorInput == 2)
- {
- DeviceProcessLogShow("放杯失败传感器没有信号");
- new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
- Wait(int.Parse(JakaModel.SENCE_初始位));
- return 1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- return 0;
- }
- }
- private int cnt_Check;
- /// <summary>
- /// 检测放杯位,是否有杯子
- /// </summary>
- /// <returns>0:无意义 1:没有杯子 2:有杯子 </returns>
- private int checkCup()
- {
- try
- {
- bSensorInput = sensor_Sign(2);
- if (bSensorInput == 2)
- {
- DeviceProcessLogShow($"放杯位传感器没有信号:{cnt_Check}");
- return 1;
- }
- else if (bSensorInput == 1)
- {
- DeviceProcessLogShow($"放杯位传感器有信号:{cnt_Check}");
- return 2;
- }
- return 2;
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- return 0;
- }
- }
-
- private T McuRead<T>(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;
- }
-
-
-
- /// <summary>
- /// 传感器防抖0.2s内检测20次,
- /// </summary>
- /// <param name="num"></param>
- /// <returns></returns>
- private int sensor_Sign(byte num)
- {
- DeviceProcessLogShow($"开始检测{num}号传感器信号");
- int cnt = 0;
- cnt_Check = 0;
- while (true)
- {
- Thread.Sleep(10);
- if (num == 0)
- {
- bSensorInput = GetStatus<bool>("Get_RobotDI0") ? 1 : 2;
- }
- else if (num == 1)
- {
- bSensorInput = GetStatus<bool>("Get_RobotDI1") ? 1 : 2;
- }
- else if (num == 2)
- {
- bSensorInput = GetStatus<bool>("Get_RobotDI2") ? 1 : 2;
- }
- else if (num == 3)
- {
- bSensorInput = GetStatus<bool>("Get_RobotDI3") ? 1 : 2;
- }
- if (bSensorInput == 1)
- {
- cnt_Check = cnt_Check + 1;
- cnt = cnt + 1;
- }
- else if (bSensorInput == 2)
- {
- cnt_Check = cnt_Check - 1;
- cnt = cnt + 1;
- }
- if (cnt >= 20)
- {
- break;
- }
- }
- if (cnt_Check >= 0)
- {
- DeviceProcessLogShow($"{num}传感器有信号:{cnt_Check}");
- return 1;
- }
- else
- {
- DeviceProcessLogShow($"{num}传感器没有信号:{cnt_Check}");
- return 2;
- }
- }
- private void DRCoffee_CoffeEndCookEventHandle(IEvent @event, EventCallBackHandle callBack)
- {
- are.Set();
- }
-
- public void SimOrder<T>(T simOrder)
- {
-
- }
-
-
-
- public override void Stop()
- {
-
- }
-
- public override void ReadData()
- {
-
- }
-
-
- public override void ResetProgram()
- {
-
- }
-
- public override void SimOrder()
- {
- }
- }
- }
|