|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
-
- 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 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();
-
- /// <summary>
- /// 炒锅1任务队列。
- /// </summary>
- ConcurrentQueue<TaskServer> FryingPan1TaskLsit { get; set; } = new();
- /// <summary>
- /// 炒锅2任务队列。
- /// </summary>
- ConcurrentQueue<TaskServer> FryingPan2TaskLsit { get; set; } = new();
- /// <summary>
- /// 高压锅任务队列。
- /// </summary>
- ConcurrentQueue<TaskServer> PressureCookerTaskLsit { get; set; } = new();
- 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());
-
- #if !FORMAL
- devices[EDeviceType.炒锅1].Init(Json<ConnectPar>.Data.FryingPanIP1);
- devices[EDeviceType.炒锅2].Init(Json<ConnectPar>.Data.FryingPanIP2);
- devices[EDeviceType.机器人].Init(Json<ConnectPar>.Data.RobotIP);
- //devices[EDeviceType.压力锅].Init(Json<ConnectPar>.Data.PressureCookerIP);
- 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;
- //ActionManage.GetInstance.Send("RefreshCanItemStorage", true);
- }
- else
- {
- morkCL.CanItemStorage = false;
- //ActionManage.GetInstance.Send("RefreshCanItemStorage", 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))
- {
- 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();
- }
- }
-
- }
- }
-
- 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} 执行完成");
- }
-
-
-
- public override void ReadData()
- {
-
- var propertyInfos = morkCL.GetType().GetProperties();
-
- 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.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("SendCurrentWeight", res);
- }
- }
- }
- 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()
- {
- }
-
- void ManualActionRegiester()
- {
- //主料入库委托。
- ActionManage.GetInstance.Register((object o) =>
- {
- if (!morkCL.CanItemStorage)
- {
- MessageNotify.GetInstance.ShowDialog("当前有炒菜任务正在排队,为避免影响菜品口味,不可入库,请稍后再试。", DialogType.Warning);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败,当前正在制作菜品。");
- 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)
- {
- 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();
- //var robot = (RobotServer)devices[EDeviceType.机器人];
- //robot.WarehousingControl(loc);
- //robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait();
-
- Json<ItemStorageInfo>.Save();
-
- ActionManage.GetInstance.Send("RefreshItemStorage");
-
- DeviceProcessLogShow($"物料{ingredients.Name},ID:[{ingredients.Id}]入库成功。");
- 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);
-
- #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);
- //会卡死。
- robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait();
- }
- }, "ItemStorage", true);
- #endregion
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o!=null && o is WriteModel<bool> write)
- {
- 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)
- {
- devices[write.DeviceType].WriteValue<ushort>(write.Address, write.Value);
- DeviceProcessLogShow($"设备[{write.DeviceType}]--手动写入地址[{write.Address}],值[{write.Value}]");
- }
- }, "WriteUshort", true);
- }
- }
- }
|