diff --git a/HBLConsole.Business/AbstractServer/Base.cs b/HBLConsole.Business/AbstractServer/Base.cs index 1f473c0..aa78b38 100644 --- a/HBLConsole.Business/AbstractServer/Base.cs +++ b/HBLConsole.Business/AbstractServer/Base.cs @@ -134,6 +134,7 @@ namespace HBLConsole.Business.AbstractServer /// public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status) { + return false; string result = string.Empty; OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId }; try diff --git a/HBLConsole.Communication/MCUSerialHelper.cs b/HBLConsole.Communication/MCUSerialHelper.cs index a5b1788..4bcc6ac 100644 --- a/HBLConsole.Communication/MCUSerialHelper.cs +++ b/HBLConsole.Communication/MCUSerialHelper.cs @@ -19,11 +19,6 @@ namespace HBLConsole.Communication private MCUSerialHelper() { } private SerialPort comPort = new SerialPort(); - ConcurrentQueue SerialMessages = new ConcurrentQueue(); - //帧尾 - private byte end = 0xDD; - //帧头 - private byte start = 0xCC; public bool IsOpen => comPort.IsOpen; public bool Open(string portName, int baudRate) @@ -41,8 +36,9 @@ namespace HBLConsole.Communication comPort.StopBits = StopBits.One; comPort.ReadTimeout = 1000; comPort.WriteTimeout = 1000; - comPort.DataReceived += ComPort_DataReceived; - comPort.RtsEnable = true; + //comPort.RtsEnable = true; //设置为 true后会读取不到数据 + //comPort.DtrEnable = true;//获取或设置一个值,该值在串行通信过程中启用数据终端就绪 (DTR) 信号。 + //comPort.RtsEnable = true;//获取或设置一个值,该值指示在串行通信中是否启用请求发送 (RTS) 信号 try { comPort.Open(); @@ -57,28 +53,6 @@ namespace HBLConsole.Communication return comPort.IsOpen; } - private void ComPort_DataReceived(object sender, SerialDataReceivedEventArgs e) - { - int len = comPort.BytesToRead; - if (len <= 0) return; - byte[] receive = new byte[len]; - comPort.Read(receive, 0, receive.Length); - if (receive[len - 1] != end) return; - List ReceiveList = new List(); - for (int i = 0; i < receive.Length; i++) - { - ReceiveList.Add(receive[i]); - if (ReceiveList.Count > 0) - { - if (ReceiveList.ElementAt(0) == start && ReceiveList.ElementAt(ReceiveList.Count - 1) == end) - { - SerialMessages.Enqueue(ReceiveList.ToArray()); - ReceiveList.Clear(); - } - } - } - comPort.DiscardInBuffer(); - } /// /// 单片机输出端口控制 @@ -87,13 +61,9 @@ namespace HBLConsole.Communication /// 控制值 public void OutputControl(byte index, bool value) { - byte NumValue = (byte)(value ? 1 : 0); + byte NumValue = (byte)(value ? 0x01 : 0x00); byte[] buffers = new byte[6] { 0xCC, 0x01, 0x01, index, NumValue, 0xDD }; - if (comPort.IsOpen) - { - comPort.Write(buffers, 0, buffers.Length); - } - + if (IsOpen) comPort.Write(buffers, 0, buffers.Length); } /// @@ -104,10 +74,7 @@ namespace HBLConsole.Communication public void ServoControl(byte index, byte value) { byte[] buffers = new byte[6] { 0xCC, 0x01, 0x02, index, value, 0xDD }; - if (comPort.IsOpen) - { - comPort.Write(buffers, 0, buffers.Length); - } + if (IsOpen) comPort.Write(buffers, 0, buffers.Length); } /// @@ -119,21 +86,28 @@ namespace HBLConsole.Communication { if (index <= 0 || index > 8) return false; byte[] buffers = new byte[6] { 0xCC, 0x01, 0x03, index, 0x00, 0xDD }; - if (comPort.IsOpen) + if (IsOpen) { comPort.Write(buffers, 0, buffers.Length); - while (SerialMessages.Count <= 0) + DateTime dt = DateTime.Now; + List receive = new List(); + while (true) { + byte[] re = new byte[comPort.BytesToRead]; + comPort.Read(re, 0, re.Length); + if (re.Contains(0xcc) && re.Contains(0xDD)) receive.AddRange(re); + comPort.DiscardInBuffer(); + if (receive.Contains(0xcc) && receive.Contains(0xdd)) break; + if (DateTime.Now.Subtract(dt).TotalSeconds >= 2) break; Thread.Sleep(1); } - if (SerialMessages.TryDequeue(out byte[] receive)) + if (receive != null) { - if (receive.Length == 6) + int Reindex = Array.FindIndex(receive.ToArray(), p => p == 0xcc); + if (Reindex < receive.Count && Reindex >= 0) { - if (receive[2] == 0x03) - { - return receive[4] == 0x01; - } + var res = receive.GetRange(Array.FindIndex(receive.ToArray(), p => p == 0xcc), 6); + return res != null && res.Count() == 6 && res.ElementAt(4) == 0x01; } } } diff --git a/HBLConsole.Communication/Serial/SerialPortClient.cs b/HBLConsole.Communication/Serial/SerialPortClient.cs index c750aab..c54a847 100644 --- a/HBLConsole.Communication/Serial/SerialPortClient.cs +++ b/HBLConsole.Communication/Serial/SerialPortClient.cs @@ -202,7 +202,7 @@ namespace HBLConsole.Communication } } - + /// /// 读取数据 /// @@ -215,7 +215,7 @@ namespace HBLConsole.Communication if (!(comPort.IsOpen)) comPort.Open(); byte[] buffer = new byte[1024]; comPort.Read(buffer, 0, buffer.Length); - return buffer; + return buffer; } } public void Start() diff --git a/HBLConsole.MORKM/Control_MORKM.cs b/HBLConsole.MORKM/Control_MORKM.cs index 0e7fb1f..6fce87b 100644 --- a/HBLConsole.MORKM/Control_MORKM.cs +++ b/HBLConsole.MORKM/Control_MORKM.cs @@ -474,7 +474,9 @@ namespace HBLConsole.MORKM { if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo)) { - mORKS.CookNodelId[loc] = orderLocInfo.SuborderId; + mORKS.CookNodelId.ElementAt(loc).CookNodelId = orderLocInfo.SuborderId; + mORKS.CookNodelId.ElementAt(loc).Loc = mORKS.TurntableFeedbackloc; + SetFallNoodleLoc((ushort)(loc + 1)); //机器人开始取面 RobotTakeNoodle(); @@ -500,28 +502,86 @@ namespace HBLConsole.MORKM { if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect) { - int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0); - if (loc >= 0 && loc <= 5) + var CookNodelIdList = mORKS.CookNodelId.Where(p => p.CookNodelId == mORKS.IngredientsCompleteId && p.CookNodelId.Length > 0).ToList(); + if (CookNodelIdList != null) { - if (mORKS.CookNoodlesComplete[loc]) + var res = mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == mORKS.IngredientsCompleteId); + if (res == null)//排队订单中不存在该订单 { - SetTakeNoodleLoc((ushort)(loc + 1)); - RobotOutMeal(); - CookNoodleStatusReset((ushort)(loc + 1)); - ResetAllowFallNoodle(); - mORKS.OutMealId = mORKS.IngredientsCompleteId; - mORKS.IngredientsCompleteId = string.Empty; - mORKS.CookNodelId[loc] = string.Empty; - - if (mORKS.CookNodelId.GetIndex(mORKS.OutMealId) < 0) + var isHaveEven = CookNodelIdList.FirstOrDefault(p => p.Loc > 0 && p.Loc % 2 == 0);//偶数,判断是否有素菜 + var isHaveOddNumber = CookNodelIdList.FirstOrDefault(p => p.Loc % 2 != 0);//奇数,判断是否有荤菜 + if (isHaveEven != null) + { + //素菜 + OutMealControl(Array.FindIndex(mORKS.CookNodelId.ToArray(), p => p.CookNodelId == isHaveEven.CookNodelId && p.CookNodelId.Length > 0)); + } + else { - CookComplete(); //告诉机器人冒菜已经煮完 - //IsAddSoup();//判断是否加汤 + if (isHaveOddNumber != null) + //荤菜 + OutMealControl(Array.FindIndex(mORKS.CookNodelId.ToArray(), p => p.CookNodelId == isHaveOddNumber.CookNodelId && p.CookNodelId.Length > 0)); } - MessageLog.GetInstance.Show($"{loc + 1}号位置出餐控制"); - mORKS.OutNoodleing = true; } + else//排队订单中有该订单 + { + + } + } + + //int loc = Array.FindIndex(mORKS.CookNodelId.ToArray(), p => p.CookNodelId == mORKS.IngredientsCompleteId && p.CookNodelId.Length > 0); + + //if (loc >= 0 && loc <= 5) + //{ + // if (mORKS.CookNoodlesComplete[loc]) + // { + // SetTakeNoodleLoc((ushort)(loc + 1)); + // RobotOutMeal(); + // CookNoodleStatusReset((ushort)(loc + 1)); + // mORKS.OutMealId = mORKS.IngredientsCompleteId; + // mORKS.IngredientsCompleteId = string.Empty; + // mORKS.CookNodelId.ElementAt(loc).CookNodelId = string.Empty; + // mORKS.CookNodelId.ElementAt(loc).Loc = -1; + + // if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == mORKS.OutMealId) == null && mORKS.CookNodelId.FirstOrDefault(p => p.CookNodelId == mORKS.OutMealId) == null) + // { + // CookComplete(); //告诉机器人冒菜已经煮完 + // //IsAddSoup();//判断是否加汤 + // ResetAllowFallNoodle(); + // MessageLog.GetInstance.Show($"{mORKS.OutMealId} 出餐完成"); + // } + + // MessageLog.GetInstance.Show($"{loc + 1}号位置出餐控制"); + // mORKS.OutNoodleing = true; + // } + //} + } + } + + private void OutMealControl(int loc) + { + if (loc >= 0 && loc <= 5) + { + if (mORKS.CookNoodlesComplete[loc]) + { + SetTakeNoodleLoc((ushort)(loc + 1)); + RobotOutMeal(); + CookNoodleStatusReset((ushort)(loc + 1)); + mORKS.CookNodelId.ElementAt(loc).CookNodelId = string.Empty; + mORKS.CookNodelId.ElementAt(loc).Loc = -1; + + if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == mORKS.IngredientsCompleteId) == null && mORKS.CookNodelId.FirstOrDefault(p => p.CookNodelId == mORKS.IngredientsCompleteId) == null) + { + CookComplete(); //告诉机器人冒菜已经煮完 + //IsAddSoup();//判断是否加汤 + ResetAllowFallNoodle(); + mORKS.OutMealId = mORKS.IngredientsCompleteId; + mORKS.IngredientsCompleteId = string.Empty; + MessageLog.GetInstance.Show($"{mORKS.OutMealId} 出餐完成"); + } + + MessageLog.GetInstance.Show($"{loc + 1}号位置出餐控制"); + mORKS.OutNoodleing = true; } } } diff --git a/HBLConsole.MORKM/GVL_MORKM.cs b/HBLConsole.MORKM/GVL_MORKM.cs index 4ac359f..cd0626e 100644 --- a/HBLConsole.MORKM/GVL_MORKM.cs +++ b/HBLConsole.MORKM/GVL_MORKM.cs @@ -16,6 +16,14 @@ namespace HBLConsole.MORKM /// public class GVL_MORKM : IGvl { + public GVL_MORKM() + { + for (int i = 0; i < 6; i++) + { + CookNodelId.Add(new CookNodleLocAndId() { CookNodelId = "", Loc = -1 }); + } + } + /// /// 机器人取面 /// PLC -> M0.3 @@ -330,7 +338,9 @@ namespace HBLConsole.MORKM /// /// 煮面口对应的订单ID /// - public string[] CookNodelId = new string[6] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, }; + //public string[] CookNodelId = new string[6] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, }; + public List CookNodelId { get; set; } = new List(); + /// /// 出餐订单ID @@ -350,4 +360,11 @@ namespace HBLConsole.MORKM #endregion } + + public class CookNodleLocAndId + { + public string CookNodelId { get; set; } + + public int Loc { get; set; } + } } diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 7ba26e4..65e87dd 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -12,6 +12,7 @@ using HBLConsole.Business; using HBLConsole.Factory; using BPA.Message.Enum; using System.Collections.ObjectModel; +using System.Threading; namespace HBLConsole.MainConsole { @@ -67,6 +68,13 @@ namespace HBLConsole.MainConsole public void BusinessInit() { + //MCUSerialHelper.GetInstance.Open("COM7", 9600); + //MCUSerialHelper.GetInstance.OutputControl(1, true); + //while (true) + //{ + // Thread.Sleep(1000); + //} + //var res = MCUSerialHelper.GetInstance.GetInputStatus(1); ThreadManage.GetInstance.Start(new Action(() => { InternetInfo.ConfigInit();//从 consul 获取配置数据