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.

100 lines
3.2 KiB
C#

using Rs.Framework;
using Rs.MotionPlat.Commom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Vision
{
public class OneGrabOneVision : BaseVision
{
string data=string.Empty;
public override void VNozzleCalib_DataRecived(System.Net.Sockets.Socket arg1, byte[] arg2)
{
//所有的视觉数据以;作为结束符
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
{
//result = new VisionResult();
////解析拍照结果
//string[] results = data.Split(',');
//if (results[1] == "-1")
//{
// result.Result = false;
// if (results.Length>=5)
// {
// result.Result = true;
// result.SN = VirtualBarCode.Code;
// result.OffsetX = double.Parse(results[3]);
// result.OffsetY = double.Parse(results[4]);
// }
//}
//else
//{
// result.Result = false;
// if (results.Length >= 5)
// {
// result.Result = true;
// result.SN = results[2];
// result.OffsetX = double.Parse(results[3]);
// result.OffsetY = double.Parse(results[4]);
// }
//}
NozzleCalibReciveEvent.Set();
}
reciveBuffer.Clear();
}
}
}
/// <summary>
/// 一拍一
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public string OneGrabOne(int timeout = 10000)
{
data = "";
result = null;
NozzleCalibReciveEvent.Reset();
int len = vNozzleCalib.Send("M;");
if (len > 0)
{
if (NozzleCalibReciveEvent.WaitOne(timeout))
{
MessageQueue.Instance.Insert($"收到视觉结果:{data}");
return data;
}
else
{
return null;
}
}
else
{
return null;
}
}
}
}