|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
-
- using BPA.Message.Enum;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.Device;
- using BPASmartClient.MorkCL.HelpClass;
- using BPASmartClient.MorkCL.Model.DB;
- using BPASmartClient.MorkCL.Model.Json;
- using BPASmartClient.MorkCL.Server;
- using Newtonsoft.Json.Linq;
- using Opc.Ua;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.WebSockets;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MorkCL
- {
- public class Control_MorkCL : BaseDevice
- {
- public override DeviceClientType DeviceType => DeviceClientType.MORKCL;
-
- GVL_MorkCL morkCL = new GVL_MorkCL();
- Alarm alarm = new Alarm();
- /// <summary>
- /// 设备信息集合
- /// </summary>
- ConcurrentDictionary<EDeviceType, IModbus> devices { get; set; } = new();
-
- /// <summary>
- /// 任务集合
- /// </summary>
- ConcurrentDictionary<EDeviceType, TaskServer> TaskList { get; set; } = new();
-
- List<PropertyInfo>? propertyInfos;
-
- public override void DoMain()
- {
- MonitorViewModel.DeviceId = DeviceId;
-
- SqliteHelper.GetInstance.Init();
-
- #region 读取本地文件数据
- Json<RecipesInfo>.Read();
- Json<ItemStorageInfo>.Read();
- Json<ConnectPar>.Read();
- #endregion
-
- //注册本地配方接收
- ActionManage.GetInstance.Register(new Action<object>(o =>
- {
- DeviceProcessLogShow($"接收到一个新配方任务。");
- if (o != null && o is ControlData cd)
- {
-
-
- morkCL.cds.Enqueue(cd);
- DeviceProcessLogShow($"新配方任务{cd.Id}解析完成,已加入配方队列。");
- }
- else
- {
- DeviceProcessLogShow($"新配方任务解析失败。");
- }
- }), NotifyTopic.FormulaDistribution);
-
- //初始化通讯对象
- devices.TryAdd(EDeviceType.炒锅1, new FryingPanServer());
- devices.TryAdd(EDeviceType.炒锅2, new FryingPanServer());
- devices.TryAdd(EDeviceType.机器人, new RobotServer());
- devices.TryAdd(EDeviceType.压力锅, new PressureCookerServer());
- devices.TryAdd(EDeviceType.外部设备, new OtherServer());
-
- morkCL.IsUseSplitStorage = Json<ConnectPar>.Data.IsUseSplitStorage;
-
- #if !FORMAL
- if (Json<ConnectPar>.Data.FryPanConnect_1)
- {
- devices[EDeviceType.炒锅1].Init(Json<ConnectPar>.Data.FryingPanIP1);
- }
- if (Json<ConnectPar>.Data.FryPanConnect_2)
- {
- devices[EDeviceType.炒锅2].Init(Json<ConnectPar>.Data.FryingPanIP2);
- }
- if (Json<ConnectPar>.Data.RobotConnet)
- {
- devices[EDeviceType.机器人].Init(Json<ConnectPar>.Data.RobotIP);
- }
- if (Json<ConnectPar>.Data.PressureCookerConnect)
- {
- devices[EDeviceType.压力锅].Init(Json<ConnectPar>.Data.PressureCookerIP);
- }
- if (Json<ConnectPar>.Data.OtherDeviceConnect)
- {
- devices[EDeviceType.外部设备].Init(PortName: Json<ConnectPar>.Data.ESPortName);
- }
- #endif
- ManualActionRegiester();
- }
-
- public override void MainTask()
- {
- //检查到有任务完成后将对已完成的任务进行清理
- var res = TaskList.FirstOrDefault(p => p.Value.IsComplete).Key;
- if (TaskList.ContainsKey(res))
- TaskList.TryRemove(res, out _);
-
- if (TaskList.IsEmpty)
- {
- morkCL.CanItemStorage = true;
- }
- else
- {
- morkCL.CanItemStorage = false;
- }
-
- //分配任务,这段程序必须写最后。
- if (morkCL.cds.Count > 0)
- {
- #region 修改为在下配方时选择使用哪个锅,这段程序不需要使用了。
- //var dishType = morkCL.cds.ElementAt(0).DishType;
- //var devieceType = EDeviceType.无;
- //if (dishType == Model.Recipe.EDishType.炒菜)
- //{
- // //如果任务队列里,炒锅1已经有任务了,就看炒锅2是否有任务,没任务就设置为炒锅2执行,如果两个锅都有任务则返回该次任务。
- // if (TaskList.ContainsKey(EDeviceType.炒锅1))
- // {
- // if (TaskList.ContainsKey(EDeviceType.炒锅2))
- // {
- // return;
- // }
- // else
- // { devieceType = EDeviceType.炒锅2; }
- // }
- // else
- // {
- // devieceType = EDeviceType.炒锅1;
- // }
- //}
- //else
- //{
- // devieceType = EDeviceType.压力锅;
- //}
-
- #endregion
-
- //这里判定主要是针对压力锅。
- //修改为炒锅和机器人不允许下单情况下,就不下单。
- if (!TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType) && GetFryPanAndRobotIsAuto(morkCL.cds.ElementAt(0).DeviceType))
- {
- if (morkCL.cds.TryDequeue(out ControlData cd))
- {
- //cd.DeviceType = devieceType;
- //cd.DeviceType = EDeviceType.炒锅1;
- TaskList.TryAdd(cd.DeviceType, new TaskServer());
- TaskList[cd.DeviceType].TaskName = $"{cd.DeviceType.ToString()}-{cd.Name}";
- TaskList[cd.DeviceType].RunTask = new Task(new Action(() => { FryingPanControl(cd.DeviceType, cd); }));
- TaskList[cd.DeviceType].RunTask.Start();
- }
- }
-
- }
- }
-
- #region 日志修改前
- //private async void FryingPanControl(EDeviceType et, ControlData cd)
- //{
- // DeviceProcessLogShow($"【{et}】开始执行-{cd.Name} 任务");
- // if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested)
- // return;
- // while (cd.ControlFuncs.Count > 0)
- // {
- // if (cd.ControlFuncs.TryDequeue(out FuncModel fm))
- // {
- // var device = (FryingPanServer)devices[et];
- // var robot = (RobotServer)devices[EDeviceType.机器人];
- // var otherDevice = (OtherServer)devices[EDeviceType.外部设备];
- // int index = (ushort)et - 1;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}。");
- // switch (fm.eFunc)
- // {
- // case EFunc.搅拌启动:
- // device.StirStartOrStop = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入搅拌频率-{fm.funcPars.ElementAt(0).ParValue.ToString()}HZ。");
- // device.MixingFrequencySet(fm.funcPars.ElementAt(0).ParValue.ToString());
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入搅拌频率-{fm.funcPars.ElementAt(0).ParValue.ToString()}HZ完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入开始搅拌。");
- // device.StirStartOrStop = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入开始搅拌完成。");
-
- // break;
- // case EFunc.搅拌停止:
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入停止搅拌。");
- // device.StirStartOrStop = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-写入停止搅拌完成。");
- // break;
- // case EFunc.加热启动:
- // device.HeatStartOrStop = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置加热挡位-【{fm.funcPars.ElementAt(0).ParValue.ToString()}】。");
- // device.HeatingGearSet(fm.funcPars.ElementAt(0).ParValue.ToString());
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置加热挡位完成,设置加热启动。");
-
- // device.HeatStartOrStop = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置加热启动完成。");
- // break;
- // case EFunc.加热停止:
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置加热停止。");
- // device.HeatStartOrStop = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置加热停止完成。");
- // break;
- // case EFunc.添加调料:
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-查找调料【{fm.funcPars.ElementAt(0).Id}】。");
- // var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
- // if (Seasoning != null)
- // {
- // device.FryingPanToSeasoningLoc = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅到调料投料位置。");
- // device.FryingPanToSeasoningLoc = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅到调料投料位置完成。");
-
- // //回到投料位置就复位。
-
- // Thread.Sleep(50);
- // device.FeedingSeasoningLocFB.Wait(Cts: TaskList[et].Cts);
- // device.FryingPanToSeasoningLoc = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-炒锅已到达调料投料位置。");
-
- // device.CuttingControl(Seasoning.Loc.ToString(), fm.funcPars.ElementAt(1).ParValue.ToString());
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-执行下料,下料位置:{Seasoning.Loc.ToString()},下料重量:【{fm.funcPars.ElementAt(1).ParValue.ToString()}】。");
- // }
- // else
- // {
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-查找调料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】调料。任务取消。");
- // TaskList[et].Cts.Cancel();
- // }
-
- // break;
- // case EFunc.添加主料:
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-查找主料【{fm.funcPars.ElementAt(0).Id}】。");
-
- // if (float.TryParse(fm.funcPars.ElementAt(1).ParValue.ToString(), out float weight))
- // {
- // //查找主料库位符合条件的物料库位,主要根据物料ID和物料重量查找。
- // var ingre_index = Array.FindIndex(Json<ItemStorageInfo>.Data.IngredientsStorage,
- // item => item.MaterialID == fm.funcPars.ElementAt(0).Id/* && item.Weight == weight*/);
- // if (ingre_index >= 0)
- // {
- // //device.CuttingControl(Seasoning.Loc.ToString(), fm.funcPars.ElementAt(1).ParValue.ToString());
- // var ingredientes = Json<ItemStorageInfo>.Data.IngredientsStorage[ingre_index];
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-执行下料,控制取{ingre_index + 1}库物料,下料名称:{ingredientes.Name.ToString()},下料重量:【{fm.funcPars.ElementAt(1).ParValue.ToString()}】。");
- // device.FryingPanHome = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(ingre_index + 1).ToString()}】,子任务【{et}】。");
-
- // robot.RobotTaskControl((ingre_index + 1).ToString(), et);
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(ingre_index + 1).ToString()}】,子任务【{et}】完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置。");
- // device.FryingPanHome = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置。");
- // device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置
- // device.FryingPanHome = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置完成。");
-
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待机器人到投料位置。");
- // robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置也就是发出倒料请求。
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待机器人到投料位置完成。");
-
- // //目前程序在炒锅在投料位置时,会自动发出允许倒料信息。
- // //DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置允许机器人开始投料。");
- // //robot.AllowPourVegetables(et);//允许机器人开始投料
- // //DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置允许机器人开始投料完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-开始等待机器人投料完成。");
- // robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-机器人投料完成。");
-
- // Json<ItemStorageInfo>.Data.IngredientsStorage[ingre_index] = new ItemStorage();
- // Json<ItemStorageInfo>.Save();
- // ActionManage.GetInstance.Send("RefreshItemStorage");
- // }
- // else
- // {
- // //TODO:暂定为直接取消任务,后期再说。
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-查找主料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】主料。任务取消。");
- // TaskList[et].Cts.Cancel();
- // }
- // }
- // break;
- // case EFunc.添加辅料:
- // MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
- // if (mb != null)
- // {
- // //先复位变量。防止上一次是异常结束,设为True时,不会响应。
- // device.FryingPanHome = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(mb.Loc + 12).ToString()}】,子任务【{et}】。");
- // robot.RobotTaskControl((mb.Loc + 12).ToString(), et);
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(mb.Loc + 12).ToString()}】,子任务【{et}】完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置。");
- // device.FryingPanHome = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置。");
- // device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置
- // device.FryingPanHome = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待机器人到投料位置。");
- // robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待机器人到投料位置完成。");
-
- // //DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置允许机器人开始投料。");
- // //robot.AllowPourVegetables(et);//允许机器人开始投料
- // //DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置允许机器人开始投料完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-开始等待机器人投料完成。");
- // robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-机器人投料完成。");
-
- // }
- // else
- // {
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-查找主料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】辅料。任务取消。");
- // TaskList[et].Cts.Cancel();
- // }
- // break;
- // case EFunc.炒锅回原点位:
- // device.FryingPanFeedingLoc = false;
- // device.FryingPanHome = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回原点。");
- // device.FryingPanHome = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅回原点完成。");
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待回原点完成。");
- // device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);
- // device.FryingPanHome = false;
-
- // break;
- // case EFunc.出餐启动:
-
- // device.DiningOutStart = false;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人取空盆。");
- // //TODO:暂时修改,后期优化。
- // while (true)
- // {
- // var emptyPanIndex = Array.FindIndex(otherDevice.BoxDetection, i => i == true);
- // if (emptyPanIndex >= 0)
- // {
- // robot.RobotTaskControl((21 + emptyPanIndex).ToString(), et);//取空盆
- // break;
- // }
- // await Task.Delay(3000);
- // DeviceProcessLogShow("无空盆,请添加空盆!");
- // }
- // //robot.RobotTaskControl("21", et);//取空盆
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置机器人取空盆完成,等待机器人到出菜位置。");
-
- // robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-机器人已到出餐位置,出餐启动。");
- // device.DiningOutStart = true;
-
- // device.OutDinningSlowDownFlag.Wait(Cts: TaskList[et].Cts);
- // robot.ModerateInPlace(et);
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-到达出餐减速位。");
-
- // device.OutDinningFinsh.Wait(Cts: TaskList[et].Cts);
- // robot.DiningOutComplete(et);
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-出餐完成。");
- // //回到投料位置就复位。
- // Thread.Sleep(50);
- // device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);
- // device.DiningOutStart = false;
- // break;
- // case EFunc.炒锅清洗:
- // device.FryingPanClear = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅清洗。");
- // device.FryingPanClear = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-炒锅清洗已写入。");
-
- // Thread.Sleep(500);
- // device.CleanFinish.Wait(Cts: TaskList[et].Cts);
- // device.FryingPanClear = false;
- // break;
- // case EFunc.炒锅回调料投料位置:
- // device.FryingPanToSeasoningLoc = false;
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅到调料投料位置。");
- // device.FryingPanToSeasoningLoc = true;
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置炒锅到调料投料位置完成。");
-
- // //回到投料位置就复位。
-
- // Thread.Sleep(50);
- // device.FeedingSeasoningLocFB.Wait(Cts: TaskList[et].Cts);
- // device.FryingPanToSeasoningLoc = false;
- // break;
- // case EFunc.去指定炒制位:
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置去指定炒制位。");
- // device.SetStirFryingLoc(fm.funcPars.ElementAt(0).ParValue.ToString());
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-设置去指定炒制位【{fm.funcPars.ElementAt(0).ParValue.ToString()}】完成。");
- // break;
- // case EFunc.炒制:
-
- // if (int.TryParse(fm.funcPars.ElementAt(0).ParValue.ToString(), out int time))
- // {
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-等待炒制【{time}】秒。");
- // Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token);
- // }
-
- // DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-炒制完成。");
- // break;
- // default:
- // break;
- // }
- // }
- // }
- // DeviceProcessLogShow($"【{et}】任务-{cd.Name} 执行完成");
- //}
- #endregion
-
- #region 炒锅流程控制日志修改后
- private async void FryingPanControl(EDeviceType et, ControlData cd)
- {
- DeviceProcessLogShow($"【{et}】开始执行-{cd.Name} 任务");
- if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested)
- return;
- while (cd.ControlFuncs.Count > 0 && !TaskList[et].Cts.IsCancellationRequested)
- {
- if (cd.ControlFuncs.TryDequeue(out FuncModel fm))
- {
- var device = (FryingPanServer)devices[et];
- var robot = (RobotServer)devices[EDeviceType.机器人];
- var otherDevice = (OtherServer)devices[EDeviceType.外部设备];
- int index = (ushort)et - 1;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}。");
- try
- {
- switch (fm.eFunc)
- {
- #region 搅拌启动与停止
-
- case EFunc.搅拌启动:
- device.StirStartOrStop = false;
-
- device.MixingFrequencySet(fm.funcPars.ElementAt(0).ParValue.ToString());
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-写入搅拌频率-{fm.funcPars.ElementAt(0).ParValue.ToString()}HZ完成。");
- await Task.Delay(400);
- device.StirStartOrStop = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-写入开始搅拌完成。");
-
- break;
- case EFunc.搅拌停止:
- device.StirStartOrStop = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-写入停止搅拌完成。");
- break;
-
- #endregion
-
- #region 加热启动与停止
-
- case EFunc.加热启动:
- device.HeatStartOrStop = false;
- await Task.Delay(400);
-
- device.HeatingGearSet(fm.funcPars.ElementAt(0).ParValue.ToString());
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置加热挡位-【{fm.funcPars.ElementAt(0).ParValue.ToString()}】完成,等待设置加热启动。");
-
- device.HeatStartOrStop = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置加热启动完成。");
- break;
- case EFunc.加热停止:
- device.HeatStartOrStop = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置加热停止完成。");
- break;
- #endregion
-
- #region 添加调料
- case EFunc.添加调料:
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-查找调料【{fm.funcPars.ElementAt(0).Id}】。");
- var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
- if (Seasoning != null)
- {
- device.FryingPanToSeasoningLoc = false;
- await Task.Delay(400);
-
- device.FryingPanToSeasoningLoc = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅到调料投料位置完成,等待炒锅到达调料投料位置。");
-
- //回到投料位置就复位。
-
- await Task.Delay(400);
-
- device.FeedingSeasoningLocFB.Wait(Cts: TaskList[et].Cts);
- device.FryingPanToSeasoningLoc = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒锅已到达调料投料位置。");
-
- device.CuttingControl(Seasoning.Loc.ToString(), fm.funcPars.ElementAt(1).ParValue.ToString(), TaskList[et].Cts);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-执行下料,下料位置:{Seasoning.Loc.ToString()},下料重量:【{fm.funcPars.ElementAt(1).ParValue.ToString()}】。");
-
- //去炒制位
- string stirFryLoc = fm.funcPars.ElementAt(2).ParValue.ToString();
- GoStirFryLoc(stirFryLoc);
-
- //炒制
- if (int.TryParse(fm.funcPars.ElementAt(3).ParValue.ToString(), out int time1))
- {
- StirFry(time1);
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"任务【{cd.Name}】查找调料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】调料,任务即将取消。", DialogType.Warning);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-查找调料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】调料。任务取消。");
- TaskList[et].Cts.Cancel();
- }
-
- break;
- #endregion
-
- #region 添加主料
- case EFunc.添加主料:
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-查找主料【{fm.funcPars.ElementAt(0).Id}】。");
-
- if (float.TryParse(fm.funcPars.ElementAt(1).ParValue.ToString(), out float weight))
- {
- robot.IsIdle.Wait(Cts: TaskList[et].Cts);
- //查找主料库位符合条件的物料库位,主要根据物料ID和物料重量查找。
- var ingre_index = Array.FindIndex(Json<ItemStorageInfo>.Data.IngredientsStorage,
- item => item.MaterialID == fm.funcPars.ElementAt(0).Id/* && item.Weight == weight*/);
- if (ingre_index >= 0)
- {
- var ingredientes = Json<ItemStorageInfo>.Data.IngredientsStorage[ingre_index];
-
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-执行下料,控制取{ingre_index + 1}库物料,下料名称:{ingredientes.Name.ToString()},下料重量:【{fm.funcPars.ElementAt(1).ParValue.ToString()}】。");
- device.FryingPanHome = false;
-
-
- robot.RobotTaskControl((ingre_index + 1).ToString(), et);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(ingre_index + 1).ToString()}】,子任务【{et}】完成。");
- await Task.Delay(400);
-
- device.FryingPanHome = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置完成,等待炒锅回到主料辅料投料位置");
-
- device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置
- await Task.Delay(400);
-
- device.FryingPanHome = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置完成。");
-
-
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-等待机器人到投料位置。");
- robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置也就是发出倒料请求。
-
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-机器人已到达投料位置,等待机器人投料完成。");
- robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-机器人投料完成。");
-
- Json<ItemStorageInfo>.Data.IngredientsStorage[ingre_index] = new ItemStorage();
- Json<ItemStorageInfo>.Save();
- ActionManage.GetInstance.Send("RefreshItemStorage");
-
- //去炒制位
- string stirFryLoc = fm.funcPars.ElementAt(2).ParValue.ToString();
- GoStirFryLoc(stirFryLoc);
-
- //炒制
- if (int.TryParse(fm.funcPars.ElementAt(3).ParValue.ToString(), out int time2))
- {
- StirFry(time2);
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"任务【{cd.Name}】查找主料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】主料,任务即将取消。", DialogType.Warning);
-
- //TODO:暂定为直接取消任务,后期再说。
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-查找主料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】主料。任务取消。");
- TaskList[et].Cts.Cancel();
- }
- }
- break;
- #endregion
-
- #region 添加辅料
- case EFunc.添加辅料:
- #region 根据配置文件选择每个炒锅的最大最小辅料位置,暂时没使用。
- var minloc = 1;
- var maxloc = 8;
- if (morkCL.IsUseSplitStorage)
- {
- if (et == EDeviceType.炒锅1)
- {
- minloc = Json<ConnectPar>.Data.FryPanAccessoriesMin_1;
- maxloc = Json<ConnectPar>.Data.FryPanAccessoriesMax_1;
- }
- else if (et == EDeviceType.炒锅2)
- {
- minloc = Json<ConnectPar>.Data.FryPanAccessoriesMin_2;
- maxloc = Json<ConnectPar>.Data.FryPanAccessoriesMax_2;
- }
- }
- else
- {
- minloc = 1;
- maxloc = 8;
- }
-
- #endregion
-
- MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Loc >= minloc && p.Loc <= maxloc && p.Id == fm.funcPars.ElementAt(0).Id);
- if (mb != null)
- {
- robot.IsIdle.Wait(Cts: TaskList[et].Cts);
- //先复位变量。防止上一次是异常结束,设为True时,不会响应。
- device.FryingPanHome = false;
-
- robot.RobotTaskControl((mb.Loc + 12).ToString(), et);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置机器人任务【{(mb.Loc + 12).ToString()}】,子任务【{et}】完成。");
-
- await Task.Delay(400);
- device.FryingPanHome = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅回投料位置完成,开始等待炒锅到投料位置。");
-
- device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置
- await Task.Delay(400);
- device.FryingPanHome = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-等待炒锅到投料位置完成,等待机器人到投料位置。");
-
- robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-机器人到达投料位置完成,开始等待机器人投料完成。");
-
- robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-机器人投料完成。");
-
- //去炒制位
- string stirFryLoc = fm.funcPars.ElementAt(1).ParValue.ToString();
- GoStirFryLoc(stirFryLoc);
-
- //炒制
- if (int.TryParse(fm.funcPars.ElementAt(2).ParValue.ToString(), out int time3))
- {
- StirFry(time3);
- }
-
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"任务【{cd.Name}】查找辅料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】辅料,任务即将取消。", DialogType.Warning);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-查找辅料失败,未查找到【{fm.funcPars.ElementAt(0).Id}】辅料。任务取消。");
- TaskList[et].Cts.Cancel();
- }
- break;
- #endregion
- case EFunc.炒锅回原点位:
- GoHome();
-
- break;
-
- #region 出餐启动
- case EFunc.出餐启动:
-
- device.DiningOutStart = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置机器人取空盆。");
-
- robot.IsIdle.Wait(Cts: TaskList[et].Cts);
- //TODO:暂时修改,后期优化。
- while (!TaskList[et].Cts.IsCancellationRequested)
- {
- var emptyPanIndex = Array.FindIndex(otherDevice.BoxDetection, i => i == true);
- if (emptyPanIndex >= 0)
- {
- robot.RobotTaskControl((21 + emptyPanIndex).ToString(), et);//取空盆
- break;
- }
- await Task.Delay(3000);
- DeviceProcessLogShow("无空盆,请添加空盆!");
- }
- //robot.RobotTaskControl("21", et);//取空盆
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置机器人取空盆完成,等待机器人到出菜位置。");
-
- robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-机器人已到出餐位置,出餐启动。");
- await Task.Delay(400);
- device.DiningOutStart = true;
-
- device.OutDinningSlowDownFlag.Wait(Cts: TaskList[et].Cts);
- robot.ModerateInPlace(et);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-到达出餐减速位。");
-
- device.OutDinningFinsh.Wait(Cts: TaskList[et].Cts);
- robot.DiningOutComplete(et);
-
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-出餐完成。");
- //回到投料位置就复位。
- Thread.Sleep(50);
- device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);
- await Task.Delay(400);
- device.DiningOutStart = false;
- break;
- #endregion
- #region 炒锅清洗--基本没用
- case EFunc.炒锅清洗:
- device.FryingPanClear = false;
-
- //DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅清洗。");
- await Task.Delay(400);
- device.FryingPanClear = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒锅清洗已写入,等待炒锅清洗完成。");
-
- Thread.Sleep(500);
- device.CleanFinish.Wait(Cts: TaskList[et].Cts);
- await Task.Delay(400);
- device.FryingPanClear = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒锅清洗完成。");
- break;
- #endregion
-
- #region
- case EFunc.去指定炒制位:
- //DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置去指定炒制位。");
- string loc = fm.funcPars.ElementAt(0).ParValue.ToString();
- GoStirFryLoc(loc);
-
-
- break;
- case EFunc.炒制:
-
- if (int.TryParse(fm.funcPars.ElementAt(0).ParValue.ToString(), out int time))
- {
- StirFry(time);
- }
-
- break;
- #endregion
- default:
- break;
- }
-
- #region 回原点
- void GoHome()
- {
- device.FryingPanFeedingLoc = false;
- device.FryingPanHome = false;
- //DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅回原点。");
- Task.Delay(400).Wait();
- device.FryingPanHome = true;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置炒锅回原点完成,等待炒锅回原点。");
-
- //DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-等待回原点完成。");
- device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);
- Task.Delay(400).Wait();
- device.FryingPanHome = false;
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒锅回原点完成。");
- }
- #endregion
-
- #region 去指定炒制位
- //去指定炒制位
- void GoStirFryLoc(string loc)
- {
- device.SetStirFryingLoc(loc, TaskList[et].Cts);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-设置去指定炒制位【{fm.funcPars.ElementAt(0).ParValue.ToString()}】完成。");
-
- //TODO:根据情况看是否需要等待反馈变量。
- //device.StirFryingLocFB[int.Parse(fm.funcPars.ElementAt(0).ParValue.ToString())].Wait();
- //DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒锅到达炒制位【{fm.funcPars.ElementAt(0).ParValue.ToString()}】。");
- }
- #endregion
-
- #region 炒制延时
- //炒制延时。
- void StirFry(int time)
- {
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-等待炒制【{time}】秒。");
-
- Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token);
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务执行-{fm.eFunc.ToString()}-炒制完成。");
- }
- #endregion
-
- }
- catch (TaskCanceledException)
- {
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务被取消。");
- }
- catch (OperationCanceledException)
- {
- DeviceProcessLogShow($"{cd.Name}-【{et}#】任务被手动取消。");
- }
- }
- }
- DeviceProcessLogShow($"【{et}】任务-{cd.Name} 执行完成");
- TaskList[et].IsComplete = true;
- }
- #endregion
-
- public override void ReadData()
- {
- if (propertyInfos is null || propertyInfos.Count == 0)
- {
- propertyInfos = morkCL.GetType().GetProperties().ToList();
- }
- morkCL.RecipeQueueCount = morkCL.cds.Count;
- morkCL.FryingPanTaskCount_1 = morkCL.cds.Count(data => data.DeviceType == EDeviceType.炒锅1);
- morkCL.FryingPanTaskCount_2 = morkCL.cds.Count(data => data.DeviceType == EDeviceType.炒锅2);
-
- var fryingPan1 = (FryingPanServer)devices[EDeviceType.炒锅1];
- var fryingPan2 = (FryingPanServer)devices[EDeviceType.炒锅2];
- var robot = (RobotServer)devices[EDeviceType.机器人];
- var pressureCooker = (PressureCookerServer)devices[EDeviceType.压力锅];
- var otherDevice = (OtherServer)devices[EDeviceType.外部设备];
-
- alarm.EStop1 = fryingPan1.EStopAlarm;
- alarm.FryingPanFowardLimit1 = fryingPan1.FryingPanFowardLimit;
- alarm.FryingPanReverseLimit1 = fryingPan1.FryingPanReverseLimit;
- alarm.FryingPanEncoderCommError1 = fryingPan1.FryingPanEncoderCommError;
- alarm.StirMotorCommError1 = fryingPan1.StirMotorCommError;
- alarm.RollingMotorCommError1 = fryingPan1.RollingMotorCommError;
- alarm.StirMotorError1 = fryingPan1.StirMotorErrorCode != "无故障" ? true : false;
- alarm.TurnMotorError1 = fryingPan1.TurnMotorErrorCode != "无故障" ? true : false;
-
- alarm.EStop2 = fryingPan2.EStopAlarm;
- alarm.FryingPanFowardLimit2 = fryingPan2.FryingPanFowardLimit;
- alarm.FryingPanReverseLimit2 = fryingPan2.FryingPanReverseLimit;
- alarm.FryingPanEncoderCommError2 = fryingPan2.FryingPanEncoderCommError;
- alarm.StirMotorCommError2 = fryingPan2.StirMotorCommError;
- alarm.RollingMotorCommError2 = fryingPan2.RollingMotorCommError;
- alarm.StirMotorError2 = fryingPan2.StirMotorErrorCode != "无故障" ? true : false;
- alarm.TurnMotorError2 = fryingPan2.TurnMotorErrorCode != "无故障" ? true : false;
-
- //这是字段。直接赋值
- morkCL.FeedingSeasoningLocFB1 = fryingPan1.FeedingSeasoningLocFB;
- morkCL.FeedingSeasoningLocFB2 = fryingPan2.FeedingSeasoningLocFB;
-
- morkCL.FeedingLocFB1 = fryingPan1.FeedingLocFB;
- morkCL.FeedingLocFB2 = fryingPan2.FeedingLocFB;
-
- morkCL.CleanFinish1 = fryingPan1.CleanFinish;
- morkCL.CleanFinish2 = fryingPan2.CleanFinish;
-
- morkCL.OutDinningFinsh1 = fryingPan1.OutDinningFinsh;
- morkCL.OutDinningFinsh2 = fryingPan2.OutDinningFinsh;
-
- morkCL.OutDinningSlowDownFlag1 = fryingPan1.OutDinningSlowDownFlag;
- morkCL.OutDinningSlowDownFlag2 = fryingPan2.OutDinningSlowDownFlag;
-
- morkCL.BoxDetection = otherDevice.BoxDetection;
- morkCL.IsIdle = robot.IsIdle;
-
- #if !FORMAL
- if (fryingPan1.FeedingLocFB)
- {
- robot.AllowPourVegetables(EDeviceType.炒锅1);
- }
- else
- {
- robot.DisablePourVegetables(EDeviceType.炒锅1);
- }
-
- if (fryingPan2.FeedingLocFB)
- {
- robot.AllowPourVegetables(EDeviceType.炒锅2);
- }
- else
- {
- robot.DisablePourVegetables(EDeviceType.炒锅2);
- }
-
-
- foreach (var property in propertyInfos)
- {
- var att = property.GetCustomAttribute<VariableMonitorAttribute>();
- if (att != null)
- {
- if (att.Notes.Contains("1号炒锅"))
- {
- var p = fryingPan1.GetType().GetProperty(property.Name.TrimEnd('1'));
- if (p != null)
- {
- property.SetValue(morkCL, p.GetValue(fryingPan1));
- }
-
- }
- else if (att.Notes.Contains("2号炒锅"))
- {
- var p = fryingPan2.GetType().GetProperty(property.Name.TrimEnd('2'));
- if (p != null)
- {
- property.SetValue(morkCL, p.GetValue(fryingPan2));
- }
-
- }
- else if (att.Notes.Contains("机器人"))
- {
- var p = robot.GetType().GetProperty(property.Name);
- if (p != null)
- {
- property.SetValue(morkCL, p.GetValue(robot));
- }
- }
- else if (att.Notes.Contains("电子秤"))
- {
- var p = otherDevice.GetType().GetProperty(property.Name);
- if (p != null)
- {
- var res = p.GetValue(otherDevice);
- property.SetValue(morkCL, res);
- if (p.Name == "CurrentWeight")
- {
- ActionManage.GetInstance.Send(res, "SendCurrentWeight");
- }
- }
- }
- else if (att.Notes.Contains("高压锅"))
- {
- var p = pressureCooker.GetType().GetProperty(property.Name);
- if (p != null)
- {
- property.SetValue(morkCL, p.GetValue(pressureCooker));
- }
- }
- }
- }
-
- #endif
- }
-
- public override void ResetProgram()
- {
- morkCL = null;
- morkCL = new GVL_MorkCL();
- }
-
- public override void SimOrder()
- {
- }
-
- public override void Stop()
- {
- }
- private bool GetFryPanAndRobotIsAuto(EDeviceType fryPan)
- {
- //目前拿不到机器人的远程状态,只能拿到炒锅的。
- var device = (FryingPanServer)devices[fryPan];
- var robot = (RobotServer)devices[EDeviceType.机器人];
- return device.InitComplete && device.StatusMode && device.EStop && robot.RemoteMode;
-
- }
- void ManualActionRegiester()
- {
- //主料入库委托。
- ActionManage.GetInstance.Register((object o) =>
- {
- if (!morkCL.CanItemStorage)
- {
- MessageNotify.GetInstance.ShowDialog("当前有炒菜任务正在排队,为避免影响菜品口味,不可入库,请稍后再试。", DialogType.Warning);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败,当前正在制作菜品。");
- return;
- }
- var robot = (RobotServer)devices[EDeviceType.机器人];
- if (robot.IsIdle == false)
- {
- MessageNotify.GetInstance.ShowDialog("当前机器人未在空闲状态,稍后再试。", DialogType.Warning);
- return;
- }
- TaskManage.GetInstance.Start(() =>
- {
- if (o != null && o is IngredientsTB ingredients)
- {
-
- var index = Array.FindIndex(Json<ItemStorageInfo>.Data.IngredientsStorage, i => i.IsEmploy == false);
- if (index >= 0)
- {
- if (!MessageNotify.GetInstance.ShowDialog($"请确认库位【{index + 1}】上无物品,否则可能会造成碰撞事故!", DialogType.Warning))
- {
-
- DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index + 1}]入库失败,未确认库位无异物。");
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料{ingredients.Name}入库失败。");
- });
- return;
- }
-
- var item = Json<ItemStorageInfo>.Data.IngredientsStorage[index];
-
- item.MaterialID = ingredients.Id;
- item.Name = ingredients.Name;
- item.IsEmploy = true;
- item.Weight = ((OtherServer)devices[EDeviceType.外部设备]).CurrentWeight;
-
- var loc = (index + 1).ToString();
- #if !FORMAL
-
- robot.WarehousingControl(loc, null);
- DeviceProcessLogShow($"已下发机器人物料入{loc}号库任务,等待机器人入库操作完成");
- robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait();
- #endif
- Json<ItemStorageInfo>.Save();
-
- ActionManage.GetInstance.Send("RefreshItemStorage");
-
- DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index + 1}]入库成功。");
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "入库成功", $"物料{ingredients.Name}入库成功。");
-
- });
- return;
- }
- else
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料库已满。");
- });
- }
- }
- else
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败。");
- });
- }
- }, "ItemStorageTask");
-
- }, NotifyTopic.ItemStorage, true);
-
- ActionManage.GetInstance.Register(() =>
- {
- ActionManage.GetInstance.Send("SystemIsBusy").OnFinally(isBusy =>
- {
- if (isBusy.IsSuccess == true)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。");
- return;
- }
- Task.Run(() =>
- {
- var robot = (RobotServer)devices[EDeviceType.机器人];
- robot.GoCleanLoc();
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "设置成功", $"设置机器人去清洗位置成功。");
- });
-
- robot.AtCleanLoc.Wait();
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"机器人已到达清洗位置。");
- });
- });
- });
-
- //if (ActionManage.GetInstance.SendResult("SystemIsBusy") is bool isBusy)
- //{
- // if (isBusy == true)
- // {
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。");
- // return;
- // }
- // Task.Run(() =>
- // {
- // var robot = (RobotServer)devices[EDeviceType.机器人];
- // robot.GoCleanLoc();
- // Application.Current.Dispatcher.Invoke(() =>
- // {
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "设置成功", $"设置机器人去清洗位置成功。");
- // });
-
- // robot.AtCleanLoc.Wait();
- // Application.Current.Dispatcher.Invoke(() =>
- // {
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"机器人已到达清洗位置。");
- // });
- // });
-
- //}
- }, "RobotGoCleanLoc", true);
-
- ActionManage.GetInstance.Register(() =>
- {
- Task.Run(() =>
- {
- var robot = (RobotServer)devices[EDeviceType.机器人];
- bool isSuccuess = robot.SendCleanFinish();
- if (isSuccuess)
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "通知成功", $"通知机器人清洗完成成功。");
- });
- }
-
- });
- }, "RobotCleanFinish", true);
-
- #region 暂时弃用
- ActionManage.GetInstance.Register((object location) =>
- {
- var loc = location.ToString();
- if (!String.IsNullOrEmpty(loc) && loc.Length >= 0)
- {
- var robot = (RobotServer)devices[EDeviceType.机器人];
- //Thread.Sleep(5000);
- robot.WarehousingControl(loc, null);
- //会卡死。
- robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait();
- }
- }, "ItemStorage", true);
- #endregion
-
- ActionManage.GetInstance.Register((object[] o) =>
- {
- if (o is not null && o is object[] para)
- {
- var device = (EDeviceType)Enum.Parse(typeof(EDeviceType), para[0].ToString());
- var channelIndex = para[1].ToString();
- var demandValue = para[2].ToString();
- ((FryingPanServer)devices[device]).CuttingControl(channelIndex, demandValue, null);
- }
- }, "DeviceCuttingControl", true);
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o is not null)
- {
- var device = (EDeviceType)Enum.Parse(typeof(EDeviceType), o.ToString());
- if (TaskList.ContainsKey(device))
- {
- TaskList[device].Cts.Cancel();
- DeviceProcessLogShow($"取消{device}当前任务成功。");
- }
- else
- {
- DeviceProcessLogShow($"[{device}]当前无任务。");
- }
- }
-
- }, "CancelFryPanTask", true);
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o is not null)
- {
- var device = (EDeviceType)Enum.Parse(typeof(EDeviceType), o.ToString());
- //TODO : 把所有属于该炒锅的任务全部删除。
- }
-
- }, "ClearFryPanTask", true);
-
- ActionManage.GetInstance.Register(() =>
- {
- //电子秤去皮
- var weghier = (OtherServer)devices[EDeviceType.外部设备];
- if (weghier.WeigherTare())
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "去皮成功", $"电子秤除皮操作成功。");
- });
- DeviceProcessLogShow($"电子秤除皮操作成功。");
- }
- else
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "去皮失败", $"电子秤除皮操作失败。");
- });
- DeviceProcessLogShow($"电子秤除皮操作失败。");
- }
-
-
- }, "WeighrTare", true);
-
- ActionManage.GetInstance.Register(() =>
- {
- //电子秤置零
- var weghier = (OtherServer)devices[EDeviceType.外部设备];
- if (weghier.WeigherZero())
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "置零成功", $"电子秤置零操作成功。");
- });
- DeviceProcessLogShow($"电子秤置零操作成功。");
- }
- else
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "置零失败", $"电子秤置零操作失败。");
- });
- DeviceProcessLogShow($"电子秤置零操作失败。");
- }
-
- }, "WeighrZero", true);
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o != null && o is WriteModel<bool> write)
- {
- if (!TaskList.ContainsKey(write.DeviceType))
- {
- devices[write.DeviceType].WriteValue<bool>(write.Address, write.Value);
- DeviceProcessLogShow($"设备[{write.DeviceType}]--手动写入地址[{write.Address}],值[{write.Value}]");
- }
- }
- }, "WriteBool", true);
-
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o != null && o is WriteModel<ushort> write)
- {
- if (!TaskList.ContainsKey(write.DeviceType))
- {
- devices[write.DeviceType].WriteValue<ushort>(write.Address, write.Value);
- DeviceProcessLogShow($"设备[{write.DeviceType}]--手动写入地址[{write.Address}],值[{write.Value}]");
- }
- //else
- //{
- // //MessageNotify.GetInstance.ShowDialog("当前有炒菜任务,不可手动操作,请稍后再试。", DialogType.Warning);
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "操作失败", $"手动操作失败,当前正在制作菜品。");
- // return;
- //}
- }
- }, "WriteUshort", true);
-
- ActionManage.GetInstance.Register(frypanIsIdle, "GetDeviceIsIdle", true);
-
- ActionManage.GetInstance.Register(() =>
- {
- var robot = (RobotServer)devices[EDeviceType.机器人];
- if (robot.InitVariable())
- {
- Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"复位所有由上位机下发至机器人的变量成功。"); });
- DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量成功。");
- }
- else
- {
- Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"复位所有由上位机下发至机器人的变量失败。"); });
- DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量失败。");
- }
- }, "InitRobotAllVar", true);
-
-
- ActionManage.GetInstance.Register<bool>(() =>
- {
- if (morkCL.RecipeQueueCount > 0 || morkCL.FryingPanTaskCount_1 > 0 || morkCL.FryingPanTaskCount_2 > 0)
- {
- return true;
- }
- return false;
- }, "SystemIsBusy", true);
- }
-
- Func<object, object> frypanIsIdle => (o) =>
- {
- if (o is not null)
- {
- var device = (EDeviceType)Enum.Parse(typeof(EDeviceType), o.ToString());
- if (!TaskList.ContainsKey(device))
- {
- return true;
- }
- }
- return false;
- };
-
- }
- }
|