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 82% rename from HBLConsole.Business/MessageServer/Base.cs rename to HBLConsole.Business/AbstractServer/Base.cs index dc1206b..c454d42 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 { @@ -22,10 +22,24 @@ namespace HBLConsole.Business.MessageServer if (orderInfo == null) return; if (orderInfo is MorkOrderPush morkOrderpush) { - OrderData order = Json.Data.morkOrderPushes.Find(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); + //OrderData order = Json.Data.morkOrderPushes.Find(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); + //if (order == null)//防止重复订单 + //{ + // Json.Data.morkOrderPushes.Add(new OrderData() + // { + // OrderStatus = ORDER_STATUS.WAIT, + // IsSelected = true, + // OrderPush = morkOrderpush + // }); + // ActionManage.GetInstance.Send("AddOrder", morkOrderpush); + // ActionManage.GetInstance.Send("DataParse", morkOrderpush); + //} + + + OrderData order = Json.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); if (order == null)//防止重复订单 { - Json.Data.morkOrderPushes.Add(new OrderData() + Json.Data.orderLists.Add(new OrderData() { OrderStatus = ORDER_STATUS.WAIT, IsSelected = true, @@ -74,12 +88,11 @@ namespace HBLConsole.Business.MessageServer { 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) @@ -109,33 +122,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.Business/AlarmHelper.cs b/HBLConsole.Business/AlarmHelper.cs index 5dd4c00..68e9225 100644 --- a/HBLConsole.Business/AlarmHelper.cs +++ b/HBLConsole.Business/AlarmHelper.cs @@ -8,6 +8,7 @@ using System.Drawing; using HBLConsole.Service; using HBLConsole.Model; using System.Collections.ObjectModel; +using HBLConsole.GVL; namespace HBLConsole.Business { @@ -64,6 +65,15 @@ namespace HBLConsole.Business }; Sqlite.GetInstance.Base.Add(tempAlarm); + IotReport.GetInstance.SendAlarmMessage(new BPA.Message.API请求.AlarmTable + { + AlarmTime=DateTime.Now, + AlarmType= tempAlarm.Grade, + AlarmMessage= tempAlarm.Info, + AlarmVla= tempAlarm.Value, + ClientId= InternetInfo.ClientId.ToString() + }); + if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null) { Alarms.Add(tempAlarm); diff --git a/HBLConsole.Business/HeartbeatReport.cs b/HBLConsole.Business/HeartbeatReport.cs index 518e5c1..808bfa5 100644 --- a/HBLConsole.Business/HeartbeatReport.cs +++ b/HBLConsole.Business/HeartbeatReport.cs @@ -46,6 +46,7 @@ namespace HBLConsole.Business MessagePackage.Timestamp = DateTime.Now; MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage(); MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize()); + IotReport.GetInstance.SendTargetMessage(); Thread.Sleep(1000); }), "设备心跳上报"); diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs index 751b0ab..e61d408 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,163 +20,209 @@ 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 变量 - /// - /// 大屏上报Model + /// 查询出当前设备信息 /// - public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { SBMC = InternetInfo.DeviceName, SBMS = InternetInfo.DeviceMS }; - + public DeviceTable device; /// - /// 当前控制的设备控件 + /// 大屏上报Model /// - //public IControl control; + public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { }; #endregion - #region 事件 + #region IOT上报公共调用 /// - /// 关闭IOT连接 + /// 上报告警消息 + /// 调用示例: SendAlarmMessage(new AlarmTable { AlarmTime = DateTime.Now,AlarmType = "1",AlarmMessage = "煮面机异常",AlarmVla = "煮面机" }); /// - public static void Close() + /// + public void SendAlarmMessage(AlarmTable alarmTable) { - if (IOTDev.client != null) - IOTDev.GetInstance().Disconnect(); + if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device!=null) + { + alarmTable.ClientId = InternetInfo.ClientId.ToString(); + alarmTable.devicename = device.devicename; + 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 T GetTypeValue(string str) + /// + public void SendLogMessage(LogTable logTable) { + if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device != null) + { + logTable.devicename = device.devicename; + 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); + } + } - return (T)SimpleFactory.GetInstance.GVL.GetType().GetProperty(str).GetValue(SimpleFactory.GetInstance.GVL, null); - //return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null); + /// + /// 上报节点状态消息 + /// 调用示例:SendNodeStatusMessage("json字符串"); + /// + /// + public void SendNodeStatusMessage(string json) + { + if (IOTDevServer.client!=null && IOTDevServer.client.IsConnected && device != null) + { + string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new NodeStatusIOT { NodeStatus = Tools.JsonConvertTools(json) } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr); + } } /// - /// 设置上报数据 + /// 上报属性状态 + /// 调用示例:SendTargetMessage(); /// - public void SetData() + /// + public void SendTargetMessage() { - #region 上报数据整理 - #region 基本数据 - //设置基本属性与状态 - iOTDevSXModel.SetJBSX(new DevSX + if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device != null) { - data = new List + string kzsx = string.Empty; + string jbsx = Tools.JsonConvertTools(new DevSX + { + data = new List { new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected ,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."}, new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true } } - }); - #endregion - - #region 扩展数据 - bool IsAllowRun = GetTypeValue("AllowRun"); - bool TemperatureReached = GetTypeValue("TemperatureReached"); - bool MissingBowl = GetTypeValue("MissingBowl"); - bool MissingBowlSignal2 = GetTypeValue("MissingBowlSignal2"); - bool IsNoodles = GetTypeValue("IsNoodles");//转台 - bool AllowFallNoodle = GetTypeValue("AllowFallNoodle");//是否允许到面 - bool[] CookNoodlesComplete = GetTypeValue("CookNoodlesComplete");//煮面完成上升信号 - bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o); - //设置扩展属性与状态,连接上机器人后才会处罚 - if (IsAllowRun) - { - iOTDevSXModel.SetKZSX(new DevSX + }); + bool IsAllowRun = GetTypeValue("AllowRun"); + bool TemperatureReached = GetTypeValue("TemperatureReached"); + bool MissingBowl = GetTypeValue("MissingBowl"); + bool MissingBowlSignal2 = GetTypeValue("MissingBowlSignal2"); + bool IsNoodles = GetTypeValue("IsNoodles");//转台 + bool AllowFallNoodle = GetTypeValue("AllowFallNoodle");//是否允许到面 + bool[] CookNoodlesComplete = GetTypeValue("CookNoodlesComplete");//煮面完成上升信号 + bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o); + //设置扩展属性与状态,连接上机器人后才会处罚 + if (IsAllowRun) { - data = new List + kzsx = Tools.JsonConvertTools(new DevSX { - new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached , - SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."}, - new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl , - SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."}, - new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 , - SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."}, - new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles , - SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."}, - new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) , - SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."} - } - }); - } - else - { - iOTDevSXModel.SetKZSX(new DevSX { data = new List { new DevSXBase { SXMC = "", SXLX = "" } } }); + data = new List + { + new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached , + SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."}, + new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl , + SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."}, + new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 , + SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."}, + new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles , + SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."}, + new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) , + SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."} + } + }); + } + string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new TargetIOT { JBSX = jbsx,KZSX = kzsx } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr); } - #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 + } + #endregion - bool InitComplete = GetTypeValue("InitComplete"); - bool RobotTakeNoodle = GetTypeValue("RobotTakeNoodle"); - bool RobotOutMeal = GetTypeValue("RobotOutMeal"); - iOTDevSXModel.SetLCSB(new ProcessMessage + #region 外部关闭或初始化IOT调用 + /// + /// 初始化IOT连接 + /// + public bool Initialize() + { + if (!IOTDevServer.GetInstance().CreateLinks(InternetInfo.ClientId,out device)) { - 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 - + 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 void Init() + public static void Close() { - 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上报云端"); + if (IOTDevServer.client != null) + IOTDevServer.GetInstance().Disconnect(); } + #endregion + #region 云端订阅主题消息接收 /// /// 接收云端消息 /// /// /// - private void actionIOTHandler(string topic, string message) + private void DevIOTActionHandler(string topic, string message) { - if (IOTDev.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端 + if (IOTDevServer.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端 { IOTCommandModel iOTCommand = Tools.JsonToObjectTools(message); - if (iOTCommand.deviceName == InternetInfo.DeviceName) + if (iOTCommand.deviceName == device.devicename) ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); } } #endregion + + #region 私有函数 + /// + /// 获取属性状态 + /// + private T GetTypeValue(string str) + { + 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; } + } + /// + /// 基本属性与扩展属性 + /// + public class TargetIOT + { + /// + /// 基本属性 + /// + public string JBSX { get; set; } + /// + /// 扩展属性 + /// + public string KZSX { get; set; } } } diff --git a/HBLConsole.Business/M2MqttHelper.cs b/HBLConsole.Business/M2MqttHelper.cs index 6b71abb..6b29b05 100644 --- a/HBLConsole.Business/M2MqttHelper.cs +++ b/HBLConsole.Business/M2MqttHelper.cs @@ -68,8 +68,7 @@ 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(); })); + }), "阿里云数据上报", false, new Action(() => { MqttM2.GetInstance.DisConnect(); })); } } diff --git a/HBLConsole.Business/ServerData.cs b/HBLConsole.Business/ServerData.cs index 41012c8..fcd67d8 100644 --- a/HBLConsole.Business/ServerData.cs +++ b/HBLConsole.Business/ServerData.cs @@ -41,7 +41,7 @@ namespace HBLConsole.Business } } Thread.Sleep(100); - }), "mqtt消息处理"); + }), "mqtt消息处理", true); } diff --git a/HBLConsole.Communication/ModbusTcpHelper.cs b/HBLConsole.Communication/ModbusTcpHelper.cs index 5522c86..248fd02 100644 --- a/HBLConsole.Communication/ModbusTcpHelper.cs +++ b/HBLConsole.Communication/ModbusTcpHelper.cs @@ -77,6 +77,38 @@ namespace HBLConsole.Communication MessageLog.GetInstance.Show("ModbusTcp 连接成功!"); } + public int GetBoolAddress(string address) + { + if (address != null && address.Length >= 4) + { + var res = address.Substring(1).Split('.'); + if (res != null && res.Length == 2) + { + if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress)) + { + if (ExitAddress >= 0 && ExitAddress <= 7) + { + return (firstAddress * 8) + 320 + ExitAddress; + } + } + } + } + return -1; + } + + public int GetWordAddress(string address) + { + if (address != null && address.Length > 3) + { + var res = address.Substring(2); + if (res != null && int.TryParse(res, out int tempAddress)) + { + return (tempAddress / 2) + 100; + } + } + return -1; + } + public void Readbool(ushort startAddress, ushort len, Action action) { object result; diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index 24dd314..50f31e9 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -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.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.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/Alarm_MORKD.cs b/HBLConsole.MORKD/Alarm_MORKD.cs index eff31fd..8540aa0 100644 --- a/HBLConsole.MORKD/Alarm_MORKD.cs +++ b/HBLConsole.MORKD/Alarm_MORKD.cs @@ -9,10 +9,142 @@ using HBLConsole.Attributes; namespace HBLConsole.MORKD { /// - /// 报警实体类 + /// 报警实体信息 /// public class Alarm_MORKD : IAlarm { + #region PLC-->上位机 + + /** + * Modbus地址数值,如何配置 + */ + + /// + /// 煮面机左侧低温报警 + /// PLC ---> M550.0 + /// ModbusTcp --> 1570 + /// + [VariableMonitor("煮面机左侧低温报警", "550.0", "1570")] + public bool MachineLeftLowTemperature { get; set; } + + /// + /// 煮面机左侧低温报警 + /// PLC ---> M550.1 + /// ModbusTcp --> 1571 + /// + [VariableMonitor("煮面机右侧低温报警", "550.1", "1571")] + public bool MachineRightLowTemperature { get; set; } + + /// + /// 供碗1缺碗 + /// PLC ---> M550.2 + /// ModbusTcp --> 1572 + /// + [VariableMonitor("供碗1缺碗", "550.2", "1572")] + public bool Supply1_LossBowl { get; set; } + + /// + /// 供碗2缺碗 + /// PLC ---> M550.3 + /// ModbusTcp --> 1573 + /// + [VariableMonitor("供碗2缺碗", "550.3", "1573")] + public bool Supply2_LossBowl { get; set; } + + /// + /// 供碗1出碗检测异常 + /// PLC ---> M550.4 + /// ModbusTcp --> 1574 + /// + [VariableMonitor("供碗1出碗检测异常", "550.4", "1574")] + public bool Supply1_ErrorOutBowl { get; set; } + + /// + /// 供碗2出碗检测异常 + /// PLC ---> M550.5 + /// ModbusTcp --> 1575 + /// + [VariableMonitor("供碗2出碗检测异常", "550.5", "1575")] + public bool Supply2_ErrorOutBowl { get; set; } + + /// + /// 推碗气缸故障 + /// PLC ---> M550.6 + /// ModbusTcp --> 1576 + /// + [VariableMonitor("推碗气缸故障", "550.6", "1576")] + public bool PushBowlCylinderError { get; set; } + + /// + /// 煮面机通讯异常 + /// PLC ---> M550.7 + /// ModbusTcp --> 1577 + /// + [VariableMonitor("煮面机通讯异常", "550.7", "1577")] + public bool NoodleMacCommunicateError { get; set; } + + /// + /// 煮面机通讯异常 + /// PLC ---> M551.0 + /// ModbusTcp --> 1580 + /// + [VariableMonitor("配料机通讯异常", "551.0", "1580")] + public bool DosingMacCommunicateError { get; set; } + + /// + /// 机器人通讯异常 + /// PLC ---> M551.1 + /// ModbusTcp --> 1581 + /// + [VariableMonitor("机器人通讯异常", "551.1", "1581")] + public bool RobotMacCommunicateError { get; set; } + + /// + /// 机器人初始化失败 + /// PLC ---> M551.3 + /// ModbusTcp --> 1583 + /// + [VariableMonitor("机器人初始化失败", "551.3", "1583")] + public bool RobotInitError { get; set; } + + /// + /// 机器人急停 + /// PLC ---> M551.4 + /// ModbusTcp --> 1584 + /// + [VariableMonitor("机器人急停", "551.4", "1584")] + public bool RobotUrgentStop { get; set; } + + /// + /// 机器人不在远程模式 + /// PLC ---> M551.5 + /// ModbusTcp --> 1585 + /// + [VariableMonitor("机器人不在远程模式", "551.5", "1585")] + public bool RobotNotInRemoteMode { get; set; } + + /// + /// 机器人伺服未就绪 + /// PLC ---> M551.6 + /// ModbusTcp --> 1586 + /// + [VariableMonitor("机器人伺服未就绪", "551.6", "1586")] + public bool RobotNotInReady { get; set; } + + /// + /// 机器人本体异常 + /// PLC ---> M551.7 + /// ModbusTcp --> 1587 + /// + [VariableMonitor("机器人本体异常", "551.7", "1587")] + public bool RobotSelfInException { get; set; } + + #endregion + + + + + } } diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index c145382..10b84ed 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -63,8 +63,6 @@ namespace HBLConsole.MORKD }), "InitCommand"); } - bool Initing = false; - /// /// 复位程序 /// @@ -72,7 +70,7 @@ namespace HBLConsole.MORKD { ThreadManage.GetInstance.StartLong(new Action(() => { - if (RTrig.GetInstance("ResetProgram").Start(Initing)) + if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) { ThreadManage.GetInstance.StopTask("MainTask", new Action(() => { @@ -145,10 +143,9 @@ namespace HBLConsole.MORKD mORKD.TakeSoupRobotIdle = bools[24]; mORKD.TakeSoupComplete = bools[27]; mORKD.PutNoodleTakeMealComplete = bools[28]; - Initing = bools[29]; + DeviceData.Initing = bools[29]; })); - ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action((bools) => { mORKD.TurntableLowerLimit = bools[0]; @@ -174,6 +171,34 @@ namespace HBLConsole.MORKD mORKD.TurntableFeedbackloc = loc; } } + + + /** 读取Alarm 报警信息 2022.4.2 + */ + ModbusTcpHelper.GetInstance.Readbool(1570, 20, new Action((bools) => + { + // 0 -- 1570 + //10 -- 1580 + int bit1570 = 1570; + alarm.MachineLeftLowTemperature = bools[bit1570]; + alarm.MachineRightLowTemperature = bools[bit1570 + 1]; + alarm.Supply1_LossBowl = bools[bit1570 + 2]; + alarm.Supply2_LossBowl = bools[bit1570 + 3]; + alarm.Supply1_ErrorOutBowl = bools[bit1570 + 4]; + alarm.Supply2_ErrorOutBowl = bools[bit1570 + 5]; + alarm.PushBowlCylinderError = bools[bit1570 + 6]; + alarm.NoodleMacCommunicateError = bools[bit1570 + 7]; + // + int bit1580 = 1580; + alarm.DosingMacCommunicateError = bools[bit1580]; + alarm.RobotMacCommunicateError = bools[bit1580 + 1]; + alarm.RobotInitError = bools[bit1580 + 3]; + alarm.RobotUrgentStop = bools[bit1580 + 4]; + alarm.RobotNotInRemoteMode = bools[bit1580 + 5]; + alarm.RobotNotInReady = bools[bit1580 + 6]; + alarm.RobotSelfInException = bools[bit1580 + 7]; + })); + Thread.Sleep(100); }), "ReadPLCData"); } @@ -350,6 +375,8 @@ namespace HBLConsole.MORKD } } + bool isNotTakeNoodle = false; //true-无法取面,false-可以取面 + /// /// 取面任务 /// @@ -361,9 +388,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 +404,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 +418,7 @@ namespace HBLConsole.MORKD mORKD.AllowTakeNoodle = false; MessageLog.GetInstance.Show("转台取面完成"); mORKD.TakeNoodleCompleteReset(); + isNotTakeNoodle = false; } } @@ -405,6 +439,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) @@ -422,6 +457,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($"###出面控制。。。"); } } } @@ -431,6 +467,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; + } + } + + /// /// 取浇头控制 /// 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); } diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index 823922e..3c7b329 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -101,8 +101,10 @@ 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)); - ReadData(); + Main(); + ReadData(); + ThreadManage.GetInstance.StartLong(new Action(() => { @@ -191,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_欢迎); @@ -344,17 +347,41 @@ 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 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..8e5acab 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 { @@ -26,39 +27,60 @@ namespace HBLConsole.MORKS ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); } - public void ConnectOk() { - //WriteRecipeBoms(); ReadData(); Main(); - //ResetProgram(); + 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 设备初始化完成"); } - /// - /// 复位程序 - /// private void ResetProgram() { ThreadManage.GetInstance.StartLong(new Action(() => { - if (RTrig.GetInstance("ResetProgram").Start(mORKS.DeviceIniting)) + if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) { 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(); - })); + { + ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => + { + mORKS = null; + mORKS = new GVL_MORKS(); + ActionManage.GetInstance.Send("ResetProgram"); + ReadData(); + Main(); + })); + })); } + Thread.Sleep(10); }), "ResetProgram"); } @@ -71,11 +93,11 @@ namespace HBLConsole.MORKS 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]; - })); + { + mORKS.RobotTakeNoodle = bools[0]; + mORKS.RobotOutMeal = bools[1]; + mORKS.MoveTurntable = bools[2]; + })); ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => { @@ -89,7 +111,7 @@ namespace HBLConsole.MORKS mORKS.RobotIdle = bools[7]; mORKS.TakeMealDetect = bools[8]; mORKS.MissingBowl = bools[9]; - mORKS.DeviceIniting = bools[10]; + DeviceData.Initing = bools[10]; mORKS.TurntableLowerLimit = bools[11]; mORKS.MissingBowlSignal2 = bools[12]; mORKS.TurntableUpLimit = bools[13]; @@ -194,53 +216,58 @@ namespace HBLConsole.MORKS } } + int OrderCount = 0; + /// /// 数据解析 /// public void DataParse(T order) { + OrderCount++; + MessageLog.GetInstance.Show($"接收到{OrderCount}次订单"); if (order is MorkOrderPush morkOrderPush) { - BatchingInfo batching_M = null;//面条 - BatchingInfo batching_W = null;//碗 - foreach (var item in morkOrderPush.GoodBatchings) { - var res = Json.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingId == item.BatchingId); + var res = Json.Data.orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId); if (res != null) { if (ushort.TryParse(res.BatchingLoc, out ushort loc)) { - if (loc >= 1 && loc <= 5) { batching_M = res; } - else if (loc >= 10 && loc <= 11) { batching_W = res; } + if (loc >= 1 && loc <= 5) + { + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId }); + } + else if (loc >= 10 && loc <= 11) + { + 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(res.BatchingLoc), + SuborderId = morkOrderPush.SuborderId, + RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 + }); + } } } } - if (batching_M != null && batching_W != null) - { - 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 }); - - - } } } - - 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; + GeneralConfig.Healthy = true; + //GeneralConfig.Healthy = mORKS.AllowRun; TakeBowlTask(); @@ -309,6 +336,7 @@ namespace HBLConsole.MORKS if (!mORKS.TurntableLocLists.Contains(loc)) { TurntableStart(loc); + MessageLog.GetInstance.Show("未检测到物料,启动转台查找"); return; } } @@ -327,9 +355,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 +377,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); // } - // }); + // } // } // } @@ -462,10 +493,15 @@ namespace HBLConsole.MORKS { SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE); MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】取餐完成"); - var RemoveItem = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); + //var RemoveItem = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); + //if (RemoveItem != null) + //{ + // Json.Data.morkOrderPushes.Remove(RemoveItem); + //} + var RemoveItem = Json.Data.orderLists.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); if (RemoveItem != null) { - Json.Data.morkOrderPushes.Remove(RemoveItem); + Json.Data.orderLists.Remove(RemoveItem); } ResetCookComplete(); mORKS.OutMealId = string.Empty; @@ -476,6 +512,7 @@ namespace HBLConsole.MORKS { mORKS.TakeNoodleInterlock = false; mORKS.AllowTakeNoodle = false; + mORKS.TurntableInterlock = false; MessageLog.GetInstance.Show("取面完成"); TakeNoodleCompleteReset(); } @@ -514,6 +551,7 @@ namespace HBLConsole.MORKS MessageLog.GetInstance.Show("成功写入配方数据"); } } + else { MessageLog.GetInstance.Show("配方数据为空"); } } /// @@ -592,11 +630,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.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.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 007e0e4..210b944 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -30,7 +30,7 @@ namespace HBLConsole.MainConsole if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct; LocaPath.GetInstance.FilePath = $"AccessFile\\{GeneralConfig.DeviceType.ToString()}\\"; ThreadManage.GetInstance.Start(new Action(() => { Sqlite.GetInstance.GetData(); }), "GetAlarm"); - Json.Read(); + //Json.Read(); Json.Read(); Json.Read(); Json.Read(); @@ -40,7 +40,7 @@ namespace HBLConsole.MainConsole public void DataSave() { - Json.Save(); + //Json.Save(); Json.Save(); Json.Save(); Json.Save(); @@ -53,53 +53,8 @@ namespace HBLConsole.MainConsole { ThreadManage.GetInstance.Start(new Action(() => { - //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();//设备初始化 - - MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - - IotReport.GetInstance.Init();//IOT 上报 - - HeartbeatReport.GetInstance.Init();//心跳上报 - - ServerData.GetInstance.Init();//数据处理初始化 - - //接收MQTT消息 - MqttHelper.GetInstance.MqttReceive = new Action((receivce) => - { - ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload)); - }); - }); - - //MQTT 重连成功 - MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); }); - - //MQTT 连接 - MqttHelper.GetInstance.MqttInitAsync(InternetInfo.MqttUserName, InternetInfo.MqttPassword, - InternetInfo.MqttAddress, InternetInfo.MqttPort, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); - - }), "业务逻辑初始化"); - } - - - [Obsolete("测试使用,服务正常后切换到函数 BusinessInit()")] - public void BusinessSimTest() - { - ThreadManage.GetInstance.Start(new Action(() => - { - InternetInfo.ConfigInit();//从 consul 获取配置数据 + IotReport.GetInstance.Initialize(); Topics.Clear(); Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId)); Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId)); @@ -111,8 +66,6 @@ namespace HBLConsole.MainConsole MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 - IotReport.GetInstance.Init();//IOT 上报 - HeartbeatReport.GetInstance.Init();//心跳上报 ServerData.GetInstance.Init();//数据处理初始化 diff --git a/HBLConsole.Model/CommunicationPar/DistributePlcPar.cs b/HBLConsole.Model/CommunicationPar/DistributePlcPar.cs new file mode 100644 index 0000000..bb093a6 --- /dev/null +++ b/HBLConsole.Model/CommunicationPar/DistributePlcPar.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Model +{ + + /// + /// 下发至Plc设备参数实体 + /// + public class DistributePlcPar + { + /***屏蔽煮面口**/ + public bool HideNoodleNo1 { get; set; } + public bool HideNoodleNo2 { get; set; } + public bool HideNoodleNo3 { get; set; } + public bool HideNoodleNo4 { get; set; } + public bool HideNoodleNo5 { get; set; } + public bool HideNoodleNo6 { get; set; } + + /***冷库转盘当前位置***/ + public int CurrentTurnPosition { get; set; } + + /***煮面口时间设定**/ + public int No1_Minute { get; set; } + public int No1_Second { get; set; } + public int No2_Minute { get; set; } + public int No2_Second { get; set; } + public int No3_Minute { get; set; } + public int No3_Second { get; set; } + public int No4_Minute { get; set; } + public int No4_Second { get; set; } + public int No5_Minute { get; set; } + public int No5_Second { get; set; } + public int No6_Minute { get; set; } + public int No6_Second { 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.Model/KeepParameter/MorkOrderPushPar.cs b/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs index b807fe4..3f75c43 100644 --- a/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs +++ b/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs @@ -9,6 +9,6 @@ namespace HBLConsole.Model { public class MorkOrderPushPar { - public List morkOrderPushes = new List(); + public List morkOrderPushes { get; set; } = new List(); } } 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/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/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/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; + } + + } +} diff --git a/HBLConsole.Service/ThreadManage.cs b/HBLConsole.Service/ThreadManage.cs index 2452ef0..46d20bd 100644 --- a/HBLConsole.Service/ThreadManage.cs +++ b/HBLConsole.Service/ThreadManage.cs @@ -36,47 +36,39 @@ 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 的循环 /// /// /// - public void StartLong(Action action, string key, Action RunComplete = null) + public void StartLong(Action action, string key, bool IsRestart = false, Action RunComplete = null) { CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => { + ccc: try { while (!CancellationTokenSources[guid + key].IsCancellationRequested) { - if (action != null) action(); + if (action != null) + { + action(); + } } } catch (Exception ex) { - MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); - CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); - Threads.TryRemove(guid + key, out Task temp1); + MessageLog.GetInstance.Show(ex.ToString()); + + if (IsRestart) goto ccc; + else + { + CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); + Threads.TryRemove(guid + key, out Task temp1); + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); + } } }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => { diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index 3371cc8..ecebaa6 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(); } /// @@ -94,6 +94,7 @@ namespace HBLConsole private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ErroLog = e.ExceptionObject.ToString(); + MessageLog.GetInstance.Show(ErroLog); TextHelper.GetInstance.WriteTextInfo(ErroLog, "ErroLog"); SqlHelper.GetInstance.Save(); MainConsole.Main.GetInstance.DataSave(); diff --git a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs index 75b2c1f..01813df 100644 --- a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs @@ -20,51 +20,6 @@ namespace HBLConsole.DialogWindow.ViewModel public static bool IsAutoClose = false; public ListDialogViewModel() { - //CloseCommand = new RelayCommand(() => - //{ - // Json.Data.morkOrderPushes.Clear(); - // orderStatusLists.Clear(); - // WeakReferenceMessenger.Default.Send("false", "Close"); - //}); - - //CancelCommand = new RelayCommand(() => - //{ - // Json.Data.morkOrderPushes.Clear(); - // orderStatusLists.Clear(); - // WeakReferenceMessenger.Default.Send("false", "Close"); - //}); - - //ConfirmCommand = new RelayCommand(() => - //{ - // foreach (var item in orderStatusLists) - // { - // if (!item.IsSelected) - // { - // var reslut = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == item.OrderPush.SuborderId); - // if (reslut != null) Json.Data.morkOrderPushes.Remove(reslut); - // } - // } - // foreach (var item in Json.Data.morkOrderPushes) - // { - // orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); - // } - // WeakReferenceMessenger.Default.Send("true", "Close"); - //}); - - //foreach (var item in Json.Data.morkOrderPushes) - //{ - // orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); - //} - - //if (Json.Data.morkOrderPushes.Count > 0) - //{ - // ThreadManage.GetInstance.Start(new Action(() => - // { - // Thread.Sleep(10000); - // if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); - // }), "延时退出"); - //} - //AllSelected = true; Init(); } @@ -86,8 +41,6 @@ namespace HBLConsole.DialogWindow.ViewModel ConfirmCommand = new RelayCommand(() => { - //if (Json.Data.orderLists.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ var res = orderStatusLists.Where(p => p.IsSelected == true).ToList(); if (res != null) { @@ -99,11 +52,11 @@ namespace HBLConsole.DialogWindow.ViewModel ActionManage.GetInstance.Send("DataParse", item.OrderPush); } } - //} WeakReferenceMessenger.Default.Send("true", "Close"); }); - if (Json.Data.morkOrderPushes.Count > 0) + //if (Json.Data.morkOrderPushes.Count > 0) + if (Json.Data.orderLists.Count > 0) { ThreadManage.GetInstance.Start(new Action(() => { 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HBLConsole/View/ParSetView.xaml.cs b/HBLConsole/View/ParSetView.xaml.cs new file mode 100644 index 0000000..1507100 --- /dev/null +++ b/HBLConsole/View/ParSetView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace HBLConsole.View +{ + /// + /// ParSetView.xaml 的交互逻辑 + /// + public partial class ParSetView : UserControl + { + public ParSetView() + { + InitializeComponent(); + } + } +} diff --git a/HBLConsole/ViewModel/DebugViewModel.cs b/HBLConsole/ViewModel/DebugViewModel.cs index e0796da..f301c08 100644 --- a/HBLConsole/ViewModel/DebugViewModel.cs +++ b/HBLConsole/ViewModel/DebugViewModel.cs @@ -46,7 +46,6 @@ namespace HBLConsole.ViewModel { locs.Add((ushort)(new Random().Next(1, 5))); locs.Add(10); - } ActionManage.GetInstance.Send("SimOrder", locs); @@ -63,46 +62,17 @@ namespace HBLConsole.ViewModel LoopSimOrderCommand = new RelayCommand(() => { - LoopButton = LoopButton == "循环跑单" ? "停止跑单" : "循环跑单"; + if (LoopOrderButtonContent == "循环跑单") ActionManage.GetInstance.Send("EnableForOrder"); + if (LoopOrderButtonContent == "停止跑单") ActionManage.GetInstance.Send("StopForOrder"); + LoopOrderButtonContent = LoopOrderButtonContent == "循环跑单" ? "停止跑单" : "循环跑单"; }); - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - // //try - // //{ - // // System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)async delegate - // // { - // // if (IsLoop && !IsLoopzc) - // // { - // // IsLoopzc = true; - // // if (simOrderVisibleDatas.ElementAt(0).IsSelected) - // // simOrderVisibleDatas.ElementAt(0).Loc = (ushort)(new Random().Next(1,6)); - - // // ActionManage.GetInstance.Send("SimOrder",new SimOrderData() - // // { - // // NoodleLoc = simOrderVisibleDatas.ElementAt(0).Loc, - // // SoupLoc = simOrderVisibleDatas.ElementAt(1).Loc, - // // BowlLoc = 10, - // // }); - // // await Task.Delay(50000); - // // IsLoopzc = false; - // // } - // // }); - - // //} - // //catch (Exception ex) - // //{ - - // //} - // Thread.Sleep(1000); - //}), "循环订单"); + EditCommand = new RelayCommand((o) => { if (o != null) { - //if (Json.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ var res = Json.Data.simOrderConfig.FirstOrDefault(p => p.Text == o.ToString()); if (res != null) { @@ -110,7 +80,6 @@ namespace HBLConsole.ViewModel simOrderConfitView.Show(); ActionManage.GetInstance.Send("SendSimData", res); } - //} } }); @@ -119,11 +88,8 @@ namespace HBLConsole.ViewModel { if (o != null) { - //if (Json.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ var res = Json.Data.simOrderConfig.FirstOrDefault(p => p.Text == o.ToString()); if (res != null) Json.Data.simOrderConfig.Remove(res); - //} } }); } @@ -132,18 +98,10 @@ namespace HBLConsole.ViewModel { get { - //if (!Json.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ - // Json.Data.simOrderConfig.TryAdd(GVL.GeneralConfig.DeviceType.ToString(), new ObservableCollection()); - //} return Json.Data.simOrderConfig; } set { - //if (!Json.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ - // Json.Data.simOrderConfig.TryAdd(GVL.GeneralConfig.DeviceType.ToString(), new ObservableCollection()); - //} Json.Data.simOrderConfig = value; } } @@ -160,23 +118,18 @@ namespace HBLConsole.ViewModel public RelayCommand RemoveCommand { get; set; } - public static bool IsLoop = false; - public static bool IsLoopzc = false; - public static string LoopButton + public static event EventHandler StaticPropertyChanged; + public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") { - get { return _LoopButton; } - set - { - _LoopButton = value; - if (value != "循环跑单") { IsLoop = true; LoopColor = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("Red")); } - else { IsLoop = false; LoopColor = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00c2f4")); } - OnStaticPropertyChanged(); - } + StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); } - private static string _LoopButton = "循环跑单"; - public static Brush LoopColor { get { return _LoopColor; } set { _LoopColor = value; OnStaticPropertyChanged(); } } - private static Brush _LoopColor = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00c2f4")); + + public static string LoopOrderButtonContent { get { return _mLoopOrderButtonContent; } set { _mLoopOrderButtonContent = value; OnStaticPropertyChanged(); } } + private static string _mLoopOrderButtonContent = "循环跑单"; + + + } diff --git a/HBLConsole/ViewModel/DeviceManageViewModel.cs b/HBLConsole/ViewModel/DeviceManageViewModel.cs index ed07875..ad3d1ca 100644 --- a/HBLConsole/ViewModel/DeviceManageViewModel.cs +++ b/HBLConsole/ViewModel/DeviceManageViewModel.cs @@ -60,7 +60,7 @@ namespace HBLConsole.ViewModel } private string _mClientDeviceType = string.Empty; - public static ObservableCollection communicationSets { get; set; } = new ObservableCollection(); + public static ObservableCollection communicationSets { get; set;} = new ObservableCollection(); public ObservableCollection ClientDevices { get; set; } = new ObservableCollection(); diff --git a/HBLConsole/ViewModel/ParSetViewModel.cs b/HBLConsole/ViewModel/ParSetViewModel.cs new file mode 100644 index 0000000..4c1994a --- /dev/null +++ b/HBLConsole/ViewModel/ParSetViewModel.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Message.Enum; +using HBLConsole.Model; +using HBLConsole.Service; +using Microsoft.Toolkit.Mvvm.Input; + +namespace HBLConsole.ViewModel +{ + public class ParSetViewModel : ViewModelBase + { + public ParSetViewModel() + { + WindowName = "参数设置"; + // + if (SaveInfoCommand == null) + { + SaveInfoCommand = new RelayCommand(SaveInfoHandler); + } + LoadInfoHandler(); + } + + private const string ParSetJsonFilePath = "DistributePlc.json"; + + private const string RootJsonPath = "AccessFile\\"; + + //开机启动 + public bool IsSelected + { + get { return SystemHelper.GetInstance.IsAutoStart(); } + set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } + } + //下拉框绑定设备类型 + public ObservableCollection ClientDevices { get; set; } + = new ObservableCollection(); + //选中类型名称 + public string ClientDeviceType + { + get { return _mClientDeviceType; } + set + { + _mClientDeviceType = value; + OnPropertyChanged(); + } + } + private string _mClientDeviceType = string.Empty; + + + /******煮面口********/ + private bool _hideNoodleNo1 = false; + public bool HideNoodleNo1 + { + get { return _hideNoodleNo1; } + set { _hideNoodleNo1 = value; OnPropertyChanged(); } + } + private bool _hideNoodleNo2 = false; + public bool HideNoodleNo2 + { + get { return _hideNoodleNo2; } + set { _hideNoodleNo2 = value; OnPropertyChanged(); } + } + private bool _hideNoodleNo3 = false; + public bool HideNoodleNo3 + { + get { return _hideNoodleNo3; } + set { _hideNoodleNo3 = value; OnPropertyChanged(); } + } + private bool _hideNoodleNo4 = false; + public bool HideNoodleNo4 + { + get { return _hideNoodleNo4; } + set { _hideNoodleNo4 = value; OnPropertyChanged(); } + } + private bool _hideNoodleNo5 = false; + public bool HideNoodleNo5 + { + get { return _hideNoodleNo5; } + set { _hideNoodleNo5 = value; OnPropertyChanged(); } + } + private bool _hideNoodleNo6 = false; + public bool HideNoodleNo6 + { + get { return _hideNoodleNo6; } + set { _hideNoodleNo6 = value; OnPropertyChanged(); } + } + + /******冷库转盘当前位置********/ + private int _currentTurnPosition = 1; + public int CurrentTurnPosition + { + get { return _currentTurnPosition; } + set { _currentTurnPosition = value; OnPropertyChanged(); } + } + + /******煮面口时间设定********/ + private int _noFirstMin = 0; + private int _noFirstSec = 0; + public int No1_Minute + { + get { return _noFirstMin; } + set { _noFirstMin = value; OnPropertyChanged(); } + } + public int No1_Second + { + get { return _noFirstSec; } + set { _noFirstSec = value; OnPropertyChanged(); } + } + private int _noSecondMin = 0; + private int _noSecondSec = 0; + public int No2_Minute + { + get { return _noSecondMin; } + set { _noSecondMin = value; OnPropertyChanged(); } + } + public int No2_Second + { + get { return _noSecondSec; } + set { _noSecondSec = value; OnPropertyChanged(); } + } + // + private int _noThirdMin = 0; + private int _noThirdSec = 0; + public int No3_Minute + { + get { return _noThirdMin; } + set { _noThirdMin = value; OnPropertyChanged(); } + } + public int No3_Second + { + get { return _noThirdSec; } + set { _noThirdSec = value; OnPropertyChanged(); } + } + + private int _noForthMin = 0; + private int _noForthSec = 0; + public int No4_Minute + { + get { return _noForthMin; } + set { _noForthMin = value; OnPropertyChanged(); } + } + public int No4_Second + { + get { return _noForthSec; } + set { _noForthSec = value; OnPropertyChanged(); } + } + + private int _noFifthMin = 0; + private int _noFifthSec = 0; + public int No5_Minute + { + get { return _noFifthMin; } + set { _noFifthMin = value; OnPropertyChanged(); } + } + public int No5_Second + { + get { return _noFifthSec; } + set { _noFifthSec = value; OnPropertyChanged(); } + } + + private int _noSixthMin = 0; + private int _noSixthSec = 0; + public int No6_Minute + { + get { return _noSixthMin; } + set { _noSixthMin = value; OnPropertyChanged(); } + } + public int No6_Second + { + get { return _noSixthSec; } + set { _noSixthSec = value; OnPropertyChanged(); } + } + + + //保存输入命令 + public RelayCommand SaveInfoCommand { get; set; } + //保存界面输入功能 + private void SaveInfoHandler() + { + DistributePlcPar distributePlcPar = GetDistributeParUserInput(); + Json.Data = distributePlcPar; + LocaPath.GetInstance.FilePath = RootJsonPath; + Json.Save(); + Trace.WriteLine($"{nameof(DistributePlcPar)},json文件已成功保存。"); + } + //载入界面数据 + private void LoadInfoHandler() + { + LocaPath.GetInstance.FilePath = RootJsonPath; + Json.Read(); + DistributePlcPar data = Json.Data; + DistributePlcPar distributePlcPar = data; + if (distributePlcPar != null) + { + this.HideNoodleNo1 = distributePlcPar.HideNoodleNo1; + this.HideNoodleNo2 = distributePlcPar.HideNoodleNo2; + this.HideNoodleNo3 = distributePlcPar.HideNoodleNo3; + this.HideNoodleNo4 = distributePlcPar.HideNoodleNo4; + this.HideNoodleNo5 = distributePlcPar.HideNoodleNo5; + this.HideNoodleNo6 = distributePlcPar.HideNoodleNo6; + + this.CurrentTurnPosition = distributePlcPar.CurrentTurnPosition; + + this.No1_Minute = distributePlcPar.No1_Minute; + this.No1_Second = distributePlcPar.No1_Second; + this.No2_Minute = distributePlcPar.No2_Minute; + this.No2_Second = distributePlcPar.No2_Second; + this.No3_Minute = distributePlcPar.No3_Minute; + this.No3_Second = distributePlcPar.No3_Second; + this.No4_Minute = distributePlcPar.No4_Minute; + this.No4_Second = distributePlcPar.No4_Second; + this.No5_Minute = distributePlcPar.No5_Minute; + this.No5_Second = distributePlcPar.No5_Second; + this.No6_Minute = distributePlcPar.No6_Minute; + this.No6_Second = distributePlcPar.No6_Second; + } + + Trace.WriteLine($"已成功载入{nameof(DistributePlcPar)}json文件"); + return; + } + + //获取界面用户输入 + private DistributePlcPar GetDistributeParUserInput() + { + DistributePlcPar distributePlcPar = new DistributePlcPar() + { + HideNoodleNo1 = this.HideNoodleNo1, + HideNoodleNo2 = this.HideNoodleNo2, + HideNoodleNo3 = this.HideNoodleNo3, + HideNoodleNo4 = this.HideNoodleNo4, + HideNoodleNo5 = this.HideNoodleNo5, + HideNoodleNo6 = this.HideNoodleNo6, + // + CurrentTurnPosition = this.CurrentTurnPosition, + // + No1_Minute = this.No1_Minute, + No1_Second = this.No1_Second, + No2_Minute = this.No2_Minute, + No2_Second = this.No2_Second, + No3_Minute = this.No3_Minute, + No3_Second = this.No3_Second, + No4_Minute = this.No4_Minute, + No4_Second = this.No4_Second, + No5_Minute = this.No5_Minute, + No5_Second = this.No5_Second, + No6_Minute = this.No6_Minute, + No6_Second = this.No6_Second, + }; + return distributePlcPar; + } + + } +} diff --git a/HBLConsole/ViewModel/ViewModelBase.cs b/HBLConsole/ViewModel/ViewModelBase.cs index 9587783..4045181 100644 --- a/HBLConsole/ViewModel/ViewModelBase.cs +++ b/HBLConsole/ViewModel/ViewModelBase.cs @@ -16,6 +16,8 @@ using BPA.Message.Enum; using System.Collections.Concurrent; using HBLConsole.Factory; using System.Threading; +using HBLConsole.Business; +using HBLConsole.GVL; namespace HBLConsole.ViewModel { @@ -27,6 +29,15 @@ namespace HBLConsole.ViewModel MessageLog.GetInstance.InfoNotify = new Action((s) => { LogMessage = MessageLog.GetInstance.LogInfo; + + IotReport.GetInstance.SendLogMessage(new BPA.Message.API请求.LogTable + { + ClientId = InternetInfo.ClientId.ToString(), + LogTime = DateTime.Now, + LogType = "1", + LogMessage = s, + LogVla = "正常", + }); }); } @@ -107,7 +118,7 @@ namespace HBLConsole.ViewModel private void Test() { #if test - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { while (morkOrderPushes.Count > 0) { @@ -188,7 +199,13 @@ namespace HBLConsole.ViewModel break; case ORDER_STATUS.COMPLETED_TAKE: var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SuborderId); - if (re != null) WaitTakeMeal.Remove(re); + if (re != null) + { + WaitTakeMeal.Remove(re); + //Json.Data.morkOrderPushes.Remove(re); + Json.Data.orderLists.Remove(re); + } + break; default: break;