diff --git a/Rs.DeweyTester/Flow/SubFlow/ProductLocationFlow.cs b/Rs.DeweyTester/Flow/SubFlow/ProductLocationFlow.cs index 9a26fd3..f5115f7 100644 --- a/Rs.DeweyTester/Flow/SubFlow/ProductLocationFlow.cs +++ b/Rs.DeweyTester/Flow/SubFlow/ProductLocationFlow.cs @@ -7,6 +7,7 @@ using Rs.MotionPlat.Flow.SafePosFlow; using Rs.MotionPlat.Vision; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -52,6 +53,7 @@ namespace Rs.MotionPlat.Flow.SubFlow finished = false; else return; + Stopwatch stopwatch = Stopwatch.StartNew(); flowStep = EProductLocationFlowStep.到料仓拍照起始位; string logInfo = string.Empty; TargetPosition targetPosition = new TargetPosition(); @@ -148,6 +150,7 @@ namespace Rs.MotionPlat.Flow.SubFlow if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2)) { AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓拍照结束位,", GetClassName()); + stopwatch.Restart(); flowStep = EProductLocationFlowStep.拍照结果处理; } else @@ -166,38 +169,56 @@ namespace Rs.MotionPlat.Flow.SubFlow } else { - string vmsg = VisionHelper.loadTakeProductVision.OneGrabSixteen(10000); - string[] msgs = vmsg.Split(new string[] { "#," }, StringSplitOptions.RemoveEmptyEntries); - - //if (!string.IsNullOrEmpty(vmsg)&& vmsg.TrimEnd(new char[] { '#', ',' }).Split('#').Length==16) - if (!string.IsNullOrEmpty(vmsg) && msgs.Length == 16) + if (stopwatch.ElapsedMilliseconds<10000) { - List snList = new List(); - foreach (string msg in msgs) + if (VisionHelper.loadTakeProductVision.Num == 16) { - string[] items = msg.Split(new char[] { ',' }); - if (items[1] == "0") + string vmsg = VisionHelper.loadTakeProductVision.OneGrabSixteen(10000); + if(vmsg != null) { - snList.Add(items[2]); - } - } - if (snList.GroupBy(a => a).Where(k => k.Count() >= 2).Count() == 0) - { - reTakePicNum = 0; - OneGrabSixteenManager.Instance.ParseResult(vmsg, slotIndex); - finished = true; - } - else - { - MessageQueue.Instance.Warn("Duplicate barcode"); - reTakePicNum++; - if (reTakePicNum > 4) - { - Msgbox.ShowTipDialog(EButtonType.Retry, "Duplicate barcode alarm", "alarm", true); - reTakePicNum = 0; + string[] msgs = vmsg.Split(new string[] { "#," }, StringSplitOptions.RemoveEmptyEntries); + + //if (!string.IsNullOrEmpty(vmsg)&& vmsg.TrimEnd(new char[] { '#', ',' }).Split('#').Length==16) + if (!string.IsNullOrEmpty(vmsg) && msgs.Length == 16) + { + List snList = new List(); + foreach (string msg in msgs) + { + string[] items = msg.Split(new char[] { ',' }); + if (items[1] == "0") + { + snList.Add(items[2]); + } + } + if (snList.GroupBy(a => a).Where(k => k.Count() >= 2).Count() == 0) + { + reTakePicNum = 0; + OneGrabSixteenManager.Instance.ParseResult(vmsg, slotIndex); + finished = true; + } + else + { + MessageQueue.Instance.Warn("Duplicate barcode"); + reTakePicNum++; + if (reTakePicNum > 4) + { + Msgbox.ShowTipDialog(EButtonType.Retry, "Duplicate barcode alarm", "alarm", true); + reTakePicNum = 0; + } + flowStep = EProductLocationFlowStep.到料仓拍照起始位; + } + } + else + { + alarmEntity = AlarmCollection.Get(AlarmConstID.一拍十六拍照失败报警); + Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true); + //Msgbox.ShowTipDialog(EButtonType.Retry, "一拍十六拍照失败,请处理后点击重试","grab fail",true); + flowStep = EProductLocationFlowStep.到料仓拍照起始位; + } } - flowStep = EProductLocationFlowStep.到料仓拍照起始位; + } + } else { @@ -206,6 +227,7 @@ namespace Rs.MotionPlat.Flow.SubFlow //Msgbox.ShowTipDialog(EButtonType.Retry, "一拍十六拍照失败,请处理后点击重试","grab fail",true); flowStep = EProductLocationFlowStep.到料仓拍照起始位; } + } break; } diff --git a/Rs.DeweyTester/Vision/LoadTakeProductVision.cs b/Rs.DeweyTester/Vision/LoadTakeProductVision.cs index b2cc686..37eeb1f 100644 --- a/Rs.DeweyTester/Vision/LoadTakeProductVision.cs +++ b/Rs.DeweyTester/Vision/LoadTakeProductVision.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Sockets; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -17,6 +18,7 @@ namespace Rs.MotionPlat.Vision /// public class LoadTakeProductVision:BaseVision { + public int Num { get; set; } = 0; string data = string.Empty; static int visionNum = 4; static ManualResetEvent visionGrabEvent = new ManualResetEvent(false); @@ -29,12 +31,13 @@ namespace Rs.MotionPlat.Vision //所有的视觉数据以;作为结束符 foreach (byte b in arg2) { - if (b != 59) + if (b != ';') { reciveBuffer.Add(b); } else { + data = Encoding.ASCII.GetString(reciveBuffer.ToArray()); //MessageQueue.Instance.Insert(data); if (data == "M,0") @@ -45,6 +48,14 @@ namespace Rs.MotionPlat.Vision { visionGrabEvent.Set(); } + else if(Regex.IsMatch(data,"M,\\d{0,2}F")) + { + Num++; + if(Num==16) + { + reciveData = false; + } + } else { visionGrabEvent.Set(); @@ -105,6 +116,7 @@ namespace Rs.MotionPlat.Vision public bool ClearQueue(int timeout = 10000) { + Num = 0; visionGrabEvent.Reset(); int len = vNozzleCalib.Send("C;"); reciveData = true; @@ -112,7 +124,7 @@ namespace Rs.MotionPlat.Vision { if (visionGrabEvent.WaitOne(timeout)) { - reciveData = false; + //reciveData = false; MessageQueue.Instance.Insert($"收到视觉结果:{data}"); return true; }