|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028 |
- using BPA.Message;
- using System;
- 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;
- using Microsoft.CodeAnalysis;
- using BPASmartClient.MorkF.ViewModel;
- using BPASmartClient.ViewModel;
- using System.Windows;
-
- namespace BPASmartClient.MorkF
- {
- public class Control_MorkF : BaseDevice
- {
- #region 常数定义
- /// <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 = 33000;
-
- ////传感器到菜品库的高度(坐标系)
- //private const int materialLaserHigh = 34500;
-
- /// <summary>
- /// 菜品盒坐标系高度
- /// </summary>
- private const int materialBoxHeight = 9700;
-
- //传感器1到菜品库的高度(厘米)
- //private const int materialLaserHighCM_1 = 22;
-
- ////传感器2到菜品库的高度(厘米)
- //private const int materialLaserHighCM_2 = 27;
-
- ////传感器3到菜品库的高度(厘米)
- //private const int materialLaserHighCM_3 = 31;
-
- /// <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;
- #endregion
-
- public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
- public AutoResetEvent minorReset = new AutoResetEvent(false);
- public AutoResetEvent mainReset = new AutoResetEvent(false);
-
- /// <summary>
- /// 等待炒制数量
- /// </summary>
- private int StagingFryCount { get; set; }
-
- /// <summary>
- /// 正在炒制数量
- /// </summary>
- private int FryingCount { get; set; }
-
- /// <summary>
- /// 炒锅编号与炒锅实例
- /// </summary>
- Dictionary<int, GVL_MorkF> morkFs = new Dictionary<int, GVL_MorkF>();//全局对象声明
-
- /// <summary>
- /// 菜品库对象
- /// </summary>
- ML_MorkF ml_morkf = new ML_MorkF();
-
- /// <summary>
- /// 小炒菜单集合
- /// </summary>f
- 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>
- private List<BPA.Message.AlarmModel> alarmModel = new List<BPA.Message.AlarmModel>();
-
- /// <summary>
- ///
- /// </summary>
- private List<StatsModel> statsModels = new List<StatsModel>();
-
- /// <summary>
- /// 暂存使用菜品量
- /// </summary>
- private List<GoodBatchings> stagingGoodBatchings = new List<GoodBatchings>();
-
- /// <summary>
- /// 是否为本地炒菜模式,默认为联网的
- /// </summary>
- private bool isLocalFryingMode { get; set; } = true;
-
- /// <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();
-
- ScreenDataServer();
- Json<MaterialAndFryingTime>.Read();
- //更新菜品余量
- UpdateMaterialSurplus();
-
- //读取坐标系
- MaterialCoordinate materialCoordinate = ReadMaterialCoordinate();
- if(materialCoordinate != null)
- {
- MaterialCoordinate.GetInstance().dicNoMaterialCoordinate = materialCoordinate.dicNoMaterialCoordinate;
- MaterialCoordinate.GetInstance().MLCoordinateList = materialCoordinate.MLCoordinateList;
- MaterialCoordinate.GetInstance().distance_1 = materialCoordinate.distance_1;
- MaterialCoordinate.GetInstance().distance_2 = materialCoordinate.distance_2;
- MaterialCoordinate.GetInstance().distance_3 = materialCoordinate.distance_3;
- MaterialCoordinate.GetInstance().frying1 = materialCoordinate.frying1;
- MaterialCoordinate.GetInstance().frying2 = materialCoordinate.frying2;
- MaterialCoordinate.GetInstance().materialHeight = materialCoordinate.materialHeight;
- MaterialCoordinate.GetInstance().MaterialOneX = materialCoordinate.MaterialOneX;
- MaterialCoordinate.GetInstance().MaterialTwoX = materialCoordinate.MaterialTwoX;
- MaterialCoordinate.GetInstance().MaterialThreeX = materialCoordinate.MaterialThreeX;
- }
- ////菜品库编号与坐标系对象存储
- //SaveMaterialCoordinate();
- }
-
- /// <summary>
- /// 主任务
- /// </summary>
- public override void MainTask()
- {
- //炒锅炒制线程
- MainProcessExcute();
- //菜品库操作线程
- MainProcessMaterial();
- //MinorProcessExcute();
- //SingleProcess();
-
- }
-
- private static object saveMaterialLock = new object();
- private void SaveMaterialData()
- {
- lock (saveMaterialLock)
- {
- Json<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
- Json<MaterialSurplus>.Save();
- }
- }
-
- private static object saveMaterialCoordinateLock = new object();
- /// <summary>
- /// 保存当前的坐标系
- /// </summary>
- public void SaveMaterialCoordinate()
- {
- lock (saveMaterialLock)
- {
- Json<MaterialCoordinate>.Data = MaterialCoordinate.GetInstance();
- Json<MaterialCoordinate>.Save();
- }
- }
-
- /// <summary>
- /// 读取坐标系
- /// </summary>
- /// <returns></returns>
- private MaterialCoordinate ReadMaterialCoordinate()
- {
- try
- {
- lock (saveMaterialLock)
- {
- Json<MaterialCoordinate>.Read();
- MaterialCoordinate materialCoordinate = Json<MaterialCoordinate>.Data;
- return materialCoordinate;
- }
- }
- catch(Exception ex)
- {
- return null;
- }
- }
-
- 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.6", new Action<object>((objects) =>
- {
- if (objects is bool[] bools && bools.Length == 2)
- {
- ml_morkf.PawOutComplete = bools[0];
- ml_morkf.PawInComplete = bools[1];
- }
- }), 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);
-
- //抓手初始化完成
- GetStatus("I0.1", new Action<object>((objects) =>
- {
- if (objects is bool[] bools && bools.Length > 2)
- {
- ml_morkf.PawPositon_1 = bools[0];
- ml_morkf.PawPositon_2 = bools[1];
- ml_morkf.PawPositon_3 = bools[2];
- }
- }), 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(StopLocalOrder, "StopLocalOrder");
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o is string materialName)
- {
- NewStartLocalOrder(materialName);
- }
- }), "NewStartLocalOrder");
- #endregion
-
- #region 菜品库
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- FoodLibInit();
- }), "FoodLibInit");
- }), "FoodLibInit");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- isLocalFryingMode = !isLocalFryingMode;
- }), "ModeChange");
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- if(!UpdateMaterialLibraryStock())
- {
- MessageLog.GetInstance.ShowEx("菜品库检测余量失败");
- }
- }), "SurplusCheck");
- }), "SurplusCheck");
- 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(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- PawExtend();
- }), "PawTurnFront");
- }), "PawTurnFront");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- PawShrink();
- }), "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)
- {
- SetArmPosition(list_int[0], list_int[1]);
- }
- }
- }), "SetNowPosition");
- }), "SetNowPosition");
- ActionManage.GetInstance.Register(new Action<object>((list) =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- if (list is List<object> list_object)
- {
- if (list_object.Count != 3)
- {
- return;
- }
-
- if (list_object[0] is string No && list_object[1] is int x && list_object[2] is int y)
- {
- if (SetArmPosition(x, y))
- {
- ActionManage.GetInstance.Send("CalibrationCallBack", new List<string> { No });//设定机械臂当前位置
- }
- }
- }
- }), "CalibrationCoordination");
- }), "CalibrationCoordination");
- #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(() =>
- {
- MagnetOn(fryIndex);
- }), "MagnetOn");
- }), "MagnetOn");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- MagnetOff(fryIndex);
- }), "MagnetOff");
- }), "MagnetOff");
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- string error;
- OutFood(fryIndex,out error);
- }), "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(() =>
- {
- string error;
- StirArmGoWork(fryIndex, out error);
- }), "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>
- /// 根据菜品ID下单
- /// </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 FoodMenuModel good)
- //{
- // NewStartLocalOrder(good.GoodName);
- //}
-
-
- //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}");
- // }
- //}
- }
-
-
-
- /// <summary>
- /// 本地配置的订单
- /// </summary>
- /// <param name="materialName"></param>
- private void NewStartLocalOrder(string materialName)
- {
- //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}");
- //}
- if (Json<MaterialAndFryingTime>.Data.materials.Count > 0)
- {
- if (!Json<MaterialAndFryingTime>.Data.materials.ContainsKey(materialName))
- {
- return;
- }
-
- List<PotActions> potActions = new List<PotActions>();
-
- foreach(var item in Json<MaterialAndFryingTime>.Data.materials[materialName])
- {
- potActions.Add(item);
- }
-
- StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- {
- SuborderId = Guid.NewGuid().ToString(),
- StirPotActions = potActions,
- GoodName = materialName
- });
- MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
- MessageBox.Show("下单成功");
- }
- }
-
- /// <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 菜品库方法
- #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.ShowEx("菜品库初始化超时");
- return false;
- }
- }
-
- return true;
- }
- /// <summary>
- /// 爪子伸出
- /// </summary>
- /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
- public bool PawExtend()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("爪子伸出错误,菜品库未初始化");
- return false;
- }
- Thread.Sleep(500);
- MaterailLibrary_Write("M0.6", true);
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawOutComplete; i++)//潘华小炒没有夹爪到位功能
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.ShowEx("爪子伸出超时");
- return false;
- }
- }
- return true;
- ////等待爪子伸出延时4s
- //Thread.Sleep(6000);
- }
- /// <summary>
- /// 爪子收缩
- /// </summary>
- /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
- public bool PawShrink()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("爪子伸出错误,菜品库未初始化");
- return false;
- }
-
- MaterailLibrary_Write("M0.7", true);
- Thread.Sleep(500);
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawInComplete; i++)//潘华小炒没有夹爪到位功能
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.ShowEx("爪子伸出超时");
- return false;
- }
- }
- return true;
- //等待爪子收缩延时4s
- //Thread.Sleep(6000);
- }
- /// <summary>
- /// 电磁阀启停
- /// </summary>
- /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
- public void Electromagnetism(object o)
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("电磁阀启停出错,菜品库未初始化");
- 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)
- {
- MessageLog.GetInstance.ShowEx("爪子去到1号位出错,菜品库未初始化");
- return false;
- }
-
- //MessageLog.GetInstance.Show("爪子去到1号位");
- MaterailLibrary_Write("M1.0", true);
-
- Thread.Sleep(500);
-
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortOne; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- if (i == 10)
- {
- MaterailLibrary_Write("M1.0", true);
- }
- MessageLog.GetInstance.ShowEx("爪子去到1号位超时");
- return false;
- }
- }
-
- Thread.Sleep(300);
-
- //MessageLog.GetInstance.Show("爪子去到1号位完成");
- return true;
- }
-
- public bool PawToPoint2()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("爪子去到2号位出错,菜品库未初始化");
- return false;
- }
-
- MaterailLibrary_Write("M1.1", true);
- //MessageLog.GetInstance.Show("爪子去到2号位");
-
-
- Thread.Sleep(500);
-
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortTwo; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- if (i == 10)
- {
- MaterailLibrary_Write("M1.1", true);
- }
- MessageLog.GetInstance.ShowEx("爪子去到2号位超时");
- return false;
- }
- }
-
- Thread.Sleep(300);
-
- //MessageLog.GetInstance.Show("爪子去到2号位完成");
- return true;
- }
-
- public bool PawToPoint3()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("爪子去到3号位出错,菜品库未初始化");
- return false;
- }
-
- //MessageLog.GetInstance.Show("爪子去到3号位");
- MaterailLibrary_Write("M1.2", true);
-
- Thread.Sleep(500);
-
- for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortThree; i++)
- {
- Thread.Sleep(materialSleepTime);
- if(i == 30)
- {
- MaterailLibrary_Write("M1.2", true);
- }
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.ShowEx("爪子去到3号位超时");
-
- }
- }
- if (!ml_morkf.PawPositon_3)
- {
- MaterailLibrary_Write("M1.2", true);
- Thread.Sleep(3000);
- }
- Thread.Sleep(300);
-
- //MessageLog.GetInstance.Show("爪子去到3号位完成");
- return true;
- }
-
- public bool GetDistance_1()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("1号测距出错,菜品库未初始化");
- return false;
- }
-
- MaterailLibrary_Write("M0.3", true);
- MaterailLibrary_Write("M0.3", false);
- Thread.Sleep(3000);
-
- //MessageLog.GetInstance.Show("1号测距开启完成");
- //MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
-
- ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "1",ml_morkf.LaserDistance.ToString() });//通知获取测距界面
-
- return true;
- }
- public bool GetDistance_2()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("2号测距出错,菜品库未初始化");
- return false;
- }
-
- MaterailLibrary_Write("M0.4", true);
- MaterailLibrary_Write("M0.4", false);
- Thread.Sleep(3000);
-
- //MessageLog.GetInstance.Show("2号测距开启完成");
- //MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
-
- ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "2", ml_morkf.LaserDistance.ToString() });//通知获取测距界面
-
- return true;
- }
- public bool GetDistance_3()
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx("3号测距出错,菜品库未初始化");
- return false;
- }
-
- MaterailLibrary_Write("M0.5", true);
- MaterailLibrary_Write("M0.5", false);
- Thread.Sleep(3000);
-
- //MessageLog.GetInstance.Show("3号测距开启完成");
- //MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
-
- ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "3", ml_morkf.LaserDistance.ToString() });//通知获取测距界面
-
- return true;
- }
-
- /// <summary>
- /// 写入传感器距离
- /// </summary>
- /// <param name="speed"></param>
- public void WriteSpeed(int speed)
- {
- MaterailLibrary_Write("VD808", speed);
- Thread.Sleep(400);
- }
-
- /// <summary>
- /// 写入传感器距离
- /// </summary>
- /// <param name="distance"></param>
- public void WriteDistance(int distance)
- {
- MaterailLibrary_Write("VW270", distance);
- }
-
- /// <summary>
- /// 根据x坐标获取传感器距离
- /// </summary>
- /// <param name="x"></param>
- /// <returns></returns>
- public bool GetDistance(int x)
- {
- bool ret = true;
- //是否在第一层菜品库
- if (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)
- {
- //获取传感器1的距离
- ret &= GetDistance_1();
-
- Thread.Sleep(400);
-
- ////获取传感器1的距离
- ret &= GetDistance_1();
- }
- //是否在第二层菜品库
- else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X)
- {
- //获取传感器2的距离
- ret &= GetDistance_2();
-
- Thread.Sleep(400);
-
- ret &= GetDistance_2();
- }
- //是否在第三层菜品库
- else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["19"].X)
- {
- //获取传感器3的距离
- ret &= GetDistance_3();
-
- Thread.Sleep(400);
-
- ret &= GetDistance_3();
- }
- if (!ret)
- {
- MessageLog.GetInstance.ShowEx($"错误:X轴:{x}获取传感器数据出错");
- }
- return ret;
- }
-
- /// <summary>
- /// 设定机械臂的位置
- /// </summary>
- /// <param name="x"></param>
- /// <param name="y"></param>
- public bool SetArmPosition(int x, int y)
- {
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.ShowEx($"机械臂移动出错,菜品库未初始化");
- return false;
- }
-
- if (x>212000|| y >240000)
- {
- MessageLog.GetInstance.ShowEx("机械臂移动超出范围");
- return false;
- }
-
- //取反
- x = 0 - Math.Abs(x);
- y = 0 - Math.Abs(y);
- if (x > 0 || y > 0)
- {
- MessageLog.GetInstance.ShowEx($"机械臂移动到[{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.ShowEx("机械臂移动操作超时");
- return false;
- }
- }
-
- //MessageLog.GetInstance.Show("机械臂移动操作完成");
-
- Thread.Sleep(300);
-
- 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);
- }
- #endregion
-
- //菜品库锁
- 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;
-
-
- //秦工要求读取后置0
- WriteDistance(0);
-
- MessageLog.GetInstance.Show($"传感器的距离{laserHigh}");
-
- int moveX = 0;
- if (LaserDistance2Coordinate(laserHigh, x, out moveX) != Laser2CoordinateState.MaterialNormal)
- {
- MessageLog.GetInstance.ShowEx("错误:传感器距离转坐标值失败");
- return false;
- }
-
- if (x < moveX)
- {
- MessageLog.GetInstance.ShowEx("错误:传感器距离转坐标值大于当前x轴坐标");
- return false;
- }
-
- //设置到传感器感应的距离处
- if (!SetArmPosition(x - moveX, y))
- {
- return false;
- }
-
- WriteSpeed(10000);
-
- //关闭电磁阀
- Electromagnetism(new List<bool> { true });
- Thread.Sleep(500);
-
- //爪子去1号位抓菜
- if (!PawToPoint1())
- {
- return false;
- }
-
- //伸出爪子
- if (!PawExtend())
- {
- return false;
- }
-
-
- //移动前开启电磁阀
- Electromagnetism(new List<bool> { false });
- Thread.Sleep(500);
-
- //根据x轴所在坐标系,计算高度差。
- if( (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)&&
- (MaterialCoordinate.GetInstance().MaterialOneX > 0 && MaterialCoordinate.GetInstance().MaterialOneX < x))
- {
- //菜品盒子出菜品库,往上移动一个盒子的距离
- if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialOneX, y))
- {
- return false;
- }
- }
- else if( (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)&&
- (MaterialCoordinate.GetInstance().MaterialTwoX > 0 && MaterialCoordinate.GetInstance().MaterialTwoX < x))
- {
- //菜品盒子出菜品库,往上移动一个盒子的距离
- if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialTwoX, y))
- {
- return false;
- }
- }
- else if ((x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X) &&
- (MaterialCoordinate.GetInstance().MaterialThreeX > 0 && MaterialCoordinate.GetInstance().MaterialThreeX < x))
- {
- //菜品盒子出菜品库,往上移动一个盒子的距离
- if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialThreeX, y))
- {
- return false;
- }
- }
- else
- {
- MessageLog.GetInstance.ShowEx("错误:未设置当前菜品库出菜位置");
- return false;
- }
-
-
- //爪子去2号位放菜
- if (!PawToPoint2())
- {
- return false;
- }
-
- WriteSpeed(50000);//移动速度
- //ThreadManage.GetInstance().Start(new Action(() =>
- //{
- // //收缩爪子
- // PawShrink();
- //}), "GetMaterialPawShrink");
-
- //收缩爪子
- if (!PawShrink()) return false;
-
- //判断炒锅是否可以放盒
- for (int i = 0; materialSleepCount > i && !morkFs[fryNum].FryPot1_HOBTPut; i++)
- {
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount - 1)
- {
- MessageLog.GetInstance.ShowEx("等待炒锅允许放盒超时");
- return false;
- }
- }
-
- //关闭启磁吸
- MagnetOff(fryNum);
-
- //Thread.Sleep(2000);
-
- //根据炒锅不同设置不同的出菜处
- if (fryNum % 2 == 0)
- {
- x = MaterialCoordinate.GetInstance().frying1.X;
- y = MaterialCoordinate.GetInstance().frying1.Y;
- }
- else
- {
- x = MaterialCoordinate.GetInstance().frying2.X;
- y = MaterialCoordinate.GetInstance().frying2.Y;
- }
-
- //先设置到炒锅i出菜处上10000点
- if (!SetArmPosition(x - materialToFryDistance, y))
- {
- return false;
- }
-
- //爪子去3号位放菜
- if (!PawToPoint3())
- {
- return false;
- }
-
- //开启磁吸
- MagnetOn(fryNum);
-
- Thread.Sleep(500);
-
- //设置到炒锅1出菜处
- if (!SetArmPosition(x, y))
- {
- return false;
- }
-
-
- //伸出爪子
- if (!PawExtend())
- {
- return false;
- }
-
- Thread.Sleep(300);
-
- //关闭电磁阀
- Electromagnetism(new List<bool> { true });
- Thread.Sleep(300);
-
- //收缩爪子
- if (!PawShrink()) return false;
-
- //设置到炒锅i出菜处
- if (!SetArmPosition(x + materialToFryDistance, y))
- {
- return false;
- }
-
- //爪子回到2号位
- if (!PawToPoint2())
- {
- return false;
- }
-
- //开启电磁阀
- Electromagnetism(new List<bool> { false });
- if (morkFs.ContainsKey(fryNum))
- {
- morkFs[fryNum].GetMaterialComplete = true;
- }
- return true;
- }
-
- /// <summary>
- /// 更新菜品库存量
- /// </summary>
- /// <returns></returns>
- public bool UpdateMaterialLibraryStock()
- {
- try
- {
- //判断是否初始化
- if (!ml_morkf.InitialComplete)
- {
- MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库未初始化");
- return false;
- }
-
- if (MaterialCoordinate.GetInstance().dicNoMaterialCoordinate == null || MaterialCoordinate.GetInstance().dicNoMaterialCoordinate.Count != 27)
- {
- MessageLog.GetInstance.ShowEx("更新菜品库存量出错,菜品库坐标系数据未建立");
- return false;
- }
-
- //关闭电磁阀
- Electromagnetism(new List<bool> { true });
-
- //爪子收回
- if (!PawShrink())
- {
- return false;
- }
-
- //爪子去2号点位
- if (!PawToPoint2())
- {
- return false;
- }
-
- //开启电磁阀
- Electromagnetism(new List<bool> { false });
-
- //遍历坐标系与位置,并根据位置更新菜品余量
- foreach (var item in MaterialCoordinate.GetInstance().dicNoMaterialCoordinate)
- {
- bool ret = true;
- switch (item.Key)
- {
- //遇到1 9 10 18 19 27号位置跳过不检测,因为这6个位置不放菜品
- case "1":
- case "9":
- case "10":
- case "18":
- case "19":
- case "27":
- ret = false;
- break;
- }
-
- if (!ret)
- {
- continue;
- }
-
- //设置到抓菜处
- if (!SetArmPosition(item.Value.X, item.Value.Y))
- {
- return false;
- }
-
- //获取该处的距离
- if (!GetDistance(item.Value.X))
- {
- MessageLog.GetInstance.ShowEx("错误:获取传感器数据出错");
- return false;
- }
-
- Thread.Sleep(1000);
-
- //获取传感器的距离
- int laserHigh = ml_morkf.LaserDistance;
-
- //秦工要求读取后置0
- WriteDistance(0);
-
- int surplus = 0;
- //根据距离算出菜品余量
- Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, item.Value.X, 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_high"></param>
- /// <returns></returns>
- public Laser2CoordinateState LaserDistance2Coordinate(int distance, int x, out int x_high)
- {
- x_high = 0;
- int boxCount = 0;
- try
- {
- Laser2CoordinateState laser2CoordinateState = LaserDistance2MaterialCount(distance, x, out boxCount);
- if (laser2CoordinateState == Laser2CoordinateState.MaterialNormal)
- {
- int compensateHeight = boxCount > 1 ? 500 : 0;//补偿高度,超过1层盒子增加补偿
-
- //盒子高度计算除去起始位置的那个盒子
- x_high = (boxCount - 1) * materialBoxHeight + compensateHeight;
- }
- return laser2CoordinateState;
-
- }
- catch(Exception ex)
- {
- return Laser2CoordinateState.MaterialUnkown;
- }
- }
-
- /// <summary>
- /// 传感器距离转为菜品数量
- /// </summary>
- /// <param name="distance"></param>
- /// <param name="x"></param>
- /// <returns></returns>
- public Laser2CoordinateState LaserDistance2MaterialCount(int distance, int x, out int count)
- {
- count = 0;
- try
- {
- //传感器高度小于80mm,无法移出,菜品库满
- if (distance < 80)
- {
- MessageLog.GetInstance.ShowEx("错误:传感器距离不满足出菜高度");
- return Laser2CoordinateState.MaterialOverdo;
- }
-
- int heightDifferent = 0;
- //根据x轴所在坐标系,计算高度差。
- if (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)
- {
- heightDifferent = MaterialCoordinate.GetInstance().distance_1 - distance;
- }
- else if (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)
- {
- heightDifferent = MaterialCoordinate.GetInstance().distance_2 - distance;
- }
- else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X)
- {
- heightDifferent = MaterialCoordinate.GetInstance().distance_3 - distance;
- }
- else
- {
- return Laser2CoordinateState.MaterialOverdo;
- }
-
- if(heightDifferent < 0)
- {
- MessageLog.GetInstance.ShowEx($"菜品库检测{x}处的菜品量时,传感器获取的高度差为负数,请校准该层高度");
- return Laser2CoordinateState.MaterialEmpty; ;
- }
-
- //盒子高度为45,但是需要考虑到误差,不足35,则认为为空
- int boxCount = (heightDifferent + 5) / 35;
- count = boxCount;
- if (count == 0)
- {
- MessageLog.GetInstance.ShowEx("菜品库为空");
- return Laser2CoordinateState.MaterialEmpty;
- }
- else if(count > 6)
- {
- MessageLog.GetInstance.ShowEx("菜品库数量超量");
- return Laser2CoordinateState.MaterialOverdo;
- }
- else
- {
- return Laser2CoordinateState.MaterialNormal;
- }
- }
- 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.ShowEx($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置");
- return;
- }
- //取菜操作
- ret = GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum);
- }
- catch (Exception ex)
- {
- ret = false;
- }
- finally
- {
- //本地炒制不进行菜品数量检查
- if(!isLocalFryingMode)
- {
- GoodBatchings goodBatchings = stagingGoodBatchings.Find(o => o.BatchingId == materialOperation.materialInfo.Key);
- if (ret == true)
- {
- if (true)
- {
- if (goodBatchings != null)
- {
- //指定位置菜品减一
- MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc, goodBatchings.BatchingCount);
- }
- }
- else
- {
- //指定位置菜品减一
- MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
- }
-
- SaveMaterialData();
- }
- //移出占用菜品
- stagingGoodBatchings.Remove(goodBatchings);
- }
- ml_morkf.MaterailIsWorking = false;
- }
-
- }), $"菜品库操作");
- }
- #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);
- }
- }
- }), $"炒锅{num}初始化");
-
- }
-
- /// <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.ShowEx($"炒锅{j}初始化超时");
- }
- }
- 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 bool OutFood(int num,out string error,bool isMaterial = false)
- {
- bool ret = true;
- error = string.Empty;
-
- if (!morkFs.ContainsKey(num))
- {
- error = $"编号为{num}的炒锅无法找到";
- return false;
- }
- int i = 0;
-
- MessageLog.GetInstance.Show("倒菜启动开始");
-
- if (isMaterial)
- {
- //判断是否完成取菜
- for (i = 0; i < materialSleepCount*2 && !morkFs[num].GetMaterialComplete; i++)
- {
- if (i == 10)
- {
- //停止搅拌
- //StopStir(num);
- //搅拌设置为1档
- SetStir(new List<int> { 1 }, i);
- //火力设置为2档
- SetFire(new List<int> { 3 }, num);
- }
- Thread.Sleep(materialSleepTime);
- if (i >= materialSleepCount * 2 - 1)
- {
- error = $"炒锅{num}倒菜超时:未能等到取菜完成,请检查菜品库是否正常运行";
- MessageLog.GetInstance.ShowEx($"炒锅{num}倒菜超时:未能等到取菜完成");
- ret &= false;
- }
- }
-
- if (i > 9)
- {
- //开启搅拌
- //StartStir(num);
- //搅拌设置为原本搅拌档位
- SetStir(new List<int> { morkFs[num].Stir }, i);
- //火力设置回原本火力
- SetFire(new List<int> { morkFs[num].Fire }, num);
- }
- }
-
- if(!ret)
- {
- return ret;
- }
-
- 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)
- {
- error = $"炒锅{num}倒菜超时,请联系相关工作人员";
- MessageLog.GetInstance.ShowEx($"炒锅{num}倒菜超时");
- ret &= false;
- }
- }
-
- FirePot_Write("LB3", false, num);
- Thread.Sleep(200);
- //MessageLog.GetInstance.Show("倒菜完成");
- morkFs[num].GetMaterialComplete = false;
- return ret;
- }
- //搅拌臂去原点位
- 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.ShowEx($"炒锅{num}搅拌臂去原点位超时");
- }
- }
-
- FirePot_Write("LB5", false, num);
- Thread.Sleep(200);
- //MessageLog.GetInstance.Show("搅拌臂到达原点位");
- }
-
- //搅拌臂去炒制位
- public bool StirArmGoWork(int num,out string error)
- {
- error = string.Empty;
- bool ret = true;
- if (!morkFs.ContainsKey(num))
- {
- error = $"编号为{num}的炒锅无法找到";
- return false;
- }
-
- 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)
- {
- error = $"炒锅{num}搅拌臂去炒制位超时";
- MessageLog.GetInstance.ShowEx($"炒锅{num}搅拌臂去炒制位超时");
- ret &= false;
- }
- }
-
- //while (!morkFs[num].ArmOnWorking)
- //{
- // Thread.Sleep(200);
- //}
-
- FirePot_Write("LB6", false, num);
- Thread.Sleep(200);
- //MessageLog.GetInstance.Show("搅拌臂到达工作位");
- return ret;
- }
-
- return true;
-
- }
- //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.ShowEx("搅拌臂不在原点位,无法完成出餐");
- return;
- }
- FirePot_Write("LB4", true, num);
- Thread.Sleep(500);
- 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);
-
- }
- }
-
- /// <summary>
- /// 开启磁吸
- /// </summary>
- /// <param name="num"></param>
- public void MagnetOn(int num)
- {
- FirePot_Write("LB8", false, num);
- Thread.Sleep(200);
- }
-
- /// <summary>
- /// 关闭磁吸
- /// </summary>
- /// <param name="num"></param>
- public void MagnetOff(int num)
- {
- FirePot_Write("LB8", true, num);
- Thread.Sleep(200);
- }
- #endregion
-
- 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),
- });
-
- }
- }
-
- 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);
- }
-
- if (stirFry.stirFrymessage.materials.Count > 0)
- {
- MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials);
- SaveMaterialData();
- }
- }
-
- }
- });
- }
-
- /// <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 Id , string goodName, ORDER_STATUS oRDER_STATUS,int deviceId)
- {
- EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, GoodName = goodName,DeviceId = deviceId, SubOrderId =Id });
- }
-
- /// <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));
-
- if(true)
- {
-
- var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.GoodsKey);//匹配订单对应制作流程
- if(order.MorkOrder.GoodBatchings.Count <= 0)
- {
- return;
- }
-
- MaterialSurplus materialSurplus = MaterialSurplusOperation.GetInstance().materialSurplus;
-
- if (order.MorkOrder.DeviceId != DeviceId)
- {
- return;
- }
-
- ///遍历并增加到待用菜品库
- foreach(var goodBatching in order.MorkOrder.GoodBatchings)
- {
- MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Find( o => o.Key == goodBatching.BatchingId);
- if (materialInfo != null)
- {
- //if
- if(System.Convert.ToInt32(materialInfo.Qty) - goodBatching.BatchingCount < 0)
- {
- MessageLog.GetInstance.ShowEx($"{materialInfo.Name}不够,请更新菜品库,并点击检测");
- return;
- }
- else
- {
- //查找是否有该菜品
- GoodBatchings existingGoodBatchings = stagingGoodBatchings.Find( o => o.BatchingId== goodBatching.BatchingId );
- //判断是否存在
- if (existingGoodBatchings != null)
- {
- existingGoodBatchings.BatchingCount += goodBatching.BatchingCount;
- }
- else
- {
- stagingGoodBatchings.Add(goodBatching);
- }
- }
- }
- else
- {
- MessageLog.GetInstance.ShowEx($"ID为{goodBatching.BatchingId}的菜品无法找到,请联系售后人员");
- return;
- }
- }
-
- //var res = LocalstirFryGoods[0];
- if (res != null)
- {
- /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
- //添加到带炒小炒队列
- if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- //待炒数量+1
- StagingFryCount++;
- lock (lock_MainProcessExcute)
- {
- StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- StirPotActions = res.StirPotActions,
- GoodName = order.MorkOrder.GoodsName
- });
- }
- }
- }
-
- }
- else
- {
- NewStartLocalOrder("莲白回锅");
- }
- ////暂时使用本地菜单
- //StartLocalOrder();
- }
-
- });
- }
- #endregion
-
- private object lock_MainProcessExcute = new object();
-
- /// <summary>
- /// 倒菜锁
- /// </summary>
- private object lock_OutMeal = 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 && ml_morkf.InitialComplete &&
- !morkFs[i].FryWorking)//炒锅在自动状态&&初始化完成&&菜品库初始化&&是否在炒菜中
- {
- Thread.Sleep(4000);
-
- lock(lock_MainProcessExcute)
- {
- //待炒小炒队列出队列
- if (StirFryGoodsQuenes.TryDequeue(out var res))
- {
- OrderChange(res.SuborderId, res.GoodName, ORDER_STATUS.WAIT, DeviceId = i);
- //设置当前炒制菜品
- nowStirFryGood[i] = res;
- //炒锅工作状态置为正在工作中
- morkFs[i].FryWorking = true;
- //空闲炒锅入队列
- morkFs[i].StirFryGoodsQuenes.Enqueue(res);
- //炒锅取菜状态置为未取到
- morkFs[i].GetMaterialComplete = false;
- //开启线程进行炒制
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- try
- {
- //待炒数量-1
- StagingFryCount--;
- //正在炒制数量+1
- FryingCount++;
- int testi = 0;
- string error = string.Empty;
- //初始化大屏
- morkFs[i].ScreenInit();
-
- bool ret = true;
-
- MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}");
- OrderChange(res.SuborderId, res.GoodName, ORDER_STATUS.COOKING, DeviceId = i);
- morkFs[i].GoodName = res.GoodName;
-
- Coordinate myCoordinate = new Coordinate();
-
- foreach (var potActions in res.StirPotActions)
- {
- if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)))
- {
- return;
- }
-
- if(ret == false)
- {
- MessageLog.GetInstance.ShowEx("上一步操作未成功");
- break;
- }
-
- ////调试大屏用代码
- //Thread.Sleep(5000);
-
- //更新
- morkFs[i].UpdateProcess(potActions);
-
- 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.取原料):
- if(potActions.SeasoningLists[0].Loc == 1 ||
- potActions.SeasoningLists[0].Loc == 9 ||
- potActions.SeasoningLists[0].Loc == 10 ||
- potActions.SeasoningLists[0].Loc == 18 ||
- potActions.SeasoningLists[0].Loc == 19 ||
- potActions.SeasoningLists[0].Loc == 27 )
- {
- MessageLog.GetInstance.ShowEx("该取料位置禁止使用");
- return;
- }
- //炒锅取菜状态置为未取到
- morkFs[i].GetMaterialComplete = false;
-
- if (isLocalFryingMode)
- {
- MaterialInfo materialInfo = new MaterialInfo();
- materialInfo.Loc = potActions.SeasoningLists[0].Loc.ToString();
- materialInfo.Id = "1232131";
- materialInfo.Name = "本地炒制未知菜品";
- materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
- //testi++;
- }
- else
- {
- if (potActions.MaterialLists != null)
- {
- foreach (var item in potActions.MaterialLists)
- {
- //通过ID获取有效的菜品对象
- MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().GetVailedMaterial(item.MaterialId);
- if (materialInfo == null)
- {
- MessageLog.GetInstance.ShowEx($"炒锅{i}获取菜品[{item.MaterialId}]失败,库存不足");
- continue;
- }
-
- materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
- }
- }
- else
- {
- MessageLog.GetInstance.ShowEx($"炒锅{i}获取菜品失败,菜品列表为空");
- }
- }
-
- 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.出餐启动):
- //停止搅拌
- StopStir(i);
- //回原点位
- StirArmGoOrigin(i);
- //出餐启动
- OutMeal(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.道菜启动):
- ret = OutFood(i, out error, true);
- if(ret == false)
- {
- alarmModel.Add(new BPA.Message.AlarmModel() { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = error });
- }
- break;
- case nameof(StirFryPotActionEnum.炒制菜品):
- Thread.Sleep(potActions.During * 1000);
- break;
- case nameof(StirFryPotActionEnum.搅拌臂原点位):
- StirArmGoOrigin(i);
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.搅拌臂炒制位):
- //出餐时,不允许搅拌臂去炒制位
- lock (lock_OutMeal)
- {
- ret = StirArmGoWork(i, out error);
- }
- if (ret == false)
- {
- alarmModel.Add(new BPA.Message.AlarmModel() { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = error });
- }
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- case nameof(StirFryPotActionEnum.洗锅):
- MessageLog.GetInstance.Show(potActions.Actions);
- break;
- default:
- break;
-
- }
- }
-
- Plc1Reset(i);//复位
- Thread.Sleep(3000);
- //回原点位
- StirArmGoOrigin(i);
- OrderChange(res.SuborderId, res.GoodName, ORDER_STATUS.COMPLETED_COOK, DeviceId = i);
- //同时只能允许有一个出餐
- lock (lock_OutMeal)
- {
- //出餐启动
- OutMeal(i);
- //等待25s出餐完毕
- Thread.Sleep(25000);
-
- }
-
- MessageLog.GetInstance.Show($"菜品{res.GoodName}完成");
-
- //菜品统计数量+1
- morkFs[i].orderCount++;
-
- StatsModel statsModel = statsModels.FirstOrDefault(p => p.Name == res.GoodName);
- if (statsModel != null)
- {
- statsModel.Count++;
- }
- else
- {
- statsModels.Add(new StatsModel() { Name = res.GoodName, Count = 0 });
- }
- }
- catch (Exception ex)
- {
- nowStirFryGood[i] = null;
- //炒完后出队列
- morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
- morkFs[i].FryWorking = false;
- //初始化大屏
- morkFs[i].ScreenClear();
- //异常菜品统计数量+1
- morkFs[i].orderAbnormalCount++;
- ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程");
- MessageLog.GetInstance.ShowEx($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message);
- }
- finally
- {
- //正在炒制数量-1
- FryingCount--;
- nowStirFryGood[i] = null;
- //炒完后出队列
- morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
- morkFs[i].FryWorking = false;
- //初始化大屏
- morkFs[i].ScreenClear();
- }
- }), String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/, true);
- }
- }
- break;
- }
- }
- }
- }
-
- /// <summary>
- /// 更新菜品库的余量
- /// </summary>
- private void UpdateMaterialSurplus()
- {
- ThreadManage.GetInstance().StartLong(new Action(() => {
-
- List<MaterialInfo> listSurplus = MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus;
-
- if (listSurplus == null)
- {
- return;
- }
-
- foreach (var surplus in listSurplus)
- {
- //找到已有的余量表
- var batchingInfo = BatchingInfos.Find(o => o.BatchingId == surplus.Key);
- //从当前下单
- var stagingGoodBatching = stagingGoodBatchings.Find(o => o.BatchingId == surplus.Key);
-
- //暂存的数量
- int stagingCount = 0;
-
- if(stagingGoodBatching != null)
- {
- stagingCount = stagingGoodBatching.BatchingCount;
- }
-
- if (batchingInfo == null)
- {
- //为空就新增
- BatchingInfos.Add(new BatchingInfo() { BatchingCount = System.Convert.ToInt32(surplus.Qty) - stagingCount, BatchingLoc = surplus.Loc, BatchingId = surplus.Key });
- }
- else
- {
- batchingInfo.BatchingLoc = surplus.Loc;
- batchingInfo.BatchingCount = System.Convert.ToInt32(surplus.Qty) - stagingCount;
- }
- }
- Thread.Sleep(1000);
- return;
- }), "UpdateMaterialSurplus", true);
- }
-
- /// <summary>
- /// 菜品库主流程
- /// </summary>
- private void MainProcessMaterial()
- {
- if(materialOperationQuenes.Count > 0)
- {
- //判断是否初始化与是否在工作中
- if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking)
- {
- //待菜品库操作列出队列
- if (materialOperationQuenes.TryDequeue(out var res))
- {
- Thread.Sleep(1000);
-
- ml_morkf.MaterailIsWorking = true;
- MessageLog.GetInstance.Show("开始操作菜品库");
- //ThreadManage.GetInstance().Start(new Action(()=>{
- // GetMaterail(res.x_high, res.y, res.fryNum);
- //}),"菜品库操作");
- GetMaterailTest(res);
- }
- }
- }
- }
-
- /// <summary>
- /// 信号处理
- /// </summary>
- private void SingleProcess()
- {
-
- }
-
-
- private void ScreenDataServer()
- {
- LocalMqtt.GetInstance.Init(ScreenDeviceType.小炒);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- //statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 });
- ScreenModelMinWok maxWok = new ScreenModelMinWok
- {
- IsRun = IsHealth ? IsRun.运行 : IsRun.停止,//new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, //设备是否运行
- WorkStatus_1 = morkFs[0].FryPot1_InitialComplete ? ((morkFs[0].Task != null)? WorkStatus.工作:WorkStatus.待机) : WorkStatus.停止,// (WorkStatus)new Random().Next(0, 3), //设备运行状态
- WorkStatus_2 = morkFs[1].FryPot1_InitialComplete ? ((morkFs[1].Task != null) ? WorkStatus.工作 : WorkStatus.待机) : WorkStatus.停止,//(WorkStatus)new Random().Next(0, 3), //设备运行状态
- RobotStatu = (WorkStatus)new Random().Next(0, 3), //机器人状态 待机 1 正常
- Alarm = alarmModel, //告警集合
- FailuresCount = alarmModel.Count, //故障数
- StatsCount = statsModels, //统计菜品数量
- MinWok_Dishes_1 = morkFs[0].GoodName,//"满汉全席",//当前炒制菜品名
- MinWok_Dishes_2 = morkFs[1].GoodName,
- MinWok_Task_1 = morkFs[0].Task,//当前任务
- MinWok_Task_2 = morkFs[1].Task, //当前任务
- //MinWok_Process_1 = new List<ProcessModel>() { new ProcessModel() { Id = 1, Name = "启动", Status = ProcessStatus.正在执行 }, new ProcessModel() { Id = 1, Name = "热油", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "炒制", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "出餐", Status = ProcessStatus.未执行 }, new ProcessModel() { Id = 1, Name = "结束", Status = ProcessStatus.未执行 } },
- MinWok_Process_1 = morkFs[0].processModels, //炒锅当前任务流程
- MinWok_Process_2 = morkFs[1].processModels, //炒锅当前任务流程
- MinWok_HeatGear_1 = morkFs[0].FireNow, //炒锅加热档位
- MinWok_HeatGear_2 = morkFs[1].FireNow, //炒锅加热档位
- MinWok_Temp_1 = morkFs[0].TempNow, //炒锅1锅底温度
- MinWok_Temp_2 = morkFs[1].TempNow, //炒锅1锅底温度
- MinWok_StirGear_1 = morkFs[0].StirNow, //炒锅搅拌档位
- MinWok_StirGear_2 = morkFs[1].StirNow, //炒锅搅拌档位
- MinWok_OrderCount_1 = morkFs[0].orderCount, //订单数量
- MinWok_OrderCount_2 = morkFs[1].orderCount, //订单数量
- MinWok_ErrorOrderCount_1 = morkFs[0].orderAbnormalCount, //异常订单数量
- MinWok_ErrorOrderCount_2 = morkFs[1].orderAbnormalCount, //异常订单数量
-
- };
- LocalMqtt.GetInstance.Publish(maxWok);
- Thread.Sleep(1000);
-
- }), "大屏数据上报",true);
-
- }
-
- 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.GetInstance().dicNoMaterialCoordinate.ContainsKey(no))
- {
- coordinate = MaterialCoordinate.GetInstance().dicNoMaterialCoordinate[no];
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- finally
- {
-
- }
- }
-
- public enum Laser2CoordinateState
- {
- MaterialOverdo = 0,//菜品过量
- MaterialNormal = 1,//菜品正常
- MaterialEmpty = 2,//菜品为空
- MaterialUnkown = 999,//菜品未知错误
- }
- }
- }
|