|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382 |
- using BPA.Message;
- using BPA.Message.Enum;
- using BPASmartClient.Device;
- using BPASmartClient.EventBus;
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.PLC;
- using BPA.Models;
- using static BPASmartClient.EventBus.EventBus;
- using BPASmartClient.Model.小炒机;
- using BPASmartClient.MorkF.Model;
- using System.Text;
- using System.Collections.Concurrent;
- using System.Windows.Documents;
- using BPASmartClient.Business;
-
- namespace BPASmartClient.MorkF
- {
- public class Control_MorkF : BaseDevice
- {
-
- /// <summary>
- /// while循环最大sleep次数
- /// </summary>
- private const int sleepCount = 20;
-
- /// <summary>
- /// while循环每次sleep时间
- /// </summary>
- private const int sleepTime = 500;
-
- /// <summary>
- /// 菜品库while循环最大sleep次数
- /// </summary>
- private const int materialSleepCount = 600;
-
- /// <summary>
- /// 菜品库while循环每次sleep时间
- /// </summary>
- private const int materialSleepTime = 100;
-
- /// <summary>
- /// 初始化炒锅数量
- /// </summary>
- private int count = 2;
-
- /// <summary>
- /// 菜品盒下移高度,相对于坐标系
- /// </summary>
- private const int materialBoxHigh = 4080;
-
- //菜品库一层的高度
- private const int materialHigh = 34500;
-
- /// <summary>
- /// 菜品库第一层的起始基点,为最下层盒子的中间点
- /// </summary>
- private const int materialOne = 34500;
-
- /// <summary>
- /// 菜品库第二层的起始基点,为最下层盒子的中间点
- /// </summary>
- private const int materialTwo = 34500;
-
- /// <summary>
- /// 菜品库第三层的起始基点,为最下层盒子的中间点
- /// </summary>
- private const int materialThree = 34500;
-
- //传感器到菜品库的高度(坐标系)
- private const int materialLaserHigh = 34500;
-
- //传感器到菜品库的高度(厘米)
- private const int materialLaserHighCM = 29;
-
- /// <summary>
- /// 传感器到隔板的距离(坐标系)
- /// </summary>
- private const int clapboardLaserHigh = 10000;
-
- //炒锅1倒菜的xy坐标
- private const int materialPutPositionXFry1 = 70000;
- private const int materialPutPositionYFry1 = 40000;
-
- //炒锅2倒菜的xy坐标
- private const int materialPutPositionXFry2 = 70000;
- private const int materialPutPositionYFry2 = 40000;
-
- //菜品库机械爪放置菜品距离
- private const int materialToFryDistance = 10000;
-
- //当前炒锅,默认为1号炒锅
- private int fryIndex = 0;
-
- public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
- public AutoResetEvent minorReset = new AutoResetEvent(false);
- public AutoResetEvent mainReset = new AutoResetEvent(false);
-
- /// <summary>
- /// 炒锅编号与炒锅实例
- /// </summary>
- Dictionary<int, GVL_MorkF> morkFs = new Dictionary<int, GVL_MorkF>();//全局对象声明
-
- /// <summary>
- /// 菜品库对象
- /// </summary>
- ML_MorkF ml_morkf = new ML_MorkF();
-
- /// <summary>
- /// 小炒菜单集合
- /// </summary>
- public static List<StirFryGoods> LocalstirFryGoods = new List<StirFryGoods>();
-
- /// <summary>
- /// 待炒小炒队列
- /// </summary>
- private ConcurrentQueue<OrderLocInfo> StirFryGoodsQuenes = new ConcurrentQueue<OrderLocInfo>();
-
- /// <summary>
- /// 炒锅炒制线程名称
- /// </summary>
- private const String striConst = "炒锅{0}炒制{1}线程";
-
- /// <summary>
- /// 当前炒制菜品
- /// </summary>
- private OrderLocInfo[] nowStirFryGood = new OrderLocInfo[2];
-
- /// <summary>
- /// 待取菜队列
- /// </summary>
- private ConcurrentQueue<MaterialOperation> materialOperationQuenes = new ConcurrentQueue<MaterialOperation>();
-
- List<int> resultorder = new List<int>();//调试变量
-
- /// <summary>
- /// 入口
- /// </summary>
- public override void DoMain()
- {
- IsHealth = true;
-
- for (int i = 0; i < count; i++)
- {
- morkFs.Add(i, new GVL_MorkF());
- }
-
- DataParse();//数据解析
- CommandRegist();//调试
- ServerInit();
- DeviceProcessLogShow("MORKF 设备初始化完成");
- ///初始化菜品库
- //FoodLibInit();
- Task2ReadMaterialData();
-
- //Json<MaterialSurplus>.Read();
- }
-
- /// <summary>
- /// 主任务
- /// </summary>
- public override void MainTask()
- {
- //炒锅炒制线程
- MainProcessExcute();
- //菜品库操作线程
- MainProcessMaterial();
- //MinorProcessExcute();
- //SingleProcess();
- }
-
- private void Task2ReadMaterialData()
- {
- ThreadManage.GetInstance().StartLong(new Action(() => {
-
- //获取定位到达状态
- GetStatus("M10.0", new Action<object>((objects) =>
- {
- if (objects is bool[] bools)
- {
-
- //ml_morkf.ArriveComplete = bools[i];
- //小炒定点到达上升沿信号捕获
- if (RTrig.GetInstance("SmartArriveComplete").Start(bools[0]))
- {
- if (isInitialArrive == false)
- {
- MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false");
- isInitialArrive = true;
- }
- else
- {
- MessageLog.GetInstance.Show("到达上升沿为true");
- ml_morkf.ArriveComplete = true;
- isInitialArrive = true;
- }
- }
- }
-
- }), 2);
- }), "ReadMaterialSmartArriveCompleteData", true);
-
- ThreadManage.GetInstance().StartLong(new Action(() => {
- ReadMaterialData();
-
- Thread.Sleep(10);
- }), "ReadMaterialData", true);
- }
-
- private void ReadMaterialData()
- {
- //获取激光距离
- GetStatus("VW270", new Action<object>((objects) =>
- {
- if (objects is ushort[] bools)
- {
- for (int i = 0; i < 1; i++)
- {
- ml_morkf.LaserDistance = bools[i];
- }
- }
- }), 2);
-
- //获取坐标X
- GetStatus("VD828", new Action<object>((objects) =>
- {
- if (objects is int bools)
- {
- ml_morkf.ArmPositionX = bools;
- }
- }), 2);
-
- //获取坐标Y
- GetStatus("VD832", new Action<object>((objects) =>
- {
- if (objects is int bools)
- {
- ml_morkf.ArmPositionY = bools;
- }
- }), 2);
-
- //获取爪子到达位置
- GetStatus("M11.0", new Action<object>((objects) =>
- {
- if (objects is bool[] bools && bools.Length > 3)
- {
- ml_morkf.PawArrivePortOne = bools[0];
- ml_morkf.PawArrivePortTwo = bools[1];
- ml_morkf.PawArrivePortThree = bools[2];
- }
- }), 2);
-
- //获取总初始化完成
- GetStatus("M10.2", new Action<object>((objects) =>
- {
- if (objects is bool[] bools)
- {
- for (int i = 0; i < 1; i++)
- {
- ml_morkf.InitialComplete = bools[i];
- }
- }
- }), 2);
-
- //抓手初始化完成
- GetStatus("M10.3", new Action<object>((objects) =>
- {
- if (objects is bool[] bools)
- {
- for (int i = 0; i < 1; i++)
- {
- ml_morkf.PawInitialComplete = bools[i];
- }
- }
- }), 2);
-
- }
-
- public override void Stop()
- {
- IsHealth = false;
- }
-
- #region 调试代码
- public void CommandRegist()
- {
- #region 设备控制
- ActionManage.GetInstance.Register(PLCInite, "InitCommand");
- ActionManage.GetInstance.Register(StartOrder, "StartOrder");
- ActionManage.GetInstance.Register(StartOrderMain, "开始下单");
- ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder");
- ActionManage.GetInstance.Register(StopLocalOrder, "StopLocalOrder");
- #endregion
-
- #region 菜品库
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- FoodLibInit();
- }), "FoodLibInit");
- }), "FoodLibInit");
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- Electromagnetism(o);
- }), "Electromagnetism");
- }), "Electromagnetism");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- PawToPoint1();
- }), "PawToPoint1");
- }), "PawToPoint1");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- PawToPoint2();
- }), "PawToPoint2");
- }), "PawToPoint2");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- PawToPoint3();
- }), "PawToPoint3");
- }), "PawToPoint3");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- GetDistance_1();
- }), "GetDistance_1");
- }), "GetDistance_1");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- GetDistance_2();
- }), "GetDistance_2");
- }), "GetDistance_2");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- GetDistance_3();
- }), "GetDistance_3");
- }), "GetDistance_3");
- ActionManage.GetInstance.Register(PawTurnFront, "PawTurnFront");
- ActionManage.GetInstance.Register(PawTurnBack, "PawTurnBack");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- if (list is List<int> list_int)
- {
- if (list_int.Count == 2)
- {
- SetArmPosition(list_int[0], list_int[1]);
- }
- }
- }), "SetArmPosition");
- }), "SetArmPosition");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- if (list is bool startOrStop)
- {
- ArmRunUp(startOrStop);
- }
- }), "ArmRunUp");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- if (list is bool startOrStop)
- {
- ArmRunDown(startOrStop);
- }
- }), "ArmRunDown");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- if (list is bool startOrStop)
- {
- ArmRunLeft(startOrStop);
- }
- }), "ArmRunLeft");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- if (list is bool startOrStop)
- {
- ArmRunRight(startOrStop);
- }
- }), "ArmRunRight");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- if (list is List<int> list_int)
- {
- if (list_int.Count == 2)
- {
- SetNowPosition(list_int[0], list_int[1]);
- }
- }
- }), "SetNowPosition");
- }), "SetNowPosition");
- #endregion
- //ActionManage.GetInstance.Register(PLCInite, "InitCommand");
- #region 配料控制
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- OutSeasoning(o, fryIndex);
- }), "OutMaterials");
- }), "OutMaterials");
- //ActionManage.GetInstance.Register(OutSeasoning, "OutMaterials");
- #endregion
-
- #region 炒锅
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- Plc1Reset(fryIndex);
- }), "Plc1Reset");
- }), "Plc1Reset");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- AddOil();
- }), "AddOil");
- }), "AddOil");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StartFire(fryIndex);
- }), "StartFire");
- }), "StartFire");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StopFire(fryIndex);
- }), "StopFire");
- }), "StopFire");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StartStir(fryIndex);
- }), "StartStir");
- }), "StartStir");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StopStir(fryIndex);
- }), "StopStir");
- }), "StopStir");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- OutFood(fryIndex);
- }), "OutFood");
- }), "OutFood");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StirArmGoOrigin(fryIndex);
- }), "StirArmGoOrigin");
- }), "StirArmGoOrigin");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StirArmGoWork(fryIndex);
- }), "StirArmGoWork");
- }), "StirArmGoWork");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- HBOTGoWork(fryIndex);
- }), "HBOTGoWork");
- }), "HBOTGoWork");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- OutMeal(fryIndex);
- }), "OutMeal");
- }), "OutMeal");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- SetFire(o, fryIndex);
- }), "SetFire");
- }), "SetFire");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- SetFry(o);
- }), "SetFry");
- }), "SetFry");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- SetStir(o, fryIndex);
- }), "SetStir");
- }), "SetStir");
- #endregion
-
-
- }
-
- /// <summary>
- /// 本地菜单下单
- /// </summary>
- private void StartOrder(object o)
- {
- if (o == null) return;
- if (o is int goodId)
- {
- var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程
- if (res != null)
- {
- /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
- if (StirFryGoodsQuenes.Count > 0) return;
- StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- {
- SuborderId = Guid.NewGuid().ToString(),
- StirPotActions = res.StirPotActions,
- GoodName = "本地菜品"
- });
- MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
- }
- }
- }
-
- /// <summary>
- /// 本地菜单下单
- /// </summary>
- private void StartOrderMain(object o)
- {
- if (o == null) return;
- if (o is string goodId)
- {
- var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey.ToString() == goodId);//匹配订单对应制作流程
- if (res != null)
- {
- /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
- if (StirFryGoodsQuenes.Count > 0) return;
- StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- {
- SuborderId = Guid.NewGuid().ToString(),
- StirPotActions = res.StirPotActions,
- GoodName = "本地菜品"
- });
- MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
- }
- }
- }
-
- private void StartLocalOrder()
- {
- if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
- if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
- {
- StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- {
- SuborderId = Guid.NewGuid().ToString(),
- StirPotActions = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions,
- GoodName = "本地菜品"
- });
- MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
- }
- }
-
- /// <summary>
- /// 停止本地菜单炒制
- /// </summary>
- private void StopLocalOrder(int num = -1)
- {
- //判断当前是否有炒制菜品
- if (nowStirFryGood == null) return;
-
- //根据morkFs中是否有num执行不同的停止操作
- if (!morkFs.ContainsKey(num))
- {
- //根据调试界面的当前炒锅编号停止炒制线程
- ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[fryIndex].GoodName), new Action(() => { Plc1Reset(fryIndex); }));
- }
- else
- {
- //根据炒锅编号停止炒制线程
- ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[num].GoodName), new Action(() => { Plc1Reset(num); }));
- }
- }
-
- /// <summary>
- /// 重置程序
- /// </summary>
- public override void ResetProgram()
- {
- IsHealth = true;
- morkFs.Clear();
- morkFs = new Dictionary<int, GVL_MorkF>();
- ml_morkf = new ML_MorkF();
-
- //根据编号new炒锅实例对象
- for (int i = 0; i < count; i++)
- {
- morkFs.Add(i, new GVL_MorkF());
- }
- }
-
- #endregion
-
- #region 公用PLC方法
- /// <summary>
- /// 获取设备PLC的所有状态
- /// </summary>
- /// <param name="key"></param>
- /// <param name="action"></param>
- /// <param name="num">炒锅编号</param>
- private void GetStatus(string key, Action<object> action, int num)
- {
- if (dicPort2peripheralStatus.ContainsKey(num))
- {
- if (dicPort2peripheralStatus[num].ContainsKey(key))
- {
- action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值
- }
- }
- }
-
- /// <summary>
- /// PLC数据读取
- /// </summary>
- public override void ReadData()
- {
-
- for (int i = 0; i < morkFs.Count; i++)
- {
- GetStatus("LB50", new Action<object>((objects) =>
- {
- if (!morkFs.ContainsKey(i))
- {
- return;
- }
- if (objects is bool[] bools)
- {
- morkFs[i].FryPot1_InitialComplete = bools[0];
- morkFs[i].FryPot1_HOBTPut = bools[1];
- morkFs[i].FryPot1_HOBTGet = bools[2];
- morkFs[i].FryPot1_MaterialIntoPot = bools[3];
- morkFs[i].OutFoodCompelete = bools[4];
- morkFs[i].CanOutFood = bools[5];
- morkFs[i].GetFoodCompelete = bools[6];
- morkFs[i].CanOutPotWashingWater = bools[7];
- morkFs[i].ArmOnOrigin = bools[8];
- morkFs[i].ArmOnWorking = bools[9];
- morkFs[i].PotOnOrigin = bools[10];
- }
-
- }), i);
- }
- for (int j = 0; j < morkFs.Count; j++)
- {
- GetStatus("LB74", new Action<object>((objects) =>
- {
- if (!morkFs.ContainsKey(j))
- {
- return;
- }
-
- if (objects is bool[] bools)
- {
- for (int i = 0; i < 14; i++)
- {
- morkFs[j].PassWay1_Compelete[i] = bools[i];
- }
- }
-
- }), j);
- }
- for (int i = 0; i < morkFs.Count; i++)
- {
- if (!morkFs.ContainsKey(i))
- {
- return;
- }
-
- GetStatus("LB90", new Action<object>((objects) =>
- {
- if (objects is bool[] bools)
- {
- morkFs[i].AutoMode = bools[0];
- }
-
- }), i);
- }
-
- }
-
- #endregion
-
- #region 菜品库PLC操作方法
- /// <summary>
- /// 菜品库数据写入
- /// </summary>
- /// <param name="address"></param>
- /// <param name="value"></param>
- private void MaterailLibrary_Write(string address, object value, int num = 2)
- {
- WriteControlExact(address, value, num);
- }
- /// <summary>
- /// 菜品库初始化
- /// </summary>
- public bool FoodLibInit()
- {
- MaterailLibrary_Write("M0.2", true);
-
- Thread.Sleep(500);
-
- for (int i = 0; i < materialSleepCount && !ml_morkf.InitialComplete; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show("菜品库初始化超时");
- return false;
- }
- }
-
- return true;
- }
- /// <summary>
- /// 电磁阀启停
- /// </summary>
- /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
- public void Electromagnetism(object o)
- {
- if (!ml_morkf.InitialComplete)
- {
- return;
- }
-
- if (o == null) return;
- if (o is List<bool> bs && bs.Count == 1)
- {
- MaterailLibrary_Write("M1.3", bs[0]);
- }
- }
-
- public bool PawToPoint1()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MessageLog.GetInstance.Show("爪子去到1号位");
- MaterailLibrary_Write("M1.0", true);
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortOne; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show("爪子去到1号位超时");
- return false;
- }
- }
-
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("爪子去到1号位完成");
- return true;
- }
-
- public bool PawToPoint2()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MessageLog.GetInstance.Show("爪子去到2号位");
- MaterailLibrary_Write("M1.1", true);
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortTwo; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show("爪子去到2号位超时");
- return false;
- }
- }
-
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("爪子去到2号位完成");
- return true;
- }
-
- public bool PawToPoint3()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MessageLog.GetInstance.Show("爪子去到3号位");
- MaterailLibrary_Write("M1.2", true);
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortThree; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show("爪子去到3号位超时");
- return false;
- }
- }
-
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("爪子去到3号位完成");
- return true;
- }
-
- public bool GetDistance_1()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MaterailLibrary_Write("M0.3", true);
- MaterailLibrary_Write("M0.3", false);
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("1号测距开启完成");
- return true;
- }
- public bool GetDistance_2()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MaterailLibrary_Write("M0.4", true);
- MaterailLibrary_Write("M0.4", false);
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("2号测距开启完成");
- return true;
- }
- public bool GetDistance_3()
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- MaterailLibrary_Write("M0.5", true);
- MaterailLibrary_Write("M0.5", false);
- Thread.Sleep(300);
-
- MessageLog.GetInstance.Show("3号测距开启完成");
- return true;
- }
-
- /// <summary>
- /// 根据x坐标获取传感器距离
- /// </summary>
- /// <param name="x"></param>
- /// <returns></returns>
- public bool GetDistance(int x)
- {
- bool ret = true;
- //是否在第一层菜品库
- if (x > 0 && x <= materialLaserHigh)
- {
- //获取传感器1的距离
- ret &= GetDistance_1();
-
- Thread.Sleep(400);
-
- //获取传感器1的距离
- ret &= GetDistance_1();
- }
- //是否在第二层菜品库
- else if (x > materialLaserHigh && x <= (2 * materialLaserHigh + clapboardLaserHigh))
- {
- //获取传感器2的距离
- ret &= GetDistance_2();
-
- Thread.Sleep(400);
-
- ret &= GetDistance_2();
- }
- //是否在第三层菜品库
- else if (x > (2 * materialLaserHigh + clapboardLaserHigh) && x <= (3 * materialLaserHigh + 2 * clapboardLaserHigh))
- {
- //获取传感器3的距离
- ret &= GetDistance_3();
-
- Thread.Sleep(400);
-
- ret &= GetDistance_3();
- }
- if (!ret)
- {
- MessageLog.GetInstance.Show($"错误:X轴:{x}获取传感器数据出错");
- }
- return ret;
- }
-
- public void PawTurnFront()
- {
- MaterailLibrary_Write("", true);
- }
- public void PawTurnBack()
- {
- MaterailLibrary_Write("", true);
- }
-
- /// <summary>
- /// 设定机械臂的位置
- /// </summary>
- /// <param name="x"></param>
- /// <param name="y"></param>
- public bool SetArmPosition(int x, int y)
- {
- if (!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- //取反
- x -= 2 * x;
- y -= 2 * y;
- if (x > 0 || y > 0)
- {
- MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]非法");
- return false;
- }
- MaterailLibrary_Write("VD836", x);
- Thread.Sleep(100);
- MaterailLibrary_Write("VD840", y);
-
- Thread.Sleep(200);
-
- MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]");
-
- //到达置为false
- ml_morkf.ArriveComplete = false;
-
- //定位启动
- MaterailLibrary_Write("M0.0", true);
-
- Thread.Sleep(400);
-
- for (int i = 0; i < materialSleepCount && (!ml_morkf.ArriveComplete); i++)
- {
- Thread.Sleep(materialSleepTime);
- //若是目标点与当前坐标一致,跳出循环
- if((ml_morkf.ArmPositionX == x && ml_morkf.ArmPositionY == y))
- {
- MessageLog.GetInstance.Show($"机械臂已移动到[{ml_morkf.ArmPositionX},{ml_morkf.ArmPositionY}]");
- break;
- }
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show("机械臂移动操作超时");
- return false;
- }
- }
-
- MessageLog.GetInstance.Show("机械臂移动操作完成");
-
- Thread.Sleep(500);
-
- return true;
- }
-
- /// <summary>
- /// 设定机械臂的当前坐标
- /// </summary>
- /// <param name="x"></param>
- /// <param name="y"></param>
- public void SetNowPosition(int x, int y)
- {
- //取反
- x -= 2 * x;
- y -= 2 * y;
- MessageLog.GetInstance.Show($"设置机械臂当前坐标为[{x},{y}]");
- MaterailLibrary_Write("VD828", x);
- Thread.Sleep(200);
- MaterailLibrary_Write("VD832", y);
- Thread.Sleep(200);
- }
-
- /// <summary>
- /// 机械臂向上移动开关
- /// </summary>
- /// <param name="startOrStop">true:开启,false:关闭</param>
- public void ArmRunUp(bool startOrStop)
- {
- MaterailLibrary_Write("M5.3", startOrStop);
- Thread.Sleep(200);
- }
-
- /// <summary>
- /// 机械臂向下移动开关
- /// </summary>
- /// <param name="startOrStop">true:开启,false:关闭</param>
- public void ArmRunDown(bool startOrStop)
- {
- MaterailLibrary_Write("M5.4", startOrStop);
- Thread.Sleep(200);
- }
-
- /// <summary>
- /// 机械臂向左移动开关
- /// </summary>
- /// <param name="startOrStop">true:开启,false:关闭</param>
- public void ArmRunLeft(bool startOrStop)
- {
- MaterailLibrary_Write("M5.5", startOrStop);
- Thread.Sleep(200);
- }
-
- /// <summary>
- /// 机械臂向右移动开关
- /// </summary>
- /// <param name="startOrStop">true:开启,false:关闭</param>
- public void ArmRunRight(bool startOrStop)
- {
- MaterailLibrary_Write("M5.6", startOrStop);
- Thread.Sleep(200);
- }
-
- //菜品库锁
- object lock_Materail = new object();
-
- /// <summary>
- /// 取菜操作
- /// </summary>
- /// <param name="x">取菜x轴坐标</param>
- /// <param name="y">取菜y轴坐标</param>
- /// <param name="fryNum">炒锅编号</param>
- public bool GetMaterail(int x, int y, int fryNum)
- {
- //设置到抓菜处
- if (!SetArmPosition(x, y))
- {
- return false;
- }
-
- if (!GetDistance(x))
- {
- MessageLog.GetInstance.Show("错误:获取传感器数据出错");
- return false;
- }
-
- Thread.Sleep(1000);
-
- //获取传感器的距离,转换成坐标系的点
- int laserHigh = ml_morkf.LaserDistance;
-
- MessageLog.GetInstance.Show($"传感器的距离{laserHigh}");
-
- if (laserHigh > 29)
- {
- MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离");
- return false;
- }
-
- int moveX = 0;
- if (LaserDistance2Coordinate(laserHigh, out moveX) != Laser2CoordinateState.MaterialNormal)
- {
- MessageLog.GetInstance.Show("错误:传感器距离转坐标值失败");
- return false;
- }
-
- if(x < moveX)
- {
- MessageLog.GetInstance.Show("错误:传感器距离转坐标值大于当前x轴坐标");
- return false;
- }
-
- //设置到传感器感应的距离处
- if (!SetArmPosition(x - moveX, y))
- {
- return false;
- }
-
- ////关闭电磁阀
- //Electromagnetism(new List<bool> { true });
- //Thread.Sleep(500);
-
- #if true
- //爪子去1号位抓菜
- if (!PawToPoint1())
- {
- return false;
- }
- #endif
-
- //设置到该层菜品库最高处
- if (!SetArmPosition(x - materialHigh, y))
- {
- return false;
- }
-
- ////移动前开启电磁阀
- //Electromagnetism(new List<bool> { false });
- //Thread.Sleep(500);
-
- #if true
- //爪子去2号位放菜
- if (!PawToPoint2())
- {
- return false;
- }
- #endif
- ////判断炒锅是否可以放盒
- //for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++)
- //{
- // Thread.Sleep(materialSleepTime);
- // if (i >= materialSleepCount - 1)
- // {
- // MessageLog.GetInstance.Show("等待炒锅允许放盒超时");
- // return;
- // }
- //}
-
- //关闭启磁吸
- MagnetOff(fryNum);
-
- Thread.Sleep(200);
-
- //根据炒锅不同设置不同的出菜处
- if (fryNum % 2 == 0)
- {
- x = materialPutPositionXFry1;
- y = materialPutPositionYFry1;
- }
- else
- {
- x = materialPutPositionXFry2;
- y = materialPutPositionYFry2;
- }
-
- //设置到炒锅1出菜处
- if (!SetArmPosition(x, y))
- {
- return false;
- }
-
- #if true
- //爪子去3号位放菜
- if (!PawToPoint3())
- {
- return false;
- }
- #endif
-
- //开启磁吸
- MagnetOn(fryNum);
-
- Thread.Sleep(200);
-
- //设置到炒锅1出菜处
- if (!SetArmPosition(x + materialToFryDistance, y))
- {
- return false;
- }
-
- #if true
- //爪子回到2号位
- if (!PawToPoint2())
- {
- return false;
- }
- #endif
- ////关闭电磁阀
- //Electromagnetism(new List<bool> { false });
- //Thread.Sleep(300);
- if (morkFs.ContainsKey(fryNum))
- {
- morkFs[fryNum].GetMaterialComplete = true;
- }
- return true;
- }
-
- /// <summary>
- /// 更新菜品库存量
- /// </summary>
- /// <returns></returns>
- public bool UpdateMaterialLibraryStock()
- {
- try
- {
- //判断是否初始化
- if(!ml_morkf.InitialComplete)
- {
- return false;
- }
-
- foreach(var item in MaterialCoordinate.dicNoMaterialCoordinate)
- {
- //设置到抓菜处
- if (!SetArmPosition(item.Value.X, item.Value.Y))
- {
- return false;
- }
-
- //获取该处的距离
- if (!GetDistance(item.Value.X))
- {
- MessageLog.GetInstance.Show("错误:获取传感器数据出错");
- return false;
- }
-
- Thread.Sleep(1000);
-
- //获取传感器的距离
- int laserHigh = ml_morkf.LaserDistance;
- int surplus = 0;
- //根据距离算出菜品余量
- Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, out surplus);
- if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty)
- {
- return false;
- }
-
- //更新菜品余量
- if (!MaterialSurplusOperation.GetInstance().UpdateSurplus(item.Key, surplus))
- {
- return false;
- }
- }
- return true;
- }
- catch(Exception ex)
- {
- return false;
- }
- }
-
- /// <summary>
- /// 传感器距离转为x轴坐标系
- /// </summary>
- /// <param name="distance"></param>
- /// <param name="x"></param>
- /// <returns></returns>
- public Laser2CoordinateState LaserDistance2Coordinate(int distance,out int x)
- {
- x = 0;
- try
- {
- //菜盒放多了
- if (distance<6)
- {
- return Laser2CoordinateState.MaterialOverdo;
- }
- else if (distance >= 6 && distance < 10)
- {
- x = 24882;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if(distance>=10 && distance < 14)
- {
- x = 18661;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if(distance >= 14 && distance < 19)
- {
- x = 12441;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 19 && distance < 23)
- {
- x = 6220;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 23 && distance < 28)
- {
- x = 0;
- return Laser2CoordinateState.MaterialNormal;
- }
- else
- {
- return Laser2CoordinateState.MaterialEmpty;
- }
- }
- catch(Exception ex)
- {
- return Laser2CoordinateState.MaterialUnkown;
- }
- }
-
- /// <summary>
- /// 传感器距离转为菜品数量
- /// </summary>
- /// <param name="distance"></param>
- /// <param name="x"></param>
- /// <returns></returns>
- public Laser2CoordinateState LaserDistance2MaterialCount(int distance, out int count)
- {
- count = 0;
- try
- {
- //菜盒放多了
- if (distance < 6)
- {
- return Laser2CoordinateState.MaterialOverdo;
- }
- else if (distance >= 6 && distance < 10)
- {
- count = 5;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 10 && distance < 14)
- {
- count = 4;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 14 && distance < 19)
- {
- count = 3;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 19 && distance < 23)
- {
- count = 2;
- return Laser2CoordinateState.MaterialNormal;
- }
- else if (distance >= 23 && distance < 28)
- {
- count = 1;
- return Laser2CoordinateState.MaterialNormal;
- }
- else
- {
- count = 0;
- return Laser2CoordinateState.MaterialEmpty;
- }
- }
- catch (Exception ex)
- {
- return Laser2CoordinateState.MaterialUnkown;
- }
- }
-
- /// <summary>
- /// 获取菜品测试
- /// </summary>
- /// <param name="isGet"></param>
- private void GetMaterailTest(MaterialOperation materialOperation)
- {
- ThreadManage.GetInstance().Start(new Action(() => {
- bool ret = false;
- try
- {
- Coordinate myCoordinate = new Coordinate();
- //获取坐标,根据菜品的位置信息
- if (!NoMaterial2Coordinate(materialOperation.materialInfo.Loc, out myCoordinate))
- {
- MessageLog.GetInstance.Show($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置");
- return;
- }
- lock (lock_Materail)
- {
- ml_morkf.MaterailIsWorking = true;
- }
- //取菜操作
- ret =GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum);
- }
- catch (Exception ex)
- {
- ret = false;
- }
- finally
- {
- lock (lock_Materail)
- {
- ml_morkf.MaterailIsWorking = false;
- }
- if (ret == true)
- {
- //指定位置菜品减一
- MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
- }
- }
-
- }), $"菜品库操作");
- }
- #endregion
-
- #region 炒锅PLC基本操作方法
- /// <summary>
- /// 炒锅写寄存器方法,num为炒锅对应编号,从0开始
- /// </summary>
- /// <param name="address">寄存器地址</param>
- /// <param name="value">值</param>
- /// <param name="num">炒锅编号</param>
- private void FirePot_Write(string address, object value, int num)
- {
- WriteControlExact(address, value, num);
- }
-
- /// <summary>
- /// 出调料
- /// </summary>
- /// <param name="o"></param>
- public void OutSeasoning(object o, int num)
- {
- if (o == null) return;
- if (o is List<int> ints && ints.Count == 2 && morkFs.ContainsKey(num))
- {
- FirePot_Write(morkFs[num].PassWayValue[ints[0]], (ushort)ints[1], num);//写入通道值
- Thread.Sleep(400);
- FirePot_Write(morkFs[num].StartPassWay[ints[0]], true, num);//开启通道
- Thread.Sleep(400);
- FirePot_Write(morkFs[num].StartPassWay[ints[0]], false, num);//开启通道
- }
- }
-
- /// <summary>
- /// 出多个调料
- /// </summary>
- public void OutSeasonings(List<SeasoningList> seasoningLists, int num)
- {
- //防止越界
- if (!morkFs.ContainsKey(num))
- {
- return;
- }
-
- foreach (SeasoningList seasoning in seasoningLists)
- {
- FirePot_Write(morkFs[num].PassWayValue[seasoning.Loc], (ushort)seasoning.Qty, num);
- Thread.Sleep(300);
- }
- foreach (SeasoningList seasoning in seasoningLists)
- {
- FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], true, num);
- Thread.Sleep(300);
- }
- foreach (SeasoningList seasoning in seasoningLists)
- {
- FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
- Thread.Sleep(300);
- }
-
- foreach (SeasoningList seasoning in seasoningLists)
- {
- FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
- Thread.Sleep(300);
- }
- }
-
- /// <summary>
- /// 复位
- /// </summary>
- public void Plc1Reset(int num)
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- StopFire(num);
- Thread.Sleep(200);
- StopStir(num);
- Thread.Sleep(200);
- FirePot_Write("LB5", false, num);
- Thread.Sleep(200);
- FirePot_Write("LB3", false, num);
- Thread.Sleep(200);
- FirePot_Write("LB6", false, num);
- Thread.Sleep(200);
- FirePot_Write("LB7", false, num);
- Thread.Sleep(200);
- FirePot_Write("LB4", false, num);
- Thread.Sleep(200);
- FirePot_Write("LB53", false, num);
- if (morkFs.ContainsKey(num))
- {
- foreach (var item in morkFs[num].StartPassWay.Values)
- {
- Thread.Sleep(200);
- FirePot_Write(item, false, num);
- }
- }
- }), "炒锅1初始化");
-
- }
-
- /// <summary>
- /// 炒锅初始化
- /// </summary>
- public void PLCInite()
- {
- for (int i = 0; i < morkFs.Count; i++)
- {
- FirePot_Write("LB0", true, i);
-
- for (int j = 0; j < sleepCount && !morkFs[i].FryPot1_InitialComplete; j++)
- {
- Thread.Sleep(sleepTime);
- if (j >= sleepCount - 1)
- {
- MessageLog.GetInstance.Show($"炒锅{j}初始化超时");
- }
- }
-
- //while (!morkFs[i].FryPot1_InitialComplete)
- //{
- // Thread.Sleep(500);
- //}
- FirePot_Write("LB0", false, i);
- }
- }
-
- //加油
- public void AddOil()
- {
-
- }
- //加热启动
- public void StartFire(int num)
- {
- FirePot_Write("LB1", true, num);
- Thread.Sleep(200);
- }
- //加热停止
- public void StopFire(int num)
- {
- FirePot_Write("LB1", false, num);
- Thread.Sleep(200);
- }
- //搅拌启动
- public void StartStir(int num)
- {
- FirePot_Write("LB2", true, num);
- Thread.Sleep(200);
- }
- //搅拌启停止
- public void StopStir(int num)
- {
- FirePot_Write("LB2", false, num);
- Thread.Sleep(200);
- }
- //倒菜
- public void OutFood(int num,bool isMaterial = false)
- {
- if (!morkFs.ContainsKey(num))
- {
- return;
- }
- int i = 0;
-
- if(isMaterial)
- {
- //判断是否完成取菜
- for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++)
- {
- if (i == 10)
- {
- //停止搅拌
- StopStir(num);
- //火力设置为2档
- SetFire(new List<int> { 2 }, num);
- }
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成");
- return;
- }
- }
-
- if (i > 9)
- {
- //开启搅拌
- StartStir(num);
- //火力设置回原本火力
- SetFire(new List<int> { morkFs[num].Fire }, num);
- }
- }
-
- FirePot_Write("LB3", true, num);
- MessageLog.GetInstance.Show("倒菜启动");
-
- Thread.Sleep(500);
-
- for (i = 0; i < materialSleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.Show($"炒锅{num}倒菜超时");
- }
- }
-
- FirePot_Write("LB3", false, num);
- Thread.Sleep(200);
- MessageLog.GetInstance.Show("倒菜完成");
- morkFs[num].GetMaterialComplete = false;
- }
- //搅拌臂去原点位
- public void StirArmGoOrigin(int num)
- {
- if (!morkFs.ContainsKey(num))
- {
- return;
- }
-
- FirePot_Write("LB5", true, num);
- MessageLog.GetInstance.Show("搅拌臂去原点位");
-
- for (int i = 0; i < sleepCount && !morkFs[num].ArmOnOrigin; i++)
- {
- Thread.Sleep(sleepTime);
- if (i >= sleepCount - 1)
- {
- MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去原点位超时");
- }
- }
-
- FirePot_Write("LB5", false, num);
- Thread.Sleep(200);
- MessageLog.GetInstance.Show("搅拌臂到达原点位");
- }
-
- //搅拌臂去炒制位
- public void StirArmGoWork(int num)
- {
- if (!morkFs.ContainsKey(num))
- {
- return;
- }
-
- if (!morkFs[num].ArmOnWorking/* && morkFs[num].PotOnOrigin*/)
- {
- FirePot_Write("LB6", true, num);
- MessageLog.GetInstance.Show("搅拌臂去工作位");
-
- for (int i = 0; i < sleepCount && !morkFs[num].ArmOnWorking; i++)
- {
- Thread.Sleep(sleepTime);
- if (i >= sleepCount - 1)
- {
- MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去炒制位超时");
- }
- }
-
- //while (!morkFs[num].ArmOnWorking)
- //{
- // Thread.Sleep(200);
- //}
-
- FirePot_Write("LB6", false, num);
- Thread.Sleep(200);
- MessageLog.GetInstance.Show("搅拌臂到达工作位");
- }
-
- }
- //HBOT放盒子到位
- public void HBOTGoWork(int num)
- {
- FirePot_Write("LB7", true, num);
- Thread.Sleep(400);
- FirePot_Write("LB7", false, num);
- }
- //出餐启动
- public void OutMeal(int num)
- {
- if (!morkFs[num].ArmOnOrigin /*&& morkFs[num].PotOnOrigin*/)
- {
- MessageLog.GetInstance.Show("搅拌臂不在原点位,无法完成出餐");
- return;
- }
- FirePot_Write("LB4", true, num);
- Thread.Sleep(200);
- FirePot_Write("LB4", false, num);
- }
- //加热挡位设定
- public void SetFire(object o, int num)
- {
- if (o == null) return;
- if (o is List<int> ints && ints.Count == 1)
- {
- FirePot_Write("LW14", (ushort)ints[0], num);
- Thread.Sleep(200);
-
- }
-
- }
-
- public void SetFry(object o)
- {
- if (o == null) return;
- if (o is List<int> ints && ints.Count == 1)
- {
- fryIndex = ints[0] - 1;
- }
- }
-
- /// <summary>
- /// 搅拌挡位设定
- /// </summary>
- /// <param name="o"></param>
- public void SetStir(object o, int num)
- {
- if (o == null) return;
- if (o is List<int> ints && ints.Count == 1)
- {
- FirePot_Write("LW15", (ushort)ints[0], num);
- Thread.Sleep(200);
-
- }
- }
-
- public void MagnetOn(int num)
- {
- FirePot_Write("LB8", false, num);
- Thread.Sleep(200);
- }
-
- public void MagnetOff(int num)
- {
- FirePot_Write("LB8", true, num);
- Thread.Sleep(200);
- }
- #endregion
-
- private static object saveMaterialLock = new object();
- private void SaveMaterialData()
- {
- lock(saveMaterialLock)
- {
- Json<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
- Json<MaterialSurplus>.Save();
- }
- }
-
- bool isInitialArrive = false;
-
- bool isInitialPaw = false;
-
- #region 联网交互
- 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;
-
- }
- });
-
- //配方数据信息
- EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is RecipeBomEvent recipe)
- {
- recipeBoms = recipe.recipeBoms;
- }
- });
- //小炒流程信息
- EventBus.EventBus.GetInstance().Subscribe<StirFryGoodsEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callback)
- {
- if (@event == null) return;
- if (@event is StirFryGoodsEvent stirFry)
- {
- if(stirFry.stirFrymessage != null)
- {
- if (stirFry.stirFrymessage.stirFryGoods.Count > 0)
- {
- foreach (var item in stirFry.stirFrymessage.stirFryGoods)
- {
- LocalstirFryGoods.Add(new StirFryGoods
- {
- GoodsKey = item.GoodsKey,
- StirPotActions = OrderSort(item.StirPotActions),
- });
- GlobalFoodMenu.LocalFoodMenus.Add(new FoodMenuModel
- {
- GoodKey = item.GoodsKey.ToString(),
- GoodName = "",
- });
- }
- }
- if(stirFry.stirFrymessage.materials.Count > 0)
- {
- MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials);
- //foreach (var item in stirFry.stirFrymessage.materials)
- //{
- // MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Add(new MaterialInfo
- // {
- // Id = item.Id,
- // Key = item.Key,
- // Name = item.Name,
- // Loc = item.Loc,
- // Qty = item.Qty,
- // });
- //}
- SaveMaterialData();
- }
- }
-
- MessageLog.GetInstance.Show("接收到小炒流程信息");
- //流程解析
- foreach (var item in LocalstirFryGoods)
- {
- MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}");
- // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程
- string MenuStep = "菜单步骤:";
- foreach (var items in item.StirPotActions)
- {
- switch (items.Actions)
- {
- case nameof(StirFryPotActionEnum.加热开启):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位1):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位2):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位3):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位4):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位5):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位6):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位7):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位8):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位9):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位10):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.停止加热):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.加调料):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.取原料):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.开启搅拌):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位1):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位2):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位3):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.关闭搅拌):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.出餐启动):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.道菜启动):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.炒制菜品):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.搅拌臂原点位):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.搅拌臂炒制位):
- MenuStep += items.Actions + ",";
- break;
- case nameof(StirFryPotActionEnum.洗锅):
- MenuStep += items.Actions + ",";
- break;
- default:
- break;
-
- }
-
-
- }
- MessageLog.GetInstance.Show(MenuStep);
-
-
-
- }
- }
- });
- }
-
- /// <summary>
- /// 订单排序
- /// </summary>
- /// <param name="potActions"></param>
- /// <returns></returns>
- private List<PotActions> OrderSort(List<PotActions> potActions)
- {
- if (potActions.Count > 1)
- {
- potActions.Sort(
- delegate (PotActions st1, PotActions st2)
- {
- //降序排列
- //return st2.FryTime.CompareTo(st1.FryTime);
-
- //升序版(颠倒 st1 和 st2 即可)
- return st1.FryTime.CompareTo(st2.FryTime);
-
- });
- }
- return potActions;
- }
-
- /// <summary>
- /// 订单状态发布
- /// </summary>
- /// <param name="subid"></param>
- /// <param name="oRDER_STATUS"></param>
- private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
- {
- EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
- }
-
- /// <summary>
- /// 数据解析
- /// </summary>
- private void DataParse()
- {
- //if (!morkFs.ContainsKey(num))
- //{
- // return;
- //}
-
- 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}次订单");
- Enum.GetNames(typeof(StirFryPotActionEnum));
-
- //var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.RecipeId);//匹配订单对应制作流程
- if(order.MorkOrder.GoodBatchings.Count <= 0)
- {
- return;
- }
-
- if(order.MorkOrder.DeviceId != DeviceId)
- {
- return;
- }
-
- //var res = LocalstirFryGoods[0];
- //if (res != null)
- //{
- // /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
- // //添加到带炒小炒队列
- // if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- // {
- // lock (lock_MainProcessExcute)
- // {
- // StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- // {
- // SuborderId = order.MorkOrder.SuborderId,
- // StirPotActions = res.StirPotActions,
- // GoodName = order.MorkOrder.GoodsName
- // });
- // }
- // }
- //}
-
- //暂时使用本地菜单
- StartLocalOrder();
- }
-
- });
- }
- #endregion
-
- private object lock_MainProcessExcute = new object();
-
- /// <summary>
- /// 炒锅主流程
- /// </summary>
- private void MainProcessExcute()
- {
- //判断是否有订单信息
- if(StirFryGoodsQuenes.Count > 0)
- {
- //遍历炒锅,找到合适、空闲的炒锅
- for(int i = 0;i<morkFs.Count;i++)
- {
- if (/*morkFs[i].AutoMode && morkFs[i].FryPot1_InitialComplete &&*/
- !morkFs[i].FryWorking)//炒锅在自动状态&&初始化完成&&是否在炒菜中
- {
- lock(lock_MainProcessExcute)
- {
- //待炒小炒队列出队列
- if (StirFryGoodsQuenes.TryDequeue(out var res))
- {
- //设置当前炒制菜品
- nowStirFryGood[i] = res;
- //炒锅工作状态置为正在工作中
- morkFs[i].FryWorking = true;
- //空闲炒锅入队列
- morkFs[i].StirFryGoodsQuenes.Enqueue(res);
- //炒锅取菜状态置为未取到
- morkFs[i].GetMaterialComplete = false;
- //开启线程进行炒制
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- try
- {
- MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}");
-
- Coordinate myCoordinate = new Coordinate();
- int getMaterailNum = 0;
- foreach (var potActions in res.StirPotActions)
- {
- if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)))
- {
- return;
- }
-
- switch (potActions.Actions)
- {
- case nameof(StirFryPotActionEnum.加热开启):
- StartFire(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位1):
- morkFs[i].Fire = 1;
- SetFire(new List<int> { 1 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位2):
- morkFs[i].Fire = 2;
- SetFire(new List<int> { 2 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位3):
- morkFs[i].Fire = 3;
- SetFire(new List<int> { 3 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位4):
- morkFs[i].Fire = 4;
- SetFire(new List<int> { 4 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位5):
- morkFs[i].Fire = 5;
- SetFire(new List<int> { 5 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位6):
- morkFs[i].Fire = 6;
- SetFire(new List<int> { 6 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位7):
- morkFs[i].Fire = 7;
- SetFire(new List<int> { 7 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位8):
- morkFs[i].Fire = 8;
- SetFire(new List<int> { 8 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位9):
- morkFs[i].Fire = 9;
- SetFire(new List<int> { 9 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置加热挡位10):
- morkFs[i].Fire = 10;
- SetFire(new List<int> { 10 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.停止加热):
- StopFire(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.加调料):
- OutSeasonings(potActions.SeasoningLists, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.取原料):
- //炒锅取菜状态置为未取到
- morkFs[i].GetMaterialComplete = false;
- if(potActions.MaterialLists != null)
- {
- foreach (var item in potActions.MaterialLists)
- {
- //通过ID获取有效的菜品对象
- MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().GetVailedMaterial(item.MaterialId);
- if (materialInfo == null)
- {
- MessageLog.GetInstance.Show($"炒锅{i}获取菜品[{materialInfo.Name}]失败,库存不足");
- continue;
- }
-
- materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
- }
- }
- else
- {
- MessageLog.GetInstance.Show($"炒锅{i}获取菜品失败,菜品列表为空");
- }
- //if(getMaterailNum == 0)
- //{
- // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[1], out myCoordinate))
- // {
- // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
- // getMaterailNum++;
- // }
- //}
- //else if(getMaterailNum == 1)
- //{
- // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[4], out myCoordinate))
- // {
- // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
- // getMaterailNum++;
- // }
- //}
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.开启搅拌):
- StartStir(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位1):
- SetStir(new List<int> { 1 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位2):
- SetStir(new List<int> { 2 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.设置搅拌挡位3):
- SetStir(new List<int> { 3 }, i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.关闭搅拌):
- StopStir(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.出餐启动):
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.道菜启动):
- OutFood(i, true);
- break;
- case nameof(StirFryPotActionEnum.炒制菜品):
- Thread.Sleep(potActions.During * 1000);
- break;
- case nameof(StirFryPotActionEnum.搅拌臂原点位):
- StirArmGoOrigin(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.搅拌臂炒制位):
- StirArmGoWork(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.洗锅):
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- default:
- break;
-
- }
- }
-
- Plc1Reset(i);//复位
- Thread.Sleep(3000);
- //回原点位
- StirArmGoOrigin(i);
-
- MessageLog.GetInstance.Show($"菜品{res.GoodName}完成");
-
-
- }
- catch (Exception ex)
- {
- ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程");
- MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message);
- }
- finally
- {
- nowStirFryGood[i] = null;
- //炒完后出队列
- morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
- morkFs[i].FryWorking = false;
- }
- }), String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/);
- }
- }
- break;
- }
- }
- }
- }
-
- /// <summary>
- /// 菜品库主流程
- /// </summary>
- private void MainProcessMaterial()
- {
- if(materialOperationQuenes.Count > 0)
- {
- //判断是否初始化与是否在工作中
- if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking)
- {
- //待菜品库操作列出队列
- if (materialOperationQuenes.TryDequeue(out var res))
- {
-
- ml_morkf.MaterailIsWorking = true;
- MessageLog.GetInstance.Show("开始操作菜品库");
- //ThreadManage.GetInstance().Start(new Action(()=>{
- // GetMaterail(res.x, res.y, res.fryNum);
- //}),"菜品库操作");
- GetMaterailTest(res);
- }
- }
- }
- }
-
- /// <summary>
- /// 信号处理
- /// </summary>
- private void SingleProcess()
- {
-
- }
-
-
- private void ScreenDataServer()
- {
- LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- List<StatsModel> statsModels = new List<StatsModel>();
- statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 });
- ScreenModelMinWok maxWok = new ScreenModelMinWok
- {
- IsRun = new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, //设备是否运行
- WorkStatus_1 = (WorkStatus)new Random().Next(0, 3), //设备运行状态
- WorkStatus_2 = (WorkStatus)new Random().Next(0, 3), //设备运行状态
- RobotStatu = (WorkStatus)new Random().Next(0, 3), //机器人状态 待机 1 正常
- Alarm = new List<AlarmModel>(), //告警集合
- FailuresCount = 0, //故障数
- StatsCount = statsModels, //统计菜品数量
- MinWok_Dishes_1 = "满汉全席",//当前炒制菜品名
- MinWok_Dishes_2 = "海鲜大餐",
- MinWok_Task_1 = "炒制菜品",//当前任务
- MinWok_Task_2 = "热油", //当前任务
- MinWok_Process_1 = new List<ProcessModel>(), //炒锅当前任务流程
- MinWok_Process_2 = new List<ProcessModel>(), //炒锅当前任务流程
- MinWok_HeatGear_1 = new Random().Next(0, 5).ToString(), //炒锅加热档位
- MinWok_HeatGear_2 = new Random().Next(0, 5).ToString(), //炒锅加热档位
- MinWok_StirGear_1 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位
- MinWok_StirGear_2 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位
- MinWok_OrderCount_1 = 2, //订单数量
- MinWok_OrderCount_2 = 2, //订单数量
- MinWok_ErrorOrderCount_1 = 0, //异常订单数量
- MinWok_ErrorOrderCount_2 = 0, //异常订单数量
-
- };
- LocalMqtt.GetInstance.Publish(maxWok);
- Thread.Sleep(1000);
-
- }), "大屏数据上报");
-
- }
-
- public override void SimOrder()
- {
-
- }
-
- /// <summary>
- /// 菜品编号转换为坐标
- /// </summary>
- /// <param name="no"></param>
- /// <param name="coordinate"></param>
- /// <returns></returns>
- public bool NoMaterial2Coordinate(string no,out Coordinate coordinate)
- {
- //默认返回0,0
- coordinate = new Coordinate();
- coordinate.X = 0;
- coordinate.Y = 0;
-
- try
- {
- if(MaterialCoordinate.dicNoMaterialCoordinate.ContainsKey(no))
- {
- coordinate = MaterialCoordinate.dicNoMaterialCoordinate[no];
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- finally
- {
-
- }
- }
-
- public enum Laser2CoordinateState
- {
- MaterialOverdo = 0,//菜品过量
- MaterialNormal = 1,//菜品正常
- MaterialEmpty = 2,//菜品为空
- MaterialUnkown = 999,//菜品未知错误
- }
- }
- }
|