You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.4 KiB
C#
132 lines
4.4 KiB
C#
using Rs.Framework;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Entitys;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.MotionPlat.Vision
|
|
{
|
|
/// <summary>
|
|
/// 侧相机
|
|
/// </summary>
|
|
public class SideCameraVision:BaseVision
|
|
{
|
|
string data = string.Empty;
|
|
static int visionNum = 4;
|
|
static ManualResetEvent visionGrabEvent = new ManualResetEvent(false);
|
|
static List<VisionResult> visionResultList = new List<VisionResult>();
|
|
bool reciveData = false;
|
|
public override void VNozzleCalib_DataRecived(Socket arg1, byte[] arg2)
|
|
{
|
|
Regex reg = new Regex("M\\dC,0");
|
|
|
|
|
|
//if (reciveData)
|
|
{
|
|
//所有的视觉数据以;作为结束符
|
|
foreach (byte b in arg2)
|
|
{
|
|
if (b != 59)
|
|
{
|
|
reciveBuffer.Add(b);
|
|
}
|
|
else
|
|
{
|
|
data = Encoding.ASCII.GetString(reciveBuffer.ToArray());
|
|
MessageQueue.Instance.Insert(data);
|
|
if (data == "M,0")
|
|
{
|
|
//MessageQueue.Instance.Insert("视觉收到拍照指令");
|
|
}
|
|
else if (reg.IsMatch(data))
|
|
{
|
|
visionGrabEvent.Set();
|
|
}
|
|
else
|
|
{
|
|
//在这里处理视觉发过来的数据
|
|
//m2,0,22;
|
|
string[] resultData = data.Split(',');
|
|
//int.TryParse(resultData
|
|
int.TryParse(resultData[0].Replace("M", ""), out int fixtureIndex);
|
|
|
|
Regex reg2 = new Regex("M\\d,");
|
|
data = $"{reg2.Replace(data, "GR#")}$";
|
|
MessageQueue.Instance.Insert(data);
|
|
TestFixtureManager.Instance.GetTestFixture(fixtureIndex).Send(data);
|
|
visionGrabEvent.Set();
|
|
}
|
|
reciveBuffer.Clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public bool ClearQueue(int fixtureIndex,int timeout = 10000)
|
|
{
|
|
visionGrabEvent.Reset();
|
|
string content = $"M{fixtureIndex}C;";
|
|
int len = vNozzleCalib.Send(content);
|
|
//reciveData = true;
|
|
if (len > 0)
|
|
{
|
|
MessageQueue.Instance.Insert($" <<< {content}");
|
|
if (visionGrabEvent.WaitOne(timeout))
|
|
{
|
|
//reciveData = false;
|
|
MessageQueue.Instance.Insert($" >>> {data}");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 一拍十六
|
|
/// </summary>
|
|
/// <param name="timeout"></param>
|
|
/// <returns></returns>
|
|
public void Grab(int fixtureIndex,string sn,int timeout = 10000)
|
|
{
|
|
data = "";
|
|
visionResultList.Clear();
|
|
result = null;
|
|
visionGrabEvent.Reset();
|
|
string cmd = $"M{fixtureIndex},{sn};";
|
|
MessageQueue.Instance.Insert($" <<< {cmd}");
|
|
int len = vNozzleCalib.Send(cmd);
|
|
//reciveData = true;
|
|
//if (len > 0)
|
|
//{
|
|
// MessageQueue.Instance.Insert($" <<< {cmd}");
|
|
// if (visionGrabEvent.WaitOne(timeout))
|
|
// {
|
|
// reciveData = false;
|
|
// string[] darr = data.Split(new char[] { ',' });
|
|
// MessageQueue.Instance.Insert($"收到视觉结果:{data}");
|
|
// data = $"{data.Replace("M2,", "GR#")}$";
|
|
// MessageQueue.Instance.Insert(data);
|
|
// TestFixtureManager.Instance.GetTestFixture(fixtureIndex).Send(data);
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|