From 64a1fbbc3f8f6d5b6d1edb701b0b39dd8e3aa8c7 Mon Sep 17 00:00:00 2001 From: taoye Date: Wed, 30 Mar 2022 18:02:27 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.MORKD/Control_MORKD.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index c145382..07a156f 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -405,6 +405,7 @@ namespace HBLConsole.MORKD { if (mORKD.CookNoodleCompleteTask.Count > 0) { + RevertOutNoodleQueue(); //交换出面台位顺序 2022.3.30 string id = mORKD.CookNodelId[mORKD.CookNoodleCompleteTask.ElementAt(0)]; int index = mORKD.AxisAllowInvertedNoodleID.GetIndex(id); if (index >= 0 && index <= 1) @@ -431,6 +432,33 @@ namespace HBLConsole.MORKD mORKD.RobotTaskInterlock = mORKD.CookNoodleCompleteTask.Count > 0 && (mlCount >= 2 || mORKD.RBTakeNoodleTask.Count == 0); } + + public int tCount = 0; + /// + /// 交换出面台位优先级 + /// + void RevertOutNoodleQueue() + { + string id = mORKD.CookNodelId[mORKD.CookNoodleCompleteTask.ElementAt(0)]; + int index = mORKD.AxisAllowInvertedNoodleID.GetIndex(id); + if (index == -1) + { + tCount++; + if (tCount == 100) + { + //交换取面位置 + mORKD.CookNoodleCompleteTask.TryDequeue(out ushort result2); + mORKD.CookNoodleCompleteTask.Enqueue(result2); + tCount = 0; + } + } + else + { + tCount = 0; + } + } + + /// /// 取浇头控制 /// From fbaf84612003a0862799d168a06b20650e376e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 30 Mar 2022 18:02:53 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Abstract/ControlAbstract.cs | 21 ++ .../{MessageServer => AbstractServer}/Base.cs | 27 +-- .../AbstractServer/ControlBase.cs | 61 ++++++ HBLConsole.Factory/SimpleFactory.cs | 36 +++- HBLConsole.Interface/IControl.cs | 1 - HBLConsole.MORKD/Control_MORKD.cs | 166 ++++++++-------- HBLConsole.MORKIC/Control_MORKIC.cs | 53 +++--- HBLConsole.MORKS/Control_MORKS.cs | 180 ++++++++---------- HBLConsole.MORKS/GVL_MORKS.cs | 29 +++ HBLConsole.Model/DeviceData.cs | 14 ++ HBLConsole.Service/RTrig.cs | 7 +- HBLConsole.Service/TTrig.cs | 39 ++++ 12 files changed, 390 insertions(+), 244 deletions(-) create mode 100644 HBLConsole.Abstract/ControlAbstract.cs rename HBLConsole.Business/{MessageServer => AbstractServer}/Base.cs (86%) create mode 100644 HBLConsole.Business/AbstractServer/ControlBase.cs create mode 100644 HBLConsole.Model/DeviceData.cs create mode 100644 HBLConsole.Service/TTrig.cs diff --git a/HBLConsole.Abstract/ControlAbstract.cs b/HBLConsole.Abstract/ControlAbstract.cs new file mode 100644 index 0000000..ff9157c --- /dev/null +++ b/HBLConsole.Abstract/ControlAbstract.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Abstract +{ + public abstract class ControlAbstract + { + public abstract void Init(); + public Action ReadDataAction { get; set; } + public Action MainAction { get; set; } + + public abstract void ReadData(); + + public abstract void Main(); + + public abstract void ResetProgram(); + } +} diff --git a/HBLConsole.Business/MessageServer/Base.cs b/HBLConsole.Business/AbstractServer/Base.cs similarity index 86% rename from HBLConsole.Business/MessageServer/Base.cs rename to HBLConsole.Business/AbstractServer/Base.cs index 889b928..5303b82 100644 --- a/HBLConsole.Business/MessageServer/Base.cs +++ b/HBLConsole.Business/AbstractServer/Base.cs @@ -13,7 +13,7 @@ using BPA.Utility; using Newtonsoft.Json; using HBLConsole.Communication; -namespace HBLConsole.Business.MessageServer +namespace HBLConsole.Business.AbstractServer { public class Base : AbstractMessageServer { @@ -109,33 +109,8 @@ namespace HBLConsole.Business.MessageServer MessageLog.GetInstance.Show("接收到辅料信息"); ActionManage.GetInstance.Send("recipeBom"); } - //WritePlcData(); } - /// - /// 写配方数据到PLC - /// - //private void WritePlcData() - //{ - // return; - // //写配方数据到PLC - // List recipeBoms = new List(); - // foreach (var item in Json.Data.recipeBoms.RecipeIds) - // { - // foreach (var rec in item.Recipes) - // { - // recipeBoms.Add((ushort)rec); - // } - // } - // if (recipeBoms.Count > 0) - // { - // if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray())) - // { - // MessageLog.GetInstance.Show("成功写入配方数据"); - // } - // } - //} - /// /// 订单状态改变 /// diff --git a/HBLConsole.Business/AbstractServer/ControlBase.cs b/HBLConsole.Business/AbstractServer/ControlBase.cs new file mode 100644 index 0000000..7452b9c --- /dev/null +++ b/HBLConsole.Business/AbstractServer/ControlBase.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using HBLConsole.Abstract; +using HBLConsole.Service; +using HBLConsole.Factory; +using HBLConsole.Model; + +namespace HBLConsole.Business.AbstractServer +{ + public class ControlBase : ControlAbstract + { + public override void Init() + { + Main(); + ReadData(); + ResetProgram(); + } + + public override void Main() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (MainAction != null) MainAction(); + Thread.Sleep(100); + }), "MainTask"); + } + + public override void ReadData() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (ReadDataAction != null) ReadDataAction(); + Thread.Sleep(100); + }), "ReadPLCData"); + } + + public override void ResetProgram() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) + { + ThreadManage.GetInstance.StopTask("MainTask", new Action(() => + { + ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => + { + SimpleFactory.GetInstance.CreateGvl(); + ReadData(); + Main(); + })); + })); + } + Thread.Sleep(10); + }), "ResetProgram"); + } + } +} diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index 24dd314..997bcec 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -15,7 +15,7 @@ namespace HBLConsole.Factory private volatile static SimpleFactory _Instance; public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory()); - private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } + //private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer()); private AbstractMessageServer _GetAbsMessageServer; @@ -23,6 +23,7 @@ namespace HBLConsole.Factory private string DeviceType => GeneralConfig.DeviceType.ToString(); private object debugControl; + private string GvlName = string.Empty; public void MqttMessage(IMessage message) { @@ -59,19 +60,43 @@ namespace HBLConsole.Factory return res; } + public void CreateGvl() + { + string NameSpace = $"HBLConsole.{DeviceType}"; + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.GVL_{DeviceType}"); + var tempGvl = Activator.CreateInstance(type); + var FieldValue = control.GetType().GetField(GvlName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); + FieldValue?.SetValue(control, null); + FieldValue?.SetValue(control, tempGvl); + GetInterfaceData(); + } + private AbstractMessageServer GetAbstractMessageServer() { string NameSpace = "HBLConsole.Business"; - Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.{DeviceType}"); + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.{DeviceType}"); if (type == null) - type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.Base"); + type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.Base"); return Activator.CreateInstance(type) as AbstractMessageServer; } + private void GetControlBase() + { + string NameSpace = "HBLConsole.Business"; + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.ControlBase"); + controlAbstract = Activator.CreateInstance(type) as ControlAbstract; + if (controlAbstract != null) + { + controlAbstract.MainAction = new Action(() => { control?.Main(); }); + controlAbstract.ReadDataAction = new Action(() => { control?.ReadData(); }); + controlAbstract.Init(); + } + } + public IControl control { get; set; } public IGvl GVL { get; set; } public IAlarm Alarm { get; set; } - + public ControlAbstract controlAbstract { get; set; } /// /// 设备初始化 @@ -91,6 +116,7 @@ namespace HBLConsole.Factory ActionManage.GetInstance.Register(new Action((o) => { control?.SimOrder(o); }), "SimOrder"); ActionManage.GetInstance.Register(new Action((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); ConnectHelper.GetInstance.Init(); + GetControlBase(); } @@ -115,6 +141,8 @@ namespace HBLConsole.Factory if (inters.Name.Equals("IGvl")) { GVL = (item.GetValue(control)) as IGvl; + GvlName = item.Name; + } else if (inters.Name.Equals("IAlarm")) { diff --git a/HBLConsole.Interface/IControl.cs b/HBLConsole.Interface/IControl.cs index 080ed04..81fa098 100644 --- a/HBLConsole.Interface/IControl.cs +++ b/HBLConsole.Interface/IControl.cs @@ -9,7 +9,6 @@ namespace HBLConsole.Interface public interface IControl { void Main(); - //object GetT(); void Init(); void ReadData(); void SimOrder(T simOrder); diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index c145382..35cd81d 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -22,7 +22,7 @@ namespace HBLConsole.MORKD { Main(); ReadData(); - ResetProgram(); + //ResetProgram(); } public void DataParse(T order) @@ -63,119 +63,121 @@ namespace HBLConsole.MORKD }), "InitCommand"); } - bool Initing = false; + //bool Initing = false; + + //bool Initing { get; set; } /// /// 复位程序 /// - private void ResetProgram() - { - ThreadManage.GetInstance.StartLong(new Action(() => - { - if (RTrig.GetInstance("ResetProgram").Start(Initing)) - { - ThreadManage.GetInstance.StopTask("MainTask", new Action(() => - { - ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => - { - mORKD = null; - mORKD = new GVL_MORKD(); - ActionManage.GetInstance.Send("ResetProgram"); - ReadData(); - Main(); - })); - })); - } - - Thread.Sleep(10); - }), "ResetProgram"); - } + //private void ResetProgram() + //{ + // ThreadManage.GetInstance.StartLong(new Action(() => + // { + // if (RTrig.GetInstance("ResetProgram").Start(Initing)) + // { + // ThreadManage.GetInstance.StopTask("MainTask", new Action(() => + // { + // ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => + // { + // mORKD = null; + // mORKD = new GVL_MORKD(); + // ActionManage.GetInstance.Send("ResetProgram"); + // ReadData(); + // Main(); + // })); + // })); + // } + + // Thread.Sleep(10); + // }), "ResetProgram"); + //} public void Main() { - ThreadManage.GetInstance.StartLong(new Action(() => - { - mORKD.AllowRun = mORKD.InitComplete && !mORKD.TemperatureReached; + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ + mORKD.AllowRun = mORKD.InitComplete && !mORKD.TemperatureReached; - TakeBowlTask(); + TakeBowlTask(); - TakeNoodleTask(); + TakeNoodleTask(); - OutNoodleTask(); + OutNoodleTask(); - SingleDetect(); + SingleDetect(); - TurntableControl(); + TurntableControl(); - OutSoupTask(); + OutSoupTask(); - TakeSoupTask(); + TakeSoupTask(); - Thread.Sleep(10); + // Thread.Sleep(10); - }), "MainTask"); + //}), "MainTask"); } public void ReadData() { - ThreadManage.GetInstance.StartLong(new Action(() => + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ + ModbusTcpHelper.GetInstance.Readbool(1120, 30, new Action((bools) => { - ModbusTcpHelper.GetInstance.Readbool(1120, 30, new Action((bools) => - { - mORKD.InitComplete = bools[0]; - mORKD.TurntableInPlace = bools[1]; - mORKD.RBTakeNoodleComplete = bools[2]; + mORKD.InitComplete = bools[0]; + mORKD.TurntableInPlace = bools[1]; + mORKD.RBTakeNoodleComplete = bools[2]; - for (int i = 0; i < 2; i++) - { - mORKD.AxisIdle[i] = bools[3 + i]; - mORKD.AxisAllowInvertedNoodle[i] = bools[5 + i]; - mORKD.AxisAllowInvertedSoup[i] = bools[7 + i]; - mORKD.SoupHeatComplete[i] = bools[9 + i]; - mORKD.BreakMechanismIdle[i] = bools[25 + i]; - } + for (int i = 0; i < 2; i++) + { + mORKD.AxisIdle[i] = bools[3 + i]; + mORKD.AxisAllowInvertedNoodle[i] = bools[5 + i]; + mORKD.AxisAllowInvertedSoup[i] = bools[7 + i]; + mORKD.SoupHeatComplete[i] = bools[9 + i]; + mORKD.BreakMechanismIdle[i] = bools[25 + i]; + } - for (int i = 0; i < 6; i++) - { - mORKD.CookNoodleBasketIdle[i] = bools[11 + i]; - mORKD.CookNoodleComplete[i] = bools[17 + i]; - } + for (int i = 0; i < 6; i++) + { + mORKD.CookNoodleBasketIdle[i] = bools[11 + i]; + mORKD.CookNoodleComplete[i] = bools[17 + i]; + } - mORKD.TakeNoodleRobotIdle = bools[23]; - mORKD.TakeSoupRobotIdle = bools[24]; - mORKD.TakeSoupComplete = bools[27]; - mORKD.PutNoodleTakeMealComplete = bools[28]; - Initing = bools[29]; - })); + mORKD.TakeNoodleRobotIdle = bools[23]; + mORKD.TakeSoupRobotIdle = bools[24]; + mORKD.TakeSoupComplete = bools[27]; + mORKD.PutNoodleTakeMealComplete = bools[28]; + DeviceData.Initing = bools[29]; + })); - ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action((bools) => + ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action((bools) => + { + mORKD.TurntableLowerLimit = bools[0]; + mORKD.TurntableUpLimit = bools[1]; + for (int i = 0; i < 5; i++) { - mORKD.TurntableLowerLimit = bools[0]; - mORKD.TurntableUpLimit = bools[1]; - for (int i = 0; i < 5; i++) - { - mORKD.SoupMaterialShortage[i] = bools[2 + i]; - } + mORKD.SoupMaterialShortage[i] = bools[2 + i]; + } - for (int i = 0; i < 3; i++) - { - mORKD.OutMealDetect[i] = bools[7 + i]; - } + for (int i = 0; i < 3; i++) + { + mORKD.OutMealDetect[i] = bools[7 + i]; + } - mORKD.TemperatureReached = bools[10]; - })); + mORKD.TemperatureReached = bools[10]; + })); - var ResLoc = ModbusTcpHelper.GetInstance.Read(720, ReadType.HoldingRegisters); - if (ResLoc != null) + var ResLoc = ModbusTcpHelper.GetInstance.Read(720, ReadType.HoldingRegisters); + if (ResLoc != null) + { + if (ResLoc is ushort loc) { - if (ResLoc is ushort loc) - { - mORKD.TurntableFeedbackloc = loc; - } + mORKD.TurntableFeedbackloc = loc; } - Thread.Sleep(100); - }), "ReadPLCData"); + } + // Thread.Sleep(100); + //}), "ReadPLCData"); } public void SimOrder(T simOrder) diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index 8e58c41..f4910f8 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -87,6 +87,14 @@ namespace HBLConsole.MORKIC //冰淇淋机创建 iceCreamMachine = new IceCreamMachine(com_IceCream, (BaudRates)Enum.Parse(typeof(BaudRates), baud_IceCream)); icchipMachine = new ICChipMachine(com_ICChip, (BaudRates)Enum.Parse(typeof(BaudRates), baud_ICChip)); + + //咖啡机开启主线程 + coffeeMachine.Start(); + //冰淇淋机开启主线程 + iceCreamMachine.Start(); + icchipMachine.Start(); + new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); + Main(); ReadData(); @@ -251,40 +259,35 @@ namespace HBLConsole.MORKIC public void Main() { - //咖啡机开启主线程 - coffeeMachine.Start(); - //冰淇淋机开启主线程 - iceCreamMachine.Start(); - icchipMachine.Start(); - new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); + //开始心跳刷新,根据咖啡机及冰淇淋机来判断 - ThreadManage.GetInstance.StartLong(new Action(() => - { + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ - //GeneralConfig.Healthy = true; - //GeneralConfig.Healthy = - // LebaiHelper.GetInstance.IsConnected && - // MorkIStatus.GetInstance().CanDo && - // MorkCStatus.GetInstance().CanDo; - GeneralConfig.Healthy = - LebaiHelper.GetInstance.IsConnected && - MorkCStatus.GetInstance().CanDo; - GeneralConfig.Healthy = true; - Thread.Sleep(100); - }), "MORK-IC心跳刷新"); + //GeneralConfig.Healthy = true; + //GeneralConfig.Healthy = + // LebaiHelper.GetInstance.IsConnected && + // MorkIStatus.GetInstance().CanDo && + // MorkCStatus.GetInstance().CanDo; + GeneralConfig.Healthy = + LebaiHelper.GetInstance.IsConnected && + MorkCStatus.GetInstance().CanDo; + GeneralConfig.Healthy = true; + // Thread.Sleep(100); + //}), "MORK-IC心跳刷新"); } public void ReadData() { - ThreadManage.GetInstance.StartLong(new Action(() => - { - lebai = LebaiHelper.GetInstance.GetValueAsync(); - LebaiHelper.GetInstance.GetRobotModeStatus(); - Thread.Sleep(100); - }), "乐百机器人数据读取"); + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ + lebai = LebaiHelper.GetInstance.GetValueAsync(); + LebaiHelper.GetInstance.GetRobotModeStatus(); + // Thread.Sleep(100); + //}), "乐百机器人数据读取"); } public void SimOrder(T simOrder) diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index 9405e8f..c63333d 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -15,6 +15,7 @@ using BPA.Message.Enum; using HBLConsole.GVL; using BPA.Models; using BPA.Message.IOT; +using HBLConsole.Abstract; namespace HBLConsole.MORKS { @@ -29,6 +30,9 @@ namespace HBLConsole.MORKS public void ConnectOk() { + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); //WriteRecipeBoms(); ReadData(); Main(); @@ -36,94 +40,67 @@ namespace HBLConsole.MORKS MessageLog.GetInstance.Show("MORKS 设备初始化完成"); } - /// - /// 复位程序 - /// - private void ResetProgram() - { - ThreadManage.GetInstance.StartLong(new Action(() => - { - if (RTrig.GetInstance("ResetProgram").Start(mORKS.DeviceIniting)) - { - ThreadManage.GetInstance.StopTask("MainTask", new Action(() => - { - //mORKS.AllowRun = false; - //TakeBowlId = string.Empty; - //IngredientsCompleteId = string.Empty; - //CookNodelId = new string[6] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, }; - //mORKS.RobotTaskInterlock = false; - //OutMealId = string.Empty; - //mORKS.TakeBowlInterlock = false; - //mORKS.TakeNoodleInterlock = false; - //mORKS.OutNoodleing = false; - Main(); - })); - } - Thread.Sleep(10); - }), "ResetProgram"); - } - /// /// 数据读取 /// public void ReadData() { - ThreadManage.GetInstance.StartLong(new Action(() => + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ + ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => { - ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => - { - mORKS.RobotTakeNoodle = bools[0]; - mORKS.RobotOutMeal = bools[1]; - mORKS.MoveTurntable = bools[2]; - })); + mORKS.RobotTakeNoodle = bools[0]; + mORKS.RobotOutMeal = bools[1]; + mORKS.MoveTurntable = bools[2]; + })); - ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => - { - mORKS.InitComplete = bools[0]; - mORKS.TakeBowlIdle = bools[1]; - mORKS.TemperatureReached = bools[2]; - mORKS.AllowFallNoodle = bools[3]; - mORKS.RbTakeNoodleComplete = bools[4]; - mORKS.RbFallNoodleComplete = bools[5]; - mORKS.RbOutMealComplete = bools[6]; - mORKS.RobotIdle = bools[7]; - mORKS.TakeMealDetect = bools[8]; - mORKS.MissingBowl = bools[9]; - mORKS.DeviceIniting = bools[10]; - mORKS.TurntableLowerLimit = bools[11]; - mORKS.MissingBowlSignal2 = bools[12]; - mORKS.TurntableUpLimit = bools[13]; - mORKS.TurntableMoveInPlace = bools[15]; - })); - - ModbusTcpHelper.GetInstance.Readbool(1136, 6, new Action((bools) => + ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => + { + mORKS.InitComplete = bools[0]; + mORKS.TakeBowlIdle = bools[1]; + mORKS.TemperatureReached = bools[2]; + mORKS.AllowFallNoodle = bools[3]; + mORKS.RbTakeNoodleComplete = bools[4]; + mORKS.RbFallNoodleComplete = bools[5]; + mORKS.RbOutMealComplete = bools[6]; + mORKS.RobotIdle = bools[7]; + mORKS.TakeMealDetect = bools[8]; + mORKS.MissingBowl = bools[9]; + DeviceData.Initing = bools[10]; + mORKS.TurntableLowerLimit = bools[11]; + mORKS.MissingBowlSignal2 = bools[12]; + mORKS.TurntableUpLimit = bools[13]; + mORKS.TurntableMoveInPlace = bools[15]; + })); + + ModbusTcpHelper.GetInstance.Readbool(1136, 6, new Action((bools) => + { + for (int i = 0; i < 6; i++) { - for (int i = 0; i < 6; i++) - { - mORKS.NoodleCookerStatus[i] = bools[i]; - } - })); + mORKS.NoodleCookerStatus[i] = bools[i]; + } + })); - ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action((bools) => + ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action((bools) => + { + for (int i = 0; i < 6; i++) { - for (int i = 0; i < 6; i++) - { - mORKS.CookNoodlesComplete[i] = bools[i]; - } - })); + mORKS.CookNoodlesComplete[i] = bools[i]; + } + })); - var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); - if (ResLoc != null) - { - if (ResLoc is ushort loc) - { - mORKS.TurntableFeedbackloc = loc; - } - } + //var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); + //if (ResLoc != null) + //{ + // if (ResLoc is ushort loc) + // { + // mORKS.TurntableFeedbackloc = loc; + // } + //} - Thread.Sleep(500); - }), "ReadPLCData"); + // Thread.Sleep(500); + //}), "ReadPLCData"); } public void SimOrder(T simOrder) @@ -224,37 +201,33 @@ namespace HBLConsole.MORKS int index = Array.FindIndex(Json.Data.recipeBoms.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId); index++; mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(batching_W.BatchingLoc), SuborderId = morkOrderPush.SuborderId, RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 }); - - } } } - - public void Main() { - ThreadManage.GetInstance.StartLong(new Action(() => - { - mORKS.AllowRun = mORKS.InitComplete; - //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; - //GeneralConfig.Healthy = true; - GeneralConfig.Healthy = mORKS.AllowRun; + //ThreadManage.GetInstance.StartLong(new Action(() => + //{ + mORKS.AllowRun = mORKS.InitComplete; + //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; + //GeneralConfig.Healthy = true; + GeneralConfig.Healthy = mORKS.AllowRun; - TakeBowlTask(); + TakeBowlTask(); - TakeNoodleTask(); + TakeNoodleTask(); - OutNoodleTask(); + OutNoodleTask(); - SingleDetect(); + SingleDetect(); - TurntableControl(); + TurntableControl(); - Thread.Sleep(100); + //Thread.Sleep(100); - }), "MainTask"); + //}), "MainTask"); } /// @@ -327,9 +300,10 @@ namespace HBLConsole.MORKS #region 优化版本 //if (mORKS.TurntableMoveInPlace && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) //{ + // var result = Json.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList(); // if (mORKS.TurntableLowerLimit) // { - // if (mORKS.TurntableFeedbackloc == mORKS.RBTakeNoodleTask.ElementAt(0).Loc) + // if (mORKS.TurntableFeedbackloc == mORKS.RBTakeNoodleTask.ElementAt(0).Loc || (result?.Count > 0 && result?.Count == mORKS.TurntableLocLists.Count)) // { // mORKS.TurntableLocLists.Clear(); // mORKS.AllowTakeNoodle = true; @@ -348,20 +322,22 @@ namespace HBLConsole.MORKS // { // if (!mORKS.TurntableInterlock) // { - // var result = Json.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList(); - // result?.ForEach(item => + // if (result != null) // { - // if (ushort.TryParse(item.BatchingLoc, out ushort loc)) + // foreach (var item in result) // { - // if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc)) + // if (ushort.TryParse(item.BatchingLoc, out ushort loc)) // { - // TurntableStart(loc); - // MessageLog.GetInstance.Show($"没有物料检测的启动转台控制,转台位置:[{loc}]"); - // return; + // if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc)) + // { + // TurntableStart(loc); + // MessageLog.GetInstance.Show($"没有物料检测的启动转台控制,转台位置:[{loc}]"); + // break; + // } + // else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc); // } - // else if (mORKS.TurntableFeedbackloc == loc) mORKS.TurntableLocLists.Add(loc); // } - // }); + // } // } // } diff --git a/HBLConsole.MORKS/GVL_MORKS.cs b/HBLConsole.MORKS/GVL_MORKS.cs index 9d982b5..d854dc3 100644 --- a/HBLConsole.MORKS/GVL_MORKS.cs +++ b/HBLConsole.MORKS/GVL_MORKS.cs @@ -42,41 +42,48 @@ namespace HBLConsole.MORKS /// 允许运行 /// [Circuit(new string[] { "机器人取面", "取碗控制" }, "允许运行")] + [VariableMonitor("允许运行")] public bool AllowRun { get; set; } /// /// //机器人任务互锁信号 /// [Circuit(new string[] { "机器人取面", "出面控制" }, "机器人互锁", new bool[] { true, false })] + [VariableMonitor("机器人任务互锁信号")] public bool RobotTaskInterlock { get; set; } /// /// 取碗互锁信号 /// [Circuit("取碗控制", "取碗互锁", true)] + [VariableMonitor("取碗互锁信号")] public bool TakeBowlInterlock { get; set; } /// /// 取面互锁信号 /// [Circuit(new string[] { "机器人取面", "出面控制" }, "取面互锁信号", new bool[] { true, true })] + [VariableMonitor("取面互锁信号")] public bool TakeNoodleInterlock { get; set; } /// /// 出面中 /// [Circuit("机器人取面", "出面中", true)] + [VariableMonitor("出面中")] public bool OutNoodleing { get; set; } /// /// 允许取面 /// [Circuit(new string[] { "转台控制", "机器人取面" }, "允许取面", new bool[] { true, false })] + [VariableMonitor("允许取面")] public bool AllowTakeNoodle { get; set; } /// /// 转台互锁信号 /// + [VariableMonitor("转台互锁信号")] public bool TurntableInterlock { get; set; } #endregion @@ -87,6 +94,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1120 /// [Circuit(new string[] { "允许运行", "转台控制", "转台控制" }, "初始化完成")] + [VariableMonitor("初始化完成", "M100.0", "1120")] public bool InitComplete { get; set; } /// @@ -95,6 +103,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1121 /// [Circuit("取碗控制", "取碗机构空闲", true)] + [VariableMonitor("初始化完成", "M100.1", "1121")] public bool TakeBowlIdle { get; set; } /// @@ -103,6 +112,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1122 /// [Circuit("允许运行", "温度到达")] + [VariableMonitor("温度到达", "M100.2", "1122")] public bool TemperatureReached { get; set; } /// @@ -111,6 +121,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1123 /// [Circuit("出面控制", "允许到面")] + [VariableMonitor("允许到面", "M100.3", "1123")] public bool AllowFallNoodle { get; set; } /// @@ -118,6 +129,7 @@ namespace HBLConsole.MORKS /// PLC -> M100.4 /// ModbusTcp -> 1124 /// + [VariableMonitor("机器人取面完成", "M100.4", "1124")] public bool RbTakeNoodleComplete { get; set; } /// @@ -125,6 +137,7 @@ namespace HBLConsole.MORKS /// PLC -> M100.5 /// ModbusTcp -> 1125 /// + [VariableMonitor("机器人倒面完成", "M100.5", "1125")] public bool RbFallNoodleComplete { get; set; } /// @@ -132,6 +145,7 @@ namespace HBLConsole.MORKS /// PLC -> M100.6 /// ModbusTcp -> 1126 /// + [VariableMonitor("机器人出餐完成", "M100.6", "1126")] public bool RbOutMealComplete { get; set; } /// @@ -140,6 +154,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1127 /// [Circuit(new string[] { "机器人取面", "出面控制" }, "机器人空闲")] + [VariableMonitor("机器人空闲", "M100.7", "1127")] public bool RobotIdle { get; set; } /// @@ -148,6 +163,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1128 /// [Circuit("出面控制", "取餐口检测", true)] + [VariableMonitor("取餐口检测", "M101.0", "1128")] public bool TakeMealDetect { get; set; } /// @@ -155,6 +171,7 @@ namespace HBLConsole.MORKS /// PLC -> M101.1 /// ModbusTcp -> 1129 /// + [VariableMonitor("缺碗信号", "M101.1", "1129")] public bool MissingBowl { get; set; } /// @@ -162,6 +179,7 @@ namespace HBLConsole.MORKS /// PLC -> M101.2 /// ModbusTcp -> 1130 /// + [VariableMonitor("设备初始化中", "M101.2", "1130")] public bool DeviceIniting { get; set; } /// @@ -170,6 +188,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1131 /// [Circuit("转台控制", "转台下限检测有物料")] + [VariableMonitor("转台下限检测", "M101.3", "1131")] public bool TurntableLowerLimit { get; set; } /// @@ -177,6 +196,7 @@ namespace HBLConsole.MORKS /// PLC -> M101.4 /// ModbusTcp -> 1132 /// + [VariableMonitor("缺碗信号 2", "M101.4", "1132")] public bool MissingBowlSignal2 { get; set; } /// @@ -184,6 +204,7 @@ namespace HBLConsole.MORKS /// PLC -> M101.5 /// ModbusTcp -> 1133 /// + [VariableMonitor("转台上限检测", "M101.5", "1133")] public bool TurntableUpLimit { get; set; } /// @@ -192,6 +213,7 @@ namespace HBLConsole.MORKS /// ModbusTcp -> 1135 /// [Circuit(new string[] { "转台控制", "机器人取面" }, "转台移动到位")] + [VariableMonitor("转台移动到位", "M101.7", "1135")] public bool TurntableMoveInPlace { get; set; } /// @@ -199,6 +221,7 @@ namespace HBLConsole.MORKS /// M102.0 - M102.5 /// 1136 - 1141 /// + [VariableMonitor("煮面炉状态", "M102.0", "1136")] public bool[] NoodleCookerStatus { get; set; } = new bool[6] { false, false, false, false, false, false }; /// @@ -206,6 +229,7 @@ namespace HBLConsole.MORKS /// M103.0 - M103.5 /// 1144 - 1149 /// + [VariableMonitor("煮面完成", "M103.0", "1144")] public bool[] CookNoodlesComplete { get; set; } = new bool[6] { false, false, false, false, false, false }; /// @@ -213,6 +237,7 @@ namespace HBLConsole.MORKS /// PLC -> VW0 /// ModbusTcp -> 100 /// + [VariableMonitor("配方编号", "VW0", "100")] public ushort RecipeNumber { get; set; } /// @@ -220,6 +245,7 @@ namespace HBLConsole.MORKS /// PLC -> VW2 /// ModbusTcp -> 101 /// + [VariableMonitor("转台位置", "VW2", "101")] public ushort TurntableLoc { get; set; } /// @@ -227,6 +253,7 @@ namespace HBLConsole.MORKS /// PLC -> VW4 /// ModbusTcp -> 102 /// + [VariableMonitor("到面至煮面炉位置", "VW4", "102")] public ushort FallNoodleLoc { get; set; } /// @@ -234,6 +261,7 @@ namespace HBLConsole.MORKS /// PLC -> VW6 /// ModbusTcp -> 103 /// + [VariableMonitor("取面位置", "VW6", "103")] public ushort TakeNoodleLoc { get; set; } /// @@ -241,6 +269,7 @@ namespace HBLConsole.MORKS /// PLC -> VW372 /// ModbusTcp -> 286 /// + [VariableMonitor("转台位置", "VW372", "286")] public ushort TurntableFeedbackloc { get; set; } /// diff --git a/HBLConsole.Model/DeviceData.cs b/HBLConsole.Model/DeviceData.cs new file mode 100644 index 0000000..126f699 --- /dev/null +++ b/HBLConsole.Model/DeviceData.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Model +{ + public class DeviceData + { + public static bool Initing { get; set; } + + } +} diff --git a/HBLConsole.Service/RTrig.cs b/HBLConsole.Service/RTrig.cs index 2a9547d..2ed01e1 100644 --- a/HBLConsole.Service/RTrig.cs +++ b/HBLConsole.Service/RTrig.cs @@ -7,9 +7,11 @@ using System.Threading.Tasks; namespace HBLConsole.Service { + /// + /// 上升沿操作类 + /// public class RTrig { - private volatile static ConcurrentDictionary _Instance; public static RTrig GetInstance(string name) { @@ -34,8 +36,5 @@ namespace HBLConsole.Service IN1 = IN; return Q; } - - - } } diff --git a/HBLConsole.Service/TTrig.cs b/HBLConsole.Service/TTrig.cs new file mode 100644 index 0000000..5b77390 --- /dev/null +++ b/HBLConsole.Service/TTrig.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Text; + +namespace HBLConsole.Service +{ + /// + /// 下降沿操作 + /// + public class TTrig + { + private volatile static ConcurrentDictionary _Instance; + public static TTrig GetInstance(string name) + { + if (_Instance == null) _Instance = new ConcurrentDictionary(); + if (!_Instance.ContainsKey(name)) _Instance.TryAdd(name, new TTrig()); + return _Instance[name]; + } + private TTrig() { } + + private bool flag1; + public bool Q { get; private set; } + private bool IN1 + { + set + { + Q = !value && flag1; + flag1 = value; + } + } + public bool Start(bool IN) + { + IN1 = IN; + return Q; + } + + } +} From 8d47194ee401e2cab6b22e444b782cb5b4b34484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 30 Mar 2022 18:57:19 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E5=86=B2=E7=AA=81=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Factory/SimpleFactory.cs | 4 +- HBLConsole.MORKD/Control_MORKD.cs | 122 ++++++++++++------------ HBLConsole.MORKIC/Control_MORKIC.cs | 64 ++++++------- HBLConsole.MORKS/Control_MORKS.cs | 139 ++++++++++++++++------------ 4 files changed, 171 insertions(+), 158 deletions(-) diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index 997bcec..50f31e9 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -15,7 +15,7 @@ namespace HBLConsole.Factory private volatile static SimpleFactory _Instance; public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory()); - //private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } + private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer()); private AbstractMessageServer _GetAbsMessageServer; @@ -116,7 +116,7 @@ namespace HBLConsole.Factory ActionManage.GetInstance.Register(new Action((o) => { control?.SimOrder(o); }), "SimOrder"); ActionManage.GetInstance.Register(new Action((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); ConnectHelper.GetInstance.Init(); - GetControlBase(); + //GetControlBase(); } diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index 97b9cf5..933851d 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -22,7 +22,7 @@ namespace HBLConsole.MORKD { Main(); ReadData(); - //ResetProgram(); + ResetProgram(); } public void DataParse(T order) @@ -63,66 +63,62 @@ namespace HBLConsole.MORKD }), "InitCommand"); } - //bool Initing = false; - - //bool Initing { get; set; } - /// /// 复位程序 /// - //private void ResetProgram() - //{ - // ThreadManage.GetInstance.StartLong(new Action(() => - // { - // if (RTrig.GetInstance("ResetProgram").Start(Initing)) - // { - // ThreadManage.GetInstance.StopTask("MainTask", new Action(() => - // { - // ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => - // { - // mORKD = null; - // mORKD = new GVL_MORKD(); - // ActionManage.GetInstance.Send("ResetProgram"); - // ReadData(); - // Main(); - // })); - // })); - // } - - // Thread.Sleep(10); - // }), "ResetProgram"); - //} + private void ResetProgram() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) + { + ThreadManage.GetInstance.StopTask("MainTask", new Action(() => + { + ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => + { + mORKD = null; + mORKD = new GVL_MORKD(); + ActionManage.GetInstance.Send("ResetProgram"); + ReadData(); + Main(); + })); + })); + } + + Thread.Sleep(10); + }), "ResetProgram"); + } public void Main() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - mORKD.AllowRun = mORKD.InitComplete && !mORKD.TemperatureReached; + ThreadManage.GetInstance.StartLong(new Action(() => + { + mORKD.AllowRun = mORKD.InitComplete && !mORKD.TemperatureReached; - TakeBowlTask(); + TakeBowlTask(); - TakeNoodleTask(); + TakeNoodleTask(); - OutNoodleTask(); + OutNoodleTask(); - SingleDetect(); + SingleDetect(); - TurntableControl(); + TurntableControl(); - OutSoupTask(); + OutSoupTask(); - TakeSoupTask(); + TakeSoupTask(); - // Thread.Sleep(10); + Thread.Sleep(10); - //}), "MainTask"); + }), "MainTask"); } public void ReadData() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - ModbusTcpHelper.GetInstance.Readbool(1120, 30, new Action((bools) => + ThreadManage.GetInstance.StartLong(new Action(() => + { + ModbusTcpHelper.GetInstance.Readbool(1120, 30, new Action((bools) => { mORKD.InitComplete = bools[0]; mORKD.TurntableInPlace = bools[1]; @@ -151,33 +147,33 @@ namespace HBLConsole.MORKD })); - ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action((bools) => - { - mORKD.TurntableLowerLimit = bools[0]; - mORKD.TurntableUpLimit = bools[1]; - for (int i = 0; i < 5; i++) + ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action((bools) => { - mORKD.SoupMaterialShortage[i] = bools[2 + i]; - } + mORKD.TurntableLowerLimit = bools[0]; + mORKD.TurntableUpLimit = bools[1]; + for (int i = 0; i < 5; i++) + { + mORKD.SoupMaterialShortage[i] = bools[2 + i]; + } - for (int i = 0; i < 3; i++) - { - mORKD.OutMealDetect[i] = bools[7 + i]; - } + for (int i = 0; i < 3; i++) + { + mORKD.OutMealDetect[i] = bools[7 + i]; + } - mORKD.TemperatureReached = bools[10]; - })); + mORKD.TemperatureReached = bools[10]; + })); - var ResLoc = ModbusTcpHelper.GetInstance.Read(720, ReadType.HoldingRegisters); - if (ResLoc != null) - { - if (ResLoc is ushort loc) + var ResLoc = ModbusTcpHelper.GetInstance.Read(720, ReadType.HoldingRegisters); + if (ResLoc != null) { - mORKD.TurntableFeedbackloc = loc; + if (ResLoc is ushort loc) + { + mORKD.TurntableFeedbackloc = loc; + } } - } - // Thread.Sleep(100); - //}), "ReadPLCData"); + Thread.Sleep(100); + }), "ReadPLCData"); } public void SimOrder(T simOrder) diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index dff63c2..3c7b329 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -102,16 +102,9 @@ namespace HBLConsole.MORKIC iceCreamMachine = new IceCreamMachine(com_IceCream, (BaudRates)Enum.Parse(typeof(BaudRates), baud_IceCream)); icchipMachine = new ICChipMachine(com_ICChip, (BaudRates)Enum.Parse(typeof(BaudRates), baud_ICChip)); - //咖啡机开启主线程 - coffeeMachine.Start(); - //冰淇淋机开启主线程 - iceCreamMachine.Start(); - icchipMachine.Start(); - new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); - Main(); ReadData(); - Main(); + ThreadManage.GetInstance.StartLong(new Action(() => { @@ -200,7 +193,8 @@ namespace HBLConsole.MORKIC }), "MORK-IC心跳刷新"); ThreadManage.GetInstance.Start(new Action(() => { - while (!LebaiHelper.GetInstance.IsConnected) { + while (!LebaiHelper.GetInstance.IsConnected) + { Thread.Sleep(10); } LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_欢迎); @@ -353,32 +347,32 @@ namespace HBLConsole.MORKIC are.Set(); } - public void Main() - { - //咖啡机开启主线程 - coffeeMachine.Start(); - //冰淇淋机开启主线程 - iceCreamMachine.Start(); - icchipMachine.Start(); - new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); - - //开始心跳刷新,根据咖啡机及冰淇淋机来判断 - ThreadManage.GetInstance.StartLong(new Action(() => - { - - //GeneralConfig.Healthy = true; - //GeneralConfig.Healthy = - // LebaiHelper.GetInstance.IsConnected && - // MorkIStatus.GetInstance().CanDo && - // MorkCStatus.GetInstance().CanDo; - GeneralConfig.Healthy = - LebaiHelper.GetInstance.IsConnected && - MorkCStatus.GetInstance().CanDo; - GeneralConfig.Healthy = true; - Thread.Sleep(100); - }), "MORK-IC心跳刷新"); - - + //public void Main() + //{ + // //咖啡机开启主线程 + // coffeeMachine.Start(); + // //冰淇淋机开启主线程 + // iceCreamMachine.Start(); + // icchipMachine.Start(); + // new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); + + // //开始心跳刷新,根据咖啡机及冰淇淋机来判断 + // ThreadManage.GetInstance.StartLong(new Action(() => + // { + + // //GeneralConfig.Healthy = true; + // //GeneralConfig.Healthy = + // // LebaiHelper.GetInstance.IsConnected && + // // MorkIStatus.GetInstance().CanDo && + // // MorkCStatus.GetInstance().CanDo; + // GeneralConfig.Healthy = + // LebaiHelper.GetInstance.IsConnected && + // MorkCStatus.GetInstance().CanDo; + // GeneralConfig.Healthy = true; + // Thread.Sleep(100); + // }), "MORK-IC心跳刷新"); + + //} public void ReadData() { diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index c63333d..1e848f3 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -36,71 +36,94 @@ namespace HBLConsole.MORKS //WriteRecipeBoms(); ReadData(); Main(); - //ResetProgram(); + ResetProgram(); MessageLog.GetInstance.Show("MORKS 设备初始化完成"); } + private void ResetProgram() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) + { + ThreadManage.GetInstance.StopTask("MainTask", new Action(() => + { + ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => + { + mORKS = null; + mORKS = new GVL_MORKS(); + ActionManage.GetInstance.Send("ResetProgram"); + ReadData(); + Main(); + })); + })); + } + + Thread.Sleep(10); + }), "ResetProgram"); + } + /// /// 数据读取 /// public void ReadData() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => + ThreadManage.GetInstance.StartLong(new Action(() => + { + ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => { mORKS.RobotTakeNoodle = bools[0]; mORKS.RobotOutMeal = bools[1]; mORKS.MoveTurntable = bools[2]; })); - ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => - { - mORKS.InitComplete = bools[0]; - mORKS.TakeBowlIdle = bools[1]; - mORKS.TemperatureReached = bools[2]; - mORKS.AllowFallNoodle = bools[3]; - mORKS.RbTakeNoodleComplete = bools[4]; - mORKS.RbFallNoodleComplete = bools[5]; - mORKS.RbOutMealComplete = bools[6]; - mORKS.RobotIdle = bools[7]; - mORKS.TakeMealDetect = bools[8]; - mORKS.MissingBowl = bools[9]; - DeviceData.Initing = bools[10]; - mORKS.TurntableLowerLimit = bools[11]; - mORKS.MissingBowlSignal2 = bools[12]; - mORKS.TurntableUpLimit = bools[13]; - mORKS.TurntableMoveInPlace = bools[15]; - })); - - ModbusTcpHelper.GetInstance.Readbool(1136, 6, new Action((bools) => - { - for (int i = 0; i < 6; i++) + ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => { - mORKS.NoodleCookerStatus[i] = bools[i]; - } - })); + mORKS.InitComplete = bools[0]; + mORKS.TakeBowlIdle = bools[1]; + mORKS.TemperatureReached = bools[2]; + mORKS.AllowFallNoodle = bools[3]; + mORKS.RbTakeNoodleComplete = bools[4]; + mORKS.RbFallNoodleComplete = bools[5]; + mORKS.RbOutMealComplete = bools[6]; + mORKS.RobotIdle = bools[7]; + mORKS.TakeMealDetect = bools[8]; + mORKS.MissingBowl = bools[9]; + DeviceData.Initing = bools[10]; + mORKS.TurntableLowerLimit = bools[11]; + mORKS.MissingBowlSignal2 = bools[12]; + mORKS.TurntableUpLimit = bools[13]; + mORKS.TurntableMoveInPlace = bools[15]; + })); + + ModbusTcpHelper.GetInstance.Readbool(1136, 6, new Action((bools) => + { + for (int i = 0; i < 6; i++) + { + mORKS.NoodleCookerStatus[i] = bools[i]; + } + })); - ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action((bools) => - { - for (int i = 0; i < 6; i++) + ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action((bools) => { - mORKS.CookNoodlesComplete[i] = bools[i]; - } - })); + for (int i = 0; i < 6; i++) + { + mORKS.CookNoodlesComplete[i] = bools[i]; + } + })); - //var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); - //if (ResLoc != null) - //{ - // if (ResLoc is ushort loc) - // { - // mORKS.TurntableFeedbackloc = loc; - // } - //} + //var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); + //if (ResLoc != null) + //{ + // if (ResLoc is ushort loc) + // { + // mORKS.TurntableFeedbackloc = loc; + // } + //} - // Thread.Sleep(500); - //}), "ReadPLCData"); + Thread.Sleep(500); + }), "ReadPLCData"); } public void SimOrder(T simOrder) @@ -208,26 +231,26 @@ namespace HBLConsole.MORKS public void Main() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - mORKS.AllowRun = mORKS.InitComplete; - //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; - //GeneralConfig.Healthy = true; - GeneralConfig.Healthy = mORKS.AllowRun; + ThreadManage.GetInstance.StartLong(new Action(() => + { + mORKS.AllowRun = mORKS.InitComplete; + //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; + //GeneralConfig.Healthy = true; + GeneralConfig.Healthy = mORKS.AllowRun; - TakeBowlTask(); + TakeBowlTask(); - TakeNoodleTask(); + TakeNoodleTask(); - OutNoodleTask(); + OutNoodleTask(); - SingleDetect(); + SingleDetect(); - TurntableControl(); + TurntableControl(); - //Thread.Sleep(100); + Thread.Sleep(100); - //}), "MainTask"); + }), "MainTask"); } /// From 509e8df5eff73b2a08ba03c9fd65db8e7691b363 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Thu, 31 Mar 2022 14:51:48 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0iot=20=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Business/IotReport.cs | 182 ++++++++++++++++++------------- HBLConsole.GVL/InternetInfo.cs | 23 ---- HBLConsole.MainConsole/Main.cs | 4 +- HBLConsole/App.config | 10 +- 4 files changed, 109 insertions(+), 110 deletions(-) diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs index 751b0ab..406a9b6 100644 --- a/HBLConsole.Business/IotReport.cs +++ b/HBLConsole.Business/IotReport.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using HBLConsole.Factory; +using BPA.Message.API请求; namespace HBLConsole.Business { @@ -19,59 +20,108 @@ namespace HBLConsole.Business #region 单例模式 private volatile static IotReport _Instance; public static IotReport GetInstance => _Instance ?? (_Instance = new IotReport()); - private IotReport() - { - IOTDev.GetInstance().Set(InternetInfo.ProductKey, InternetInfo.DeviceName, InternetInfo.DeviceSecret); - IOTDev.GetInstance().CreateLinks(); - IOTDev.GetInstance().IOT_Subscribe(IOTDev.BroadcastTopic);//订阅广播主题 - IOTDev.actionIOT += actionIOTHandler;//消息数据回调 - IOTDev.UNConnectMqtt += new Action((o) => { MessageLog.GetInstance.Show(o); }); - if (IOTDev.client.IsConnected) MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接成功."); - else MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接失败.不能上报业务信息"); - //string NameSpace = $"HBLConsole.{GeneralConfig.DeviceType}"; - //control = (IControl)(Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{GeneralConfig.DeviceType}"))?.GetProperty("Instance").GetValue(null); - } #endregion #region 变量 - + /// + /// 查询出当前设备信息 + /// + public DeviceTable device; /// /// 大屏上报Model /// - public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { SBMC = InternetInfo.DeviceName, SBMS = InternetInfo.DeviceMS }; + public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { }; + #endregion + #region IOT上报公共调用 /// - /// 当前控制的设备控件 + /// 上报告警消息 + /// 调用示例: SendAlarmMessage(new AlarmTable { AlarmTime = DateTime.Now,AlarmType = "1",AlarmMessage = "煮面机异常",AlarmVla = "煮面机" }); /// - //public IControl control; + /// + public void SendAlarmMessage(AlarmTable alarmTable) + { + alarmTable.ClientId = InternetInfo.ClientId.ToString(); + string json = Tools.JsonConvertTools>(new IotModel { @params = new AlarmIOT { GJXX = Tools.JsonConvertTools(alarmTable) } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json); + } + + /// + /// 上报日志消息 + /// 调用示例:SendLogMessage(new LogTable { LogTime = DateTime.Now,LogType = "1",LogMessage = "程序异常",LogVla = "程序" }); + /// + /// + public void SendLogMessage(LogTable logTable) + { + logTable.ClientId = InternetInfo.ClientId.ToString(); + string json = Tools.JsonConvertTools>(new IotModel { @params = new LogIOT { SZXX = Tools.JsonConvertTools(logTable) } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json); + } + + /// + /// 上报节点状态消息 + /// 调用示例:SendNodeStatusMessage("json字符串"); + /// + /// + public void SendNodeStatusMessage(string json) + { + string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new NodeStatusIOT { NodeStatus = Tools.JsonConvertTools(json) } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr); + } #endregion - #region 事件 + #region 外部关闭或初始化IOT调用 + /// + /// 初始化IOT连接 + /// + public bool Initialize() + { + if (!IOTDevServer.GetInstance().CreateLinks(InternetInfo.ClientId,out device)) + { + MessageLog.GetInstance.Show($"设备{InternetInfo.ClientId}阿里云上没有该设备。"); + return false; + } + IOTDevServer.GetInstance().IOT_Subscribe(IOTDevServer.BroadcastTopic);//订阅广播主题 + IOTDevServer.DevIOTAction += DevIOTActionHandler; + IOTDevServer.UNConnectMqtt += new Action((o) => { MessageLog.GetInstance.Show(o); });//断网自动重连接与打印 + if (IOTDevServer.client.IsConnected) MessageLog.GetInstance.Show($"设备{device.devicename} {device.remark}阿里云连接成功."); + else MessageLog.GetInstance.Show($"设备{device.devicename} {device.remark}阿里云连接失败.不能上报业务信息"); + return IOTDevServer.client.IsConnected; + } + /// /// 关闭IOT连接 /// public static void Close() { - if (IOTDev.client != null) - IOTDev.GetInstance().Disconnect(); + if (IOTDevServer.client != null) + IOTDevServer.GetInstance().Disconnect(); } + #endregion + #region 云端订阅主题消息接收 /// - /// 获取属性状态 + /// 接收云端消息 /// - public T GetTypeValue(string str) + /// + /// + private void DevIOTActionHandler(string topic, string message) { - - return (T)SimpleFactory.GetInstance.GVL.GetType().GetProperty(str).GetValue(SimpleFactory.GetInstance.GVL, null); - //return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null); + if (IOTDevServer.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端 + { + IOTCommandModel iOTCommand = Tools.JsonToObjectTools(message); + if (iOTCommand.deviceName == device.devicename) + ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); + } } + #endregion + #region 废弃代码 /// - /// 设置上报数据 + /// 设置上报基本与扩展数据 /// public void SetData() { - #region 上报数据整理 #region 基本数据 //设置基本属性与状态 iOTDevSXModel.SetJBSX(new DevSX @@ -116,66 +166,44 @@ namespace HBLConsole.Business } else { - iOTDevSXModel.SetKZSX(new DevSX { data = new List { new DevSXBase { SXMC = "", SXLX = "" } } }); + iOTDevSXModel.SetKZSX(new DevSX { data = new List { new DevSXBase { SXMC = "",SXLX = "" } } }); } #endregion - //设置告警消息 - #region 告警消息 - List bases = Tools.JsonToObjectTools(iOTDevSXModel.JBSX)?.data?.ToList().FindAll(par => par.SXStatus == false); - if (bases != null) bases.AddRange(Tools.JsonToObjectTools(iOTDevSXModel.KZSX)?.data?.ToList().FindAll(par => par.SXStatus == false)); - List alarms = new List(); - bases?.ForEach(par => alarms.Add(new AlarmModel { DeviceMC = iOTDevSXModel.SBMC, DeviceSJ = DateTime.Now.ToString(), AlarmCD = "一般", DeviceZT = "未处理", DeviceMS = par.SXYCMS })); - iOTDevSXModel.SetGJXX(new AlarmMessage { data = alarms }); - #endregion - - bool InitComplete = GetTypeValue("InitComplete"); - bool RobotTakeNoodle = GetTypeValue("RobotTakeNoodle"); - bool RobotOutMeal = GetTypeValue("RobotOutMeal"); - iOTDevSXModel.SetLCSB(new ProcessMessage - { - data = new List - { - new ProcessModel { ProcessName="开机",IsMark=IsAllowRun,ProcessMS=IsAllowRun?"机器人开机成功":"" }, - new ProcessModel { ProcessName="初始化",IsMark=InitComplete,ProcessMS=InitComplete?"机器人正在初始化成功":"" }, - new ProcessModel { ProcessName="取面",IsMark=RobotTakeNoodle,ProcessMS=RobotTakeNoodle?"机器人正在取面过程中....":""}, - new ProcessModel { ProcessName="出餐",IsMark=AllowFallNoodle,ProcessMS=AllowFallNoodle?"机器人正在出餐过程中....":"" } - } - }); - #endregion - - } - - /// - /// 初始化上报流程 - /// - public void Init() - { - ThreadManage.GetInstance.StartLong(new Action(() => - { - if (IOTDev.client.IsConnected && GeneralConfig.DeviceType.ToString() == "MORKS") - { - //SetData(); - IOTDev.GetInstance().IOT_Publish(IOTDev.PubTopic, iOTDevSXModel.Tojson()); - } - Thread.Sleep(5000); - }), "设备IOT上报云端"); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,iOTDevSXModel.Tojson()); } + #endregion + #region 私有函数 /// - /// 接收云端消息 + /// 获取属性状态 /// - /// - /// - private void actionIOTHandler(string topic, string message) + private T GetTypeValue(string str) { - if (IOTDev.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端 - { - IOTCommandModel iOTCommand = Tools.JsonToObjectTools(message); - if (iOTCommand.deviceName == InternetInfo.DeviceName) - ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); - } + return (T)SimpleFactory.GetInstance.GVL?.GetType().GetProperty(str).GetValue(SimpleFactory.GetInstance.GVL,null); } #endregion } + + /// + /// 日志上报 + /// + public class LogIOT + { + public string SZXX { get; set; } + } + /// + /// 告警上报 + /// + public class AlarmIOT + { + public string GJXX { get; set; } + } + /// + /// 节点状态上报 + /// + public class NodeStatusIOT + { + public string NodeStatus { get; set; } + } } diff --git a/HBLConsole.GVL/InternetInfo.cs b/HBLConsole.GVL/InternetInfo.cs index 7643ee7..b34fbb2 100644 --- a/HBLConsole.GVL/InternetInfo.cs +++ b/HBLConsole.GVL/InternetInfo.cs @@ -36,10 +36,6 @@ namespace HBLConsole.GVL ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"]; ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); - ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"]; - DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"]; - DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"]; - DeviceMS= System.Configuration.ConfigurationManager.AppSettings["DeviceMS"]; while (StockServer == null) { try @@ -124,24 +120,5 @@ namespace HBLConsole.GVL public static string StockServer { get; set; } #endregion - #region IOT设备地址 - /// - /// IOT ProductKey - /// - public static string ProductKey { get; set; } - /// - /// IOT DeviceName - /// - public static string DeviceName { get; set; } - /// - /// IOT DeviceSecret - /// - public static string DeviceSecret { get; set; } - /// - /// IOT DeviceMS - /// - public static string DeviceMS { get; set; } - #endregion - } } diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 6849f58..bf6a7ee 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -69,7 +69,7 @@ namespace HBLConsole.MainConsole MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - IotReport.GetInstance.Init();//IOT 上报 + IotReport.GetInstance.Initialize();//IOT 上报 HeartbeatReport.GetInstance.Init();//心跳上报 @@ -110,7 +110,7 @@ namespace HBLConsole.MainConsole { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - IotReport.GetInstance.Init();//IOT 上报 + IotReport.GetInstance.Initialize();//IOT 上报 HeartbeatReport.GetInstance.Init();//心跳上报 diff --git a/HBLConsole/App.config b/HBLConsole/App.config index 4070578..d9cad27 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -4,7 +4,7 @@ - + @@ -12,13 +12,7 @@ - - - - - - - + From eba61aaf8938bb35997fe816dff335610b5b0d24 Mon Sep 17 00:00:00 2001 From: taoye Date: Thu, 31 Mar 2022 18:04:31 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=96=E9=9D=A2?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.MORKD/Control_MORKD.cs | 12 +++++++++++- HBLConsole.MORKD/GVL_MORKD.cs | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index 07a156f..4300260 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -350,6 +350,8 @@ namespace HBLConsole.MORKD } } + bool isNotTakeNoodle = false; //true-无法取面,false-可以取面 + /// /// 取面任务 /// @@ -361,9 +363,13 @@ namespace HBLConsole.MORKD if (mORKD.TurntableInPlace && !mORKD.OutNoodleing && mORKD.RBTakeNoodleTask.Count > 0) { int loc = mORKD.CookNoodleBasketIdle.GetIndex(false);//查找煮面炉空闲位置 - int IdleLoc = mORKD.CookNodeState.GetIndex(false);//获取煮面炉空闲状态互锁位置 + int IdleLoc = mORKD.CookNodeState.GetIndex(false);//获取煮面炉空闲状态互锁位置 if (loc >= 0 && loc <= 5) { + if (isNotTakeNoodle) + { + return; + } if (mORKD.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo)) { mORKD.RBTakeNoodleStart((ushort)(loc + 1), orderLocInfo.Loc); @@ -373,6 +379,8 @@ namespace HBLConsole.MORKD //MessageLog.GetInstance.Show($"订单【{orderLocInfo.SuborderId}】,煮面栏:[{loc + 1}]"); mORKD.TakeNoodleInterlock = true; MessageLog.GetInstance.Show($"{loc + 1}号煮面篮订单ID:[{orderLocInfo.SuborderId}]"); + Trace.WriteLine($"%%%开始下面。。。" + $"{loc + 1}号煮面篮订单ID:[{orderLocInfo.SuborderId}]"); + isNotTakeNoodle = true; } } } @@ -385,6 +393,7 @@ namespace HBLConsole.MORKD mORKD.AllowTakeNoodle = false; MessageLog.GetInstance.Show("转台取面完成"); mORKD.TakeNoodleCompleteReset(); + isNotTakeNoodle = false; } } @@ -423,6 +432,7 @@ namespace HBLConsole.MORKD MessageLog.GetInstance.Show($"从{loc + 1}号位置取面"); MessageLog.GetInstance.Show($"倒入{index + 1}号碗位置"); MessageLog.GetInstance.Show($"{index + 1}号轴允许倒浇头ID:[{ mORKD.AxisAllowInvertedSoupID[index]}]"); + //Trace.WriteLine($"###出面控制。。。"); } } } diff --git a/HBLConsole.MORKD/GVL_MORKD.cs b/HBLConsole.MORKD/GVL_MORKD.cs index e37327d..0672b45 100644 --- a/HBLConsole.MORKD/GVL_MORKD.cs +++ b/HBLConsole.MORKD/GVL_MORKD.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Collections.Concurrent; using HBLConsole.Model; using HBLConsole.Attributes; +using System.Diagnostics; namespace HBLConsole.MORKD { @@ -47,6 +48,7 @@ namespace HBLConsole.MORKD { ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, OutNoodleLoc); ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, BowlLoc); + Trace.WriteLine($"#######出面位置:{OutNoodleLoc},碗位置:{BowlLoc}"); ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true); } From 9e1738197b05bf07863a43fb79cd76cf7ba36a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Thu, 31 Mar 2022 18:34:15 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E5=B1=95=E4=BC=9A=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Business/AbstractServer/Base.cs | 3 +- HBLConsole.Business/M2MqttHelper.cs | 1 - HBLConsole.MORKS/Control_MORKS.cs | 75 ++++++++++++++++------ HBLConsole.MainConsole/Main.cs | 10 +-- HBLConsole.Model/ViewModel/ParSet.cs | 17 +++++ HBLConsole.Service/SystemHelper.cs | 9 ++- HBLConsole.Service/ThreadManage.cs | 26 ++------ HBLConsole/App.config | 9 +-- HBLConsole/App.xaml.cs | 4 +- HBLConsole/View/DebugView.xaml | 6 +- HBLConsole/View/MainView.xaml | 2 + HBLConsole/View/ParSetView.xaml | 39 +++++++++++ HBLConsole/View/ParSetView.xaml.cs | 28 ++++++++ HBLConsole/ViewModel/DebugViewModel.cs | 73 ++++----------------- HBLConsole/ViewModel/ParSetViewModel.cs | 26 ++++++++ HBLConsole/ViewModel/ViewModelBase.cs | 9 ++- 16 files changed, 214 insertions(+), 123 deletions(-) create mode 100644 HBLConsole.Model/ViewModel/ParSet.cs create mode 100644 HBLConsole/View/ParSetView.xaml create mode 100644 HBLConsole/View/ParSetView.xaml.cs create mode 100644 HBLConsole/ViewModel/ParSetViewModel.cs diff --git a/HBLConsole.Business/AbstractServer/Base.cs b/HBLConsole.Business/AbstractServer/Base.cs index ac3d098..f8f3ba4 100644 --- a/HBLConsole.Business/AbstractServer/Base.cs +++ b/HBLConsole.Business/AbstractServer/Base.cs @@ -74,12 +74,11 @@ namespace HBLConsole.Business.AbstractServer { Json.Data.recipeBoms = JsonConvert.DeserializeObject(result); ActionManage.GetInstance.Send("recipeBom"); - //WritePlcData(); + MessageLog.GetInstance.Show("接收到辅料信息"); } else if (PushType == 0) { Json.Data.orderMaterialDelivery = JsonConvert.DeserializeObject(result); - } } catch (Exception ex) diff --git a/HBLConsole.Business/M2MqttHelper.cs b/HBLConsole.Business/M2MqttHelper.cs index 6b71abb..b503e56 100644 --- a/HBLConsole.Business/M2MqttHelper.cs +++ b/HBLConsole.Business/M2MqttHelper.cs @@ -68,7 +68,6 @@ namespace HBLConsole.Business MqttM2.GetInstance.PublishInfo(PublishContent); //mqttClient.Publish($"/sys/grgp0rFA2uu/{deviceName}/thing/event/property/post", Encoding.UTF8.GetBytes(PublishContent), 0, false); - Thread.Sleep(1000); }), "阿里云数据上报", new Action(() => { MqttM2.GetInstance.DisConnect(); })); } diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index 1e848f3..afda066 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -27,16 +27,38 @@ namespace HBLConsole.MORKS ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); } - public void ConnectOk() { - mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); - mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); - mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()); - //WriteRecipeBoms(); ReadData(); Main(); ResetProgram(); + ActionManage.GetInstance.Register(new Action(() => + { + Random rd = new Random(); + ThreadManage.GetInstance.StartLong(new Action(() => + { + int NoodleLoc = rd.Next(1, 6); + int BowlLoc = rd.Next(10, 11); + string guid = new Guid().ToString(); + + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid }); + MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】"); + + mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid }); + MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】"); + Thread.Sleep(60000); + }), "ForOrder"); + }), "EnableForOrder"); + + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance.StopTask("ForOrder", new Action(() => + { + mORKS.RBTakeNoodleTask.Clear(); + mORKS.TakeBowlTask.Clear(); + })); + }), "StopForOrder"); + MessageLog.GetInstance.Show("MORKS 设备初始化完成"); } @@ -113,14 +135,14 @@ namespace HBLConsole.MORKS })); - //var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); - //if (ResLoc != null) - //{ - // if (ResLoc is ushort loc) - // { - // mORKS.TurntableFeedbackloc = loc; - // } - //} + var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); + if (ResLoc != null) + { + if (ResLoc is ushort loc) + { + mORKS.TurntableFeedbackloc = loc; + } + } Thread.Sleep(500); }), "ReadPLCData"); @@ -221,9 +243,19 @@ namespace HBLConsole.MORKS batching_W.BatchingLoc = "10"; mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(batching_M.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = batching_M.BatchingId }); - int index = Array.FindIndex(Json.Data.recipeBoms.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId); - index++; - mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(batching_W.BatchingLoc), SuborderId = morkOrderPush.SuborderId, RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 }); + int index = 0; + if (Json.Data.recipeBoms != null) + { + index = Array.FindIndex(Json.Data.recipeBoms?.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId); + index++; + } + mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() + { + Loc = ushort.Parse(batching_W.BatchingLoc), + SuborderId = morkOrderPush.SuborderId, + RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 + }); + } } @@ -235,8 +267,8 @@ namespace HBLConsole.MORKS { mORKS.AllowRun = mORKS.InitComplete; //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; - //GeneralConfig.Healthy = true; - GeneralConfig.Healthy = mORKS.AllowRun; + GeneralConfig.Healthy = true; + //GeneralConfig.Healthy = mORKS.AllowRun; TakeBowlTask(); @@ -305,6 +337,7 @@ namespace HBLConsole.MORKS if (!mORKS.TurntableLocLists.Contains(loc)) { TurntableStart(loc); + MessageLog.GetInstance.Show("未检测到物料,启动转台查找"); return; } } @@ -475,6 +508,7 @@ namespace HBLConsole.MORKS { mORKS.TakeNoodleInterlock = false; mORKS.AllowTakeNoodle = false; + mORKS.TurntableInterlock = false; MessageLog.GetInstance.Show("取面完成"); TakeNoodleCompleteReset(); } @@ -513,6 +547,7 @@ namespace HBLConsole.MORKS MessageLog.GetInstance.Show("成功写入配方数据"); } } + else { MessageLog.GetInstance.Show("配方数据为空"); } } /// @@ -591,11 +626,11 @@ namespace HBLConsole.MORKS /// private void TakeBowlControl(ushort loc) { - if (loc == 10) + if (loc == 10)//小碗 { ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true); } - else if (loc == 11) + else if (loc == 11)//大碗 { ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true); } diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 6849f58..b836f41 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -53,23 +53,23 @@ namespace HBLConsole.MainConsole { ThreadManage.GetInstance.Start(new Action(() => { - SimpleFactory.GetInstance.DeviceInit();//设备初始化 + //SimpleFactory.GetInstance.DeviceInit();//设备初始化 InternetInfo.ConfigInit();//从 consul 获取配置数据 Topics.Clear(); Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId)); Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId)); - + //MQTT 连接成功 MqttHelper.GetInstance.ConnectOk = new Action(() => { - //SimpleFactory.GetInstance.DeviceInit();//设备初始化 + SimpleFactory.GetInstance.DeviceInit();//设备初始化 MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - IotReport.GetInstance.Init();//IOT 上报 + //IotReport.GetInstance.Init();//IOT 上报 HeartbeatReport.GetInstance.Init();//心跳上报 @@ -110,7 +110,7 @@ namespace HBLConsole.MainConsole { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - IotReport.GetInstance.Init();//IOT 上报 + //IotReport.GetInstance.Init();//IOT 上报 HeartbeatReport.GetInstance.Init();//心跳上报 diff --git a/HBLConsole.Model/ViewModel/ParSet.cs b/HBLConsole.Model/ViewModel/ParSet.cs new file mode 100644 index 0000000..93577ab --- /dev/null +++ b/HBLConsole.Model/ViewModel/ParSet.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + +namespace HBLConsole.Model +{ + public class ParSet : ObservableObject + { + + public bool IsAutoStart { get { return _mIsAutoStart; } set { _mIsAutoStart = value; OnPropertyChanged(); } } + private bool _mIsAutoStart; + + } +} diff --git a/HBLConsole.Service/SystemHelper.cs b/HBLConsole.Service/SystemHelper.cs index bb79c99..ad85a6b 100644 --- a/HBLConsole.Service/SystemHelper.cs +++ b/HBLConsole.Service/SystemHelper.cs @@ -95,9 +95,12 @@ namespace HBLConsole.Service /// public bool IsAutoStart() { - //RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"); - RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"); - return registryKey.GetValueNames().Contains(GetApplicationName); + RegistryKey R_local = Registry.CurrentUser; + RegistryKey R_run = R_local.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + bool res = R_run.GetValueNames().Contains(GetApplicationName); + R_run.Close(); + R_local.Close(); + return res; } diff --git a/HBLConsole.Service/ThreadManage.cs b/HBLConsole.Service/ThreadManage.cs index 2452ef0..3ef6179 100644 --- a/HBLConsole.Service/ThreadManage.cs +++ b/HBLConsole.Service/ThreadManage.cs @@ -36,24 +36,6 @@ namespace HBLConsole.Service ActionManage.GetInstance.Register(ExitCallback, guid + key); } - //public void StopTask(string[] keys, Action ExitCallback = null) - //{ - // lock (_lock) - // if (keys != null) - // { - // for (int i = 0; i < keys.Length; i++) - // { - // this.keys.Add(keys[i]); - // callbackKey.Append(keys[i]); - // if (CancellationTokenSources.ContainsKey(guid + keys[i])) - // CancellationTokenSources[guid + keys[i]]?.Cancel(); - // } - // callbackKey.Append(guid); - // ActionManage.GetInstance.Register(ExitCallback, callbackKey.ToString()); - // } - - //} - /// /// 长任务,带 while true 的循环 /// @@ -62,17 +44,21 @@ namespace HBLConsole.Service public void StartLong(Action action, string key, Action RunComplete = null) { CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(async () => { try { while (!CancellationTokenSources[guid + key].IsCancellationRequested) { - if (action != null) action(); + if (action != null) + { + action(); + } } } catch (Exception ex) { + MessageLog.GetInstance.Show(ex.ToString()); MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); Threads.TryRemove(guid + key, out Task temp1); diff --git a/HBLConsole/App.config b/HBLConsole/App.config index 4070578..de52edd 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -4,14 +4,15 @@ - + - + + @@ -24,8 +25,8 @@ - - + + \ No newline at end of file diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index 3371cc8..d40b8ed 100644 --- a/HBLConsole/App.xaml.cs +++ b/HBLConsole/App.xaml.cs @@ -35,7 +35,7 @@ namespace HBLConsole protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); - SystemHelper.GetInstance.AutoStart(false); + //SystemHelper.GetInstance.AutoStart(true); SystemHelper.GetInstance.CreateDesktopShortcut(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; MainConsole.Main.GetInstance.DataInit(); @@ -44,7 +44,7 @@ namespace HBLConsole mainView.Show(); SplitScreenDisplay(); NoCompleteOrderInit(); - MainConsole.Main.GetInstance.BusinessSimTest(); + MainConsole.Main.GetInstance.BusinessInit(); } /// diff --git a/HBLConsole/View/DebugView.xaml b/HBLConsole/View/DebugView.xaml index 990399f..79f27d8 100644 --- a/HBLConsole/View/DebugView.xaml +++ b/HBLConsole/View/DebugView.xaml @@ -264,10 +264,8 @@