添加项目文件。

This commit is contained in:
2025-11-21 11:31:14 +08:00
parent 92e620b8fd
commit 091ce9b21f
21 changed files with 3351 additions and 0 deletions

28
WaferAlignment.sln Normal file
View File

@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.11205.157 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaferAlignment", "WaferAlignment\WaferAlignment.csproj", "{941B8ABC-436F-457D-95DA-A79E23C8CA5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Debug|x64.ActiveCfg = Debug|x64
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Debug|x64.Build.0 = Debug|x64
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Release|Any CPU.Build.0 = Release|Any CPU
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Release|x64.ActiveCfg = Release|x64
{941B8ABC-436F-457D-95DA-A79E23C8CA5D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>

39
WaferAlignment/CalibForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,39 @@
namespace WaferAlignment
{
partial class CalibForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "CalibForm";
}
#endregion
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WaferAlignment
{
public partial class CalibForm : Form
{
public CalibForm()
{
InitializeComponent();
}
}
}

539
WaferAlignment/Camera.cs Normal file
View File

@@ -0,0 +1,539 @@
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using MvCamCtrl.NET;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace WaferAlignment
{
public class Camera
{
private bool _isConnected = false;
public bool IsConnected
{
get { return _isConnected; }
set { _isConnected = value; }
}
private bool _isStarted = false;
public bool IsStarted
{
get { return _isStarted; }
set { _isStarted = value; }
}
public event Action<Bitmap> OutputImageEvent;
private float expo = 8;
private uint imgHeight = 4000;
private MyCamera _dev;
private CancellationTokenSource _startAcqToken;
private CancellationTokenSource _stopAcqToken;
private Task _imageAcquisitionTask;
private static Object BufForDriverLock = new Object();
private IntPtr m_BufForDriver = IntPtr.Zero;
private UInt32 m_nBufSizeForDriver = 0;
private MyCamera.MV_FRAME_OUT_INFO_EX m_stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
public void Connect()
{
IntPtr devIPtr;
try
{
MyCamera.MV_CC_DEVICE_INFO_LIST m_stDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref m_stDeviceList);
if (m_stDeviceList.nDeviceNum > 0)
{
devIPtr = m_stDeviceList.pDeviceInfo[0];
}
else
{
throw new Exception("未找到相机连接!");
}
}
catch (Exception ex)
{
throw new Exception("相机查找失败!");
}
MyCamera.MV_CC_DEVICE_INFO devInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(devIPtr, typeof(MyCamera.MV_CC_DEVICE_INFO));
if (_dev != null)
{
throw new Exception("相机连接失败,原因:该设备实例已存在");
}
_dev = new MyCamera();
if (_dev == null)
{
throw new Exception("相机连接失败,原因:该设备实例化失败");
}
int status = _dev.MV_CC_CreateDevice_NET(ref devInfo);
if (status != MyCamera.MV_OK)
{
throw new Exception(String.Format("相机连接失败,原因:设备创建失败"));
}
status = _dev.MV_CC_OpenDevice_NET();
if (status != MyCamera.MV_OK)
{
throw new Exception(String.Format("相机连接失败,原因:设备启动失败"));
}
int nPacketSize = _dev.MV_CC_GetOptimalPacketSize_NET();
if (nPacketSize > 0)
{
status = _dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
if (status != MyCamera.MV_OK)
{
throw new Exception(String.Format("相机连接失败,原因:获取本地包大小失败"));
}
}
else
{
throw new Exception(String.Format("相机连接失败,原因:获取本地包大小失败"));
}
// 连续采集
int nRet;
nRet = _dev.MV_CC_SetEnumValue_NET("AcquisitionMode", (uint)MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS);
// 手动曝光
nRet = _dev.MV_CC_SetEnumValue_NET("ExposureAuto", (uint)MyCamera.MV_CAM_EXPOSURE_AUTO_MODE.MV_EXPOSURE_AUTO_MODE_OFF);
// 行触发关闭
//nRet = _dev.MV_CC_SetEnumValue_NET("TriggerSelector", 9);
//nRet = _dev.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF);
// 帧触发打开,软件触发
nRet = _dev.MV_CC_SetEnumValue_NET("TriggerSelector", 6);
nRet = _dev.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON);
nRet = _dev.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_COUNTER0);
nRet = _dev.MV_CC_SetFloatValue_NET("ExposureTime", expo);
//nRet = _dev.MV_CC_SetIntValue_NET("Width", 1600);
//nRet = _dev.MV_CC_SetIntValue_NET("Height", 1200);
//nRet = _dev.MV_CC_SetIntValue_NET("OffsetX", 1760);
//nRet = _dev.MV_CC_SetIntValue_NET("OffsetY", 1448);
_isConnected = true;
}
public void Disconnect()
{
if (_dev != null)
{
// 关闭设备
_dev.MV_CC_CloseDevice_NET();
_dev.MV_CC_DestroyDevice_NET();
_dev = null;
_isConnected = false;
}
}
public void Start()
{
if (_dev == null)
{
_isStarted = false;
MessageBox.Show("相机启动失败,相机未连接");
return;
}
ImageAcquisitionStart();
m_stFrameInfo.nFrameLen = 0;//取流之前先清除帧长度
m_stFrameInfo.enPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Undefined;
_dev.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_COUNTER0);
int nRet = _dev.MV_CC_StartGrabbing_NET();
if (MyCamera.MV_OK != nRet)
{
ImageAcquisitionStop();
_isStarted = false;
MessageBox.Show("相机启动失败,清除缓存区失败");
return;
}
_isStarted = true;
}
public void SoftwareGrab()
{
_dev.MV_CC_StopGrabbing_NET();
_dev.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE);
_dev.MV_CC_StartGrabbing_NET();
_dev.MV_CC_TriggerSoftwareExecute_NET();
Thread.Sleep(100);
}
public void Stop()
{
if (_dev == null)
{
_isStarted = false;
MessageBox.Show("相机停止失败,相机未连接");
return;
}
ImageAcquisitionStop();
int nRet = _dev.MV_CC_StopGrabbing_NET();
if (nRet != MyCamera.MV_OK)
{
_isStarted = false;
MessageBox.Show("相机停止失败");
return;
}
_isStarted = false;
}
private void ImageAcquisitionStart()
{
_startAcqToken = new CancellationTokenSource();
_imageAcquisitionTask = new Task(() => ImageAcquisitionProcess(), _startAcqToken.Token);
_imageAcquisitionTask.Start();
}
private void ImageAcquisitionStop()
{
try
{
_startAcqToken.Cancel();
Thread.Sleep(20);
_imageAcquisitionTask.Wait(_stopAcqToken.Token);
_imageAcquisitionTask.Dispose();
}
catch (OperationCanceledException ex)
{
_imageAcquisitionTask.Dispose();
}
}
private void ImageAcquisitionProcess()
{
_stopAcqToken = new CancellationTokenSource();
MyCamera.MV_FRAME_OUT stFrameInfo = new MyCamera.MV_FRAME_OUT();
while (true)
{
if (_startAcqToken.IsCancellationRequested)
break;
int nRet = _dev.MV_CC_GetImageBuffer_NET(ref stFrameInfo, 1000);
Console.WriteLine("-----------------------Get Image Buffer:" + "Width[" + Convert.ToString(stFrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(stFrameInfo.stFrameInfo.nHeight)
+ "] ,Trigger[" + Convert.ToString(stFrameInfo.stFrameInfo.nTriggerIndex) + "], FrameNum[" + Convert.ToString(stFrameInfo.stFrameInfo.nFrameNum) + "]");
if (nRet == MyCamera.MV_OK)
{
lock (BufForDriverLock)
{
if (m_BufForDriver == IntPtr.Zero || stFrameInfo.stFrameInfo.nFrameLen > m_nBufSizeForDriver)
{
if (m_BufForDriver != IntPtr.Zero)
{
Marshal.Release(m_BufForDriver);
m_BufForDriver = IntPtr.Zero;
}
m_BufForDriver = Marshal.AllocHGlobal((Int32)stFrameInfo.stFrameInfo.nFrameLen);
if (m_BufForDriver == IntPtr.Zero)
{
return;
}
m_nBufSizeForDriver = stFrameInfo.stFrameInfo.nFrameLen;
}
m_stFrameInfo = stFrameInfo.stFrameInfo;
CopyMemory(m_BufForDriver, stFrameInfo.pBufAddr, stFrameInfo.stFrameInfo.nFrameLen);
}
if (RemoveCustomPixelFormats(stFrameInfo.stFrameInfo.enPixelType))
{
_dev.MV_CC_FreeImageBuffer_NET(ref stFrameInfo);
continue;
}
//从缓存区获取图片
IntPtr pTemp = IntPtr.Zero;
MyCamera.MvGvspPixelType enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Undefined;
if (m_stFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
{
pTemp = m_BufForDriver;
enDstPixelType = m_stFrameInfo.enPixelType;
}
else
{
//ErrorMsgEvent(DeviceName + " -> 图像格式错误");
}
_dev.MV_CC_FreeImageBuffer_NET(ref stFrameInfo);
//************************Mono8 转 Bitmap*******************************
Bitmap bmp = new Bitmap(m_stFrameInfo.nWidth, m_stFrameInfo.nHeight, m_stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, pTemp);
ColorPalette cp = bmp.Palette;
for (int i = 0; i < 256; i++)
{
cp.Entries[i] = Color.FromArgb(i, i, i);
}
bmp.Palette = cp;
OutputImageEvent(bmp);
}
else
{
Thread.Sleep(10);
}
}
_stopAcqToken.Cancel();
}
private bool RemoveCustomPixelFormats(MyCamera.MvGvspPixelType enPixelFormat)
{
Int32 nResult = ((int)enPixelFormat) & (unchecked((Int32)0x80000000));
if (0x80000000 == nResult)
{
return true;
}
else
{
return false;
}
}
//public Bitmap Trigger()
//{
// if (_dev == null)
// {
// throw new Exception(String.Format("相机触发失败,原因:该设备未连接"));
// }
// _dev.MV_CC_SetEnumValue_NET("TriggerSelector", 6);
// int nRet = _dev.MV_CC_SetCommandValue_NET("TriggerSoftware");
// if (MyCamera.MV_OK != nRet)
// {
// throw new Exception(String.Format("相机触发失败"));
// }
// MyCamera.MV_FRAME_OUT stFrameInfo = new MyCamera.MV_FRAME_OUT();
// nRet = _dev.MV_CC_GetImageBuffer_NET(ref stFrameInfo, 1000);
// if (nRet == MyCamera.MV_OK)
// {
// lock (BufForDriverLock)
// {
// if (m_BufForDriver == IntPtr.Zero || stFrameInfo.stFrameInfo.nFrameLen > m_nBufSizeForDriver)
// {
// if (m_BufForDriver != IntPtr.Zero)
// {
// Marshal.Release(m_BufForDriver);
// m_BufForDriver = IntPtr.Zero;
// }
// m_BufForDriver = Marshal.AllocHGlobal((Int32)stFrameInfo.stFrameInfo.nFrameLen);
// if (m_BufForDriver == IntPtr.Zero)
// {
// return null;
// }
// m_nBufSizeForDriver = stFrameInfo.stFrameInfo.nFrameLen;
// }
// m_stFrameInfo = stFrameInfo.stFrameInfo;
// CopyMemory(m_BufForDriver, stFrameInfo.pBufAddr, stFrameInfo.stFrameInfo.nFrameLen);
// }
// if (RemoveCustomPixelFormats(stFrameInfo.stFrameInfo.enPixelType))
// {
// _dev.MV_CC_FreeImageBuffer_NET(ref stFrameInfo);
// return null;
// }
// //从缓存区获取图片
// IntPtr pTemp = IntPtr.Zero;
// MyCamera.MvGvspPixelType enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Undefined;
// if (m_stFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
// {
// pTemp = m_BufForDriver;
// enDstPixelType = m_stFrameInfo.enPixelType;
// }
// _dev.MV_CC_FreeImageBuffer_NET(ref stFrameInfo);
// //************************Mono8 转 Bitmap*******************************
// Bitmap bmp = new Bitmap(m_stFrameInfo.nWidth, m_stFrameInfo.nHeight, m_stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, pTemp);
// ColorPalette cp = bmp.Palette;
// for (int i = 0; i < 256; i++)
// {
// cp.Entries[i] = Color.FromArgb(i, i, i);
// }
// bmp.Palette = cp;
// return bmp;
// }
// else
// {
// return null;
// }
//}
//private bool RemoveCustomPixelFormats(MyCamera.MvGvspPixelType enPixelFormat)
//{
// Int32 nResult = ((int)enPixelFormat) & (unchecked((Int32)0x80000000));
// if (0x80000000 == nResult)
// {
// return true;
// }
// else
// {
// return false;
// }
//}
}
public class SiemensS7
{
private SiemensS7Net _s7;
private string _ip;
public bool OK { get; private set; }
private System.Timers.Timer _reconnectTimer;
public SiemensS7(string ip)
{
OK = false;
_ip = ip;
_reconnectTimer = new System.Timers.Timer(5000); // 设置定时器为5秒
_reconnectTimer.Elapsed += ReconnectTimerElapsed;
_reconnectTimer.AutoReset = true;
}
//public void Connect()
//{
// _s7 = new SiemensS7Net(SiemensPLCS.S1200);
// _s7.IpAddress = _ip;
// _s7.Port = 102;
// OperateResult operateResult = _s7.ConnectServer();
// if (!operateResult.IsSuccess)
// {
// throw new Exception(string.Format("Siemens S7 S1200客户端连接失败"));
// }
//}
public void Connect()
{
_s7 = new SiemensS7Net(SiemensPLCS.S1200);
_s7.IpAddress = _ip;
_s7.Port = 102;
TryConnect();
}
private void TryConnect()
{
OperateResult operateResult = _s7.ConnectServer();
if (!operateResult.IsSuccess)
{
OK = false;
Console.WriteLine("Siemens S7 S1200客户端连接失败5秒后重试...");
_reconnectTimer.Start(); // 启动定时器
}
else
{
OK = true;
Console.WriteLine("Siemens S7 S1200客户端连接成功");
_reconnectTimer.Stop(); // 停止定时器
}
}
private void ReconnectTimerElapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("尝试重新连接...");
TryConnect();
}
public void Disconnect()
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
OperateResult operateResult = _s7.ConnectClose();
if (!operateResult.IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1200客户端断开失败"));
}
}
public bool GetValue(string address, out bool value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
OperateResult<bool> boolResult = _s7.ReadBool(address);
if (boolResult.IsSuccess)
{
value = boolResult.Content;
return true;
}
else
{
value = false;
return false;
}
}
public void SetValue(string address, bool value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
public void SetValue(string address, int value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
public void SetValue(string address, uint value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
public void SetValue(string address, short value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
public void SetValue(string address, ushort value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
public void SetValue(string address, float value)
{
if (_s7 == null)
{
throw new Exception(string.Format("Siemens S7 S1200通信未连接"));
}
if (!_s7.Write(address, value).IsSuccess)
{
throw new Exception(string.Format("Siemens S7 S1500客户端发送数据失败"));
}
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace WaferAlignment
{
[XmlRootAttribute("CenterOfRotation", IsNullable = false)]
public class CenterOfRotation
{
private double center_X = 0;
private double center_Y = 0;
[XmlElementAttribute("Center_X")]
public double Center_X
{
get { return center_X; }
set { center_X = value; }
}
[XmlElementAttribute("Center_Y")]
public double Center_Y
{
get { return center_Y; }
set { center_Y = value; }
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConVX.VXData
{
public class ConfigStore
{
public object ReadConfigFromFile(Type objectType, string filePath)
{
try
{
object mxml = new object();
XmlSerializer serializer = new XmlSerializer(objectType);
StreamReader reader = new StreamReader(filePath);
mxml = serializer.Deserialize(reader);
reader.Close();
return mxml;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void WriteConfigToFile(object config, Type objectType, string filePath)
{
try
{
object mConfig = new object();
mConfig = config;
XmlSerializer serializer = new XmlSerializer(objectType);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.Unicode;
StringWriter txtwriter = new StringWriter();
XmlWriter xmlwtr = XmlWriter.Create(txtwriter, settings);
serializer.Serialize(xmlwtr, mConfig);
StreamWriter writer = new StreamWriter(filePath);
writer.Write(txtwriter.ToString());
writer.Close();
txtwriter.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,138 @@
using Cognex.VisionPro;
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace ConVX.VXData
{
public class DataPostbox
{
#region
/// <summary>
/// 图像队列:来存储数据信封CogImage8Grey的队列。
/// </summary>
private ConcurrentQueue<CogImage8Grey> _queue;
/// <summary>
/// 判断线程状态
/// </summary>
private AutoResetEvent _autoReset = null;
/// <summary>
/// 线程
/// </summary>
private Task _task;
/// <summary>
/// 控制任务启动
/// </summary>
private CancellationTokenSource RuningToken;
/// <summary>
/// 控制任务终止
/// </summary>
private CancellationTokenSource StopToken;
/// <summary>
/// 最大队列容量
/// </summary>
private int _maxQueueSize = 10;
#endregion
#region
/// <summary>
/// 当有信件被派发时触发的事件。
/// </summary>
public event Action<CogImage8Grey> DeliverLetterEvent;
/// <summary>
/// 当发生错误时触发的事件。
/// </summary>
public event Action<string> ErrorEvent;
#endregion
#region
/// <summary>
/// 构造函数
/// </summary>
public DataPostbox()
{
_queue = new ConcurrentQueue<CogImage8Grey>();
_autoReset = new AutoResetEvent(false);//线程非终止状态
}
/// <summary>
/// 启动派发
/// </summary>
public void Start()
{
RuningToken = new CancellationTokenSource();//创建启动
_task = new Task(() => EnvelopeProcessing(), RuningToken.Token);
_task.Start();//线程启动
}
/// <summary>
/// 停止派发
/// </summary>
public async void Stop()
{
try
{
RuningToken.Cancel();
_autoReset.Set();//为了避免线程正在执行或等待状态
await _task;
}
catch (OperationCanceledException ex)
{
_task.Dispose();
_task = null;
}
}
/// <summary>
/// 邮寄信件
/// </summary>
/// <param name="envelope">信息信件</param>
public void Mailing(CogImage8Grey envelope)
{
//if (_queue.Count > _maxQueueSize)
//{
// ErrorEvent(string.Format("数据队列超出队列最大容量{0}", _maxQueueSize));
//}
//else
//{
// _queue.Enqueue(envelope);
// _autoReset.Set();
//}
_queue.Enqueue(envelope);
_autoReset.Set();
}
#endregion
#region 线
private void EnvelopeProcessing()
{
StopToken = new CancellationTokenSource();
while (!RuningToken.IsCancellationRequested)
{
if (_queue.IsEmpty)
{
_autoReset.WaitOne();
}
else
{
try
{
CogImage8Grey envelope;
if (_queue.TryDequeue(out envelope))
{
DeliverLetterEvent(envelope);
}
Thread.Sleep(20);
}
catch (Exception ex)
{
ErrorEvent(string.Format("数据队列出队失败,原因:{0}", ex.Message.ToString()));
}
}
}
StopToken.Cancel();
}
#endregion
}
}

Binary file not shown.

562
WaferAlignment/Form1.Designer.cs generated Normal file
View File

@@ -0,0 +1,562 @@
namespace WaferAlignment
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.cogRecordDisplay1 = new Cognex.VisionPro.CogRecordDisplay();
this.lbl_Time = new System.Windows.Forms.Label();
this.txt_Time = new System.Windows.Forms.TextBox();
this.lbl_Times = new System.Windows.Forms.Label();
this.txt_Times = new System.Windows.Forms.TextBox();
this.lbl_RMS = new System.Windows.Forms.Label();
this.txt_RMS = new System.Windows.Forms.TextBox();
this.lbl_RotationR = new System.Windows.Forms.Label();
this.txt_RR = new System.Windows.Forms.TextBox();
this.lbl_CommunState = new System.Windows.Forms.Label();
this.lbl_Commun = new System.Windows.Forms.Label();
this.lbl_CameraState = new System.Windows.Forms.Label();
this.lbl_Camera = new System.Windows.Forms.Label();
this.lbl_DR = new System.Windows.Forms.Label();
this.txt_DR = new System.Windows.Forms.TextBox();
this.lbl_DY = new System.Windows.Forms.Label();
this.txt_DY = new System.Windows.Forms.TextBox();
this.lbl_DX = new System.Windows.Forms.Label();
this.txt_DX = new System.Windows.Forms.TextBox();
this.lbl_RotationY = new System.Windows.Forms.Label();
this.txt_RY = new System.Windows.Forms.TextBox();
this.lbl_RotationX = new System.Windows.Forms.Label();
this.txt_RX = new System.Windows.Forms.TextBox();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btn_RunTest = new System.Windows.Forms.Button();
this.lbl_R = new System.Windows.Forms.Label();
this.nud_SizeR = new System.Windows.Forms.NumericUpDown();
this.lbl_Y = new System.Windows.Forms.Label();
this.nud_SizeY = new System.Windows.Forms.NumericUpDown();
this.lbl_X = new System.Windows.Forms.Label();
this.nud_SizeX = new System.Windows.Forms.NumericUpDown();
this.btn_Action = new System.Windows.Forms.Button();
this.btn_ToZero = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.cogRecordDisplay1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeY)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeX)).BeginInit();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.cogRecordDisplay1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.lbl_Time);
this.splitContainer1.Panel2.Controls.Add(this.txt_Time);
this.splitContainer1.Panel2.Controls.Add(this.lbl_Times);
this.splitContainer1.Panel2.Controls.Add(this.txt_Times);
this.splitContainer1.Panel2.Controls.Add(this.lbl_RMS);
this.splitContainer1.Panel2.Controls.Add(this.txt_RMS);
this.splitContainer1.Panel2.Controls.Add(this.lbl_RotationR);
this.splitContainer1.Panel2.Controls.Add(this.txt_RR);
this.splitContainer1.Panel2.Controls.Add(this.lbl_CommunState);
this.splitContainer1.Panel2.Controls.Add(this.lbl_Commun);
this.splitContainer1.Panel2.Controls.Add(this.lbl_CameraState);
this.splitContainer1.Panel2.Controls.Add(this.lbl_Camera);
this.splitContainer1.Panel2.Controls.Add(this.lbl_DR);
this.splitContainer1.Panel2.Controls.Add(this.txt_DR);
this.splitContainer1.Panel2.Controls.Add(this.lbl_DY);
this.splitContainer1.Panel2.Controls.Add(this.txt_DY);
this.splitContainer1.Panel2.Controls.Add(this.lbl_DX);
this.splitContainer1.Panel2.Controls.Add(this.txt_DX);
this.splitContainer1.Panel2.Controls.Add(this.lbl_RotationY);
this.splitContainer1.Panel2.Controls.Add(this.txt_RY);
this.splitContainer1.Panel2.Controls.Add(this.lbl_RotationX);
this.splitContainer1.Panel2.Controls.Add(this.txt_RX);
this.splitContainer1.Panel2.Controls.Add(this.dataGridView1);
this.splitContainer1.Panel2.Controls.Add(this.btn_RunTest);
this.splitContainer1.Panel2.Controls.Add(this.lbl_R);
this.splitContainer1.Panel2.Controls.Add(this.nud_SizeR);
this.splitContainer1.Panel2.Controls.Add(this.lbl_Y);
this.splitContainer1.Panel2.Controls.Add(this.nud_SizeY);
this.splitContainer1.Panel2.Controls.Add(this.lbl_X);
this.splitContainer1.Panel2.Controls.Add(this.nud_SizeX);
this.splitContainer1.Panel2.Controls.Add(this.btn_Action);
this.splitContainer1.Panel2.Controls.Add(this.btn_ToZero);
this.splitContainer1.Size = new System.Drawing.Size(885, 806);
this.splitContainer1.SplitterDistance = 558;
this.splitContainer1.TabIndex = 1;
//
// cogRecordDisplay1
//
this.cogRecordDisplay1.ColorMapLowerClipColor = System.Drawing.Color.Black;
this.cogRecordDisplay1.ColorMapLowerRoiLimit = 0D;
this.cogRecordDisplay1.ColorMapPredefined = Cognex.VisionPro.Display.CogDisplayColorMapPredefinedConstants.None;
this.cogRecordDisplay1.ColorMapUpperClipColor = System.Drawing.Color.Black;
this.cogRecordDisplay1.ColorMapUpperRoiLimit = 1D;
this.cogRecordDisplay1.Dock = System.Windows.Forms.DockStyle.Fill;
this.cogRecordDisplay1.DoubleTapZoomCycleLength = 2;
this.cogRecordDisplay1.DoubleTapZoomSensitivity = 2.5D;
this.cogRecordDisplay1.Location = new System.Drawing.Point(0, 0);
this.cogRecordDisplay1.MouseWheelMode = Cognex.VisionPro.Display.CogDisplayMouseWheelModeConstants.Zoom1;
this.cogRecordDisplay1.MouseWheelSensitivity = 1D;
this.cogRecordDisplay1.Name = "cogRecordDisplay1";
this.cogRecordDisplay1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("cogRecordDisplay1.OcxState")));
this.cogRecordDisplay1.Size = new System.Drawing.Size(885, 558);
this.cogRecordDisplay1.TabIndex = 0;
//
// lbl_Time
//
this.lbl_Time.AutoSize = true;
this.lbl_Time.Location = new System.Drawing.Point(655, 25);
this.lbl_Time.Name = "lbl_Time";
this.lbl_Time.Size = new System.Drawing.Size(65, 12);
this.lbl_Time.TabIndex = 32;
this.lbl_Time.Text = "检测时间:";
//
// txt_Time
//
this.txt_Time.Location = new System.Drawing.Point(741, 22);
this.txt_Time.Name = "txt_Time";
this.txt_Time.ReadOnly = true;
this.txt_Time.Size = new System.Drawing.Size(129, 21);
this.txt_Time.TabIndex = 31;
//
// lbl_Times
//
this.lbl_Times.AutoSize = true;
this.lbl_Times.Location = new System.Drawing.Point(234, 15);
this.lbl_Times.Name = "lbl_Times";
this.lbl_Times.Size = new System.Drawing.Size(89, 12);
this.lbl_Times.TabIndex = 30;
this.lbl_Times.Text = "整体检测时间:";
//
// txt_Times
//
this.txt_Times.Location = new System.Drawing.Point(326, 12);
this.txt_Times.Name = "txt_Times";
this.txt_Times.ReadOnly = true;
this.txt_Times.Size = new System.Drawing.Size(129, 21);
this.txt_Times.TabIndex = 29;
//
// lbl_RMS
//
this.lbl_RMS.AutoSize = true;
this.lbl_RMS.Location = new System.Drawing.Point(655, 133);
this.lbl_RMS.Name = "lbl_RMS";
this.lbl_RMS.Size = new System.Drawing.Size(71, 12);
this.lbl_RMS.TabIndex = 28;
this.lbl_RMS.Text = "RMS偏差量";
//
// txt_RMS
//
this.txt_RMS.Location = new System.Drawing.Point(741, 130);
this.txt_RMS.Name = "txt_RMS";
this.txt_RMS.ReadOnly = true;
this.txt_RMS.Size = new System.Drawing.Size(129, 21);
this.txt_RMS.TabIndex = 27;
//
// lbl_RotationR
//
this.lbl_RotationR.AutoSize = true;
this.lbl_RotationR.Location = new System.Drawing.Point(655, 106);
this.lbl_RotationR.Name = "lbl_RotationR";
this.lbl_RotationR.Size = new System.Drawing.Size(77, 12);
this.lbl_RotationR.TabIndex = 26;
this.lbl_RotationR.Text = "拟合半径 R";
//
// txt_RR
//
this.txt_RR.Location = new System.Drawing.Point(741, 103);
this.txt_RR.Name = "txt_RR";
this.txt_RR.ReadOnly = true;
this.txt_RR.Size = new System.Drawing.Size(129, 21);
this.txt_RR.TabIndex = 25;
//
// lbl_CommunState
//
this.lbl_CommunState.BackColor = System.Drawing.Color.Red;
this.lbl_CommunState.ForeColor = System.Drawing.Color.White;
this.lbl_CommunState.Location = new System.Drawing.Point(86, 45);
this.lbl_CommunState.Name = "lbl_CommunState";
this.lbl_CommunState.Size = new System.Drawing.Size(89, 23);
this.lbl_CommunState.TabIndex = 24;
this.lbl_CommunState.Text = "未连接";
this.lbl_CommunState.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lbl_Commun
//
this.lbl_Commun.AutoSize = true;
this.lbl_Commun.Location = new System.Drawing.Point(15, 50);
this.lbl_Commun.Name = "lbl_Commun";
this.lbl_Commun.Size = new System.Drawing.Size(59, 12);
this.lbl_Commun.TabIndex = 23;
this.lbl_Commun.Text = "PLC状态";
//
// lbl_CameraState
//
this.lbl_CameraState.BackColor = System.Drawing.Color.Red;
this.lbl_CameraState.ForeColor = System.Drawing.Color.White;
this.lbl_CameraState.Location = new System.Drawing.Point(86, 12);
this.lbl_CameraState.Name = "lbl_CameraState";
this.lbl_CameraState.Size = new System.Drawing.Size(89, 23);
this.lbl_CameraState.TabIndex = 22;
this.lbl_CameraState.Text = "未连接";
this.lbl_CameraState.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lbl_Camera
//
this.lbl_Camera.AutoSize = true;
this.lbl_Camera.Location = new System.Drawing.Point(15, 17);
this.lbl_Camera.Name = "lbl_Camera";
this.lbl_Camera.Size = new System.Drawing.Size(65, 12);
this.lbl_Camera.TabIndex = 21;
this.lbl_Camera.Text = "相机状态:";
//
// lbl_DR
//
this.lbl_DR.AutoSize = true;
this.lbl_DR.Location = new System.Drawing.Point(655, 214);
this.lbl_DR.Name = "lbl_DR";
this.lbl_DR.Size = new System.Drawing.Size(65, 12);
this.lbl_DR.TabIndex = 20;
this.lbl_DR.Text = "偏差量 R";
//
// txt_DR
//
this.txt_DR.Location = new System.Drawing.Point(741, 211);
this.txt_DR.Name = "txt_DR";
this.txt_DR.ReadOnly = true;
this.txt_DR.Size = new System.Drawing.Size(129, 21);
this.txt_DR.TabIndex = 19;
//
// lbl_DY
//
this.lbl_DY.AutoSize = true;
this.lbl_DY.Location = new System.Drawing.Point(655, 187);
this.lbl_DY.Name = "lbl_DY";
this.lbl_DY.Size = new System.Drawing.Size(65, 12);
this.lbl_DY.TabIndex = 18;
this.lbl_DY.Text = "偏差量 Y";
//
// txt_DY
//
this.txt_DY.Location = new System.Drawing.Point(741, 184);
this.txt_DY.Name = "txt_DY";
this.txt_DY.ReadOnly = true;
this.txt_DY.Size = new System.Drawing.Size(129, 21);
this.txt_DY.TabIndex = 17;
//
// lbl_DX
//
this.lbl_DX.AutoSize = true;
this.lbl_DX.Location = new System.Drawing.Point(655, 160);
this.lbl_DX.Name = "lbl_DX";
this.lbl_DX.Size = new System.Drawing.Size(65, 12);
this.lbl_DX.TabIndex = 16;
this.lbl_DX.Text = "偏差量 X";
//
// txt_DX
//
this.txt_DX.Location = new System.Drawing.Point(741, 157);
this.txt_DX.Name = "txt_DX";
this.txt_DX.ReadOnly = true;
this.txt_DX.Size = new System.Drawing.Size(129, 21);
this.txt_DX.TabIndex = 15;
//
// lbl_RotationY
//
this.lbl_RotationY.AutoSize = true;
this.lbl_RotationY.Location = new System.Drawing.Point(655, 79);
this.lbl_RotationY.Name = "lbl_RotationY";
this.lbl_RotationY.Size = new System.Drawing.Size(77, 12);
this.lbl_RotationY.TabIndex = 14;
this.lbl_RotationY.Text = "拟合中心 Y";
//
// txt_RY
//
this.txt_RY.Location = new System.Drawing.Point(741, 76);
this.txt_RY.Name = "txt_RY";
this.txt_RY.ReadOnly = true;
this.txt_RY.Size = new System.Drawing.Size(129, 21);
this.txt_RY.TabIndex = 13;
//
// lbl_RotationX
//
this.lbl_RotationX.AutoSize = true;
this.lbl_RotationX.Location = new System.Drawing.Point(655, 52);
this.lbl_RotationX.Name = "lbl_RotationX";
this.lbl_RotationX.Size = new System.Drawing.Size(77, 12);
this.lbl_RotationX.TabIndex = 12;
this.lbl_RotationX.Text = "拟合中心 X";
//
// txt_RX
//
this.txt_RX.Location = new System.Drawing.Point(741, 49);
this.txt_RX.Name = "txt_RX";
this.txt_RX.ReadOnly = true;
this.txt_RX.Size = new System.Drawing.Size(129, 21);
this.txt_RX.TabIndex = 11;
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4});
this.dataGridView1.Location = new System.Drawing.Point(181, 53);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(461, 188);
this.dataGridView1.TabIndex = 10;
//
// Column1
//
this.Column1.HeaderText = "角度";
this.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
//
// Column2
//
this.Column2.HeaderText = "X";
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
//
// Column3
//
this.Column3.HeaderText = "Y";
this.Column3.Name = "Column3";
this.Column3.ReadOnly = true;
//
// Column4
//
this.Column4.HeaderText = "检测时间";
this.Column4.Name = "Column4";
this.Column4.ReadOnly = true;
//
// btn_RunTest
//
this.btn_RunTest.Location = new System.Drawing.Point(481, 12);
this.btn_RunTest.Name = "btn_RunTest";
this.btn_RunTest.Size = new System.Drawing.Size(161, 23);
this.btn_RunTest.TabIndex = 9;
this.btn_RunTest.Text = "启动检测";
this.btn_RunTest.UseVisualStyleBackColor = true;
this.btn_RunTest.Click += new System.EventHandler(this.btn_RunTest_Click);
//
// lbl_R
//
this.lbl_R.AutoSize = true;
this.lbl_R.Location = new System.Drawing.Point(15, 193);
this.lbl_R.Name = "lbl_R";
this.lbl_R.Size = new System.Drawing.Size(59, 12);
this.lbl_R.TabIndex = 7;
this.lbl_R.Text = "R轴位置";
//
// nud_SizeR
//
this.nud_SizeR.DecimalPlaces = 2;
this.nud_SizeR.Location = new System.Drawing.Point(80, 191);
this.nud_SizeR.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.nud_SizeR.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.nud_SizeR.Name = "nud_SizeR";
this.nud_SizeR.Size = new System.Drawing.Size(95, 21);
this.nud_SizeR.TabIndex = 8;
//
// lbl_Y
//
this.lbl_Y.AutoSize = true;
this.lbl_Y.Location = new System.Drawing.Point(15, 166);
this.lbl_Y.Name = "lbl_Y";
this.lbl_Y.Size = new System.Drawing.Size(59, 12);
this.lbl_Y.TabIndex = 5;
this.lbl_Y.Text = "Y轴位置";
//
// nud_SizeY
//
this.nud_SizeY.DecimalPlaces = 2;
this.nud_SizeY.Location = new System.Drawing.Point(80, 164);
this.nud_SizeY.Minimum = new decimal(new int[] {
100,
0,
0,
-2147483648});
this.nud_SizeY.Name = "nud_SizeY";
this.nud_SizeY.Size = new System.Drawing.Size(95, 21);
this.nud_SizeY.TabIndex = 6;
this.nud_SizeY.Value = new decimal(new int[] {
1,
0,
0,
-2147483648});
//
// lbl_X
//
this.lbl_X.AutoSize = true;
this.lbl_X.Location = new System.Drawing.Point(15, 139);
this.lbl_X.Name = "lbl_X";
this.lbl_X.Size = new System.Drawing.Size(59, 12);
this.lbl_X.TabIndex = 3;
this.lbl_X.Text = "X轴位置";
//
// nud_SizeX
//
this.nud_SizeX.DecimalPlaces = 2;
this.nud_SizeX.Location = new System.Drawing.Point(80, 137);
this.nud_SizeX.Minimum = new decimal(new int[] {
100,
0,
0,
-2147483648});
this.nud_SizeX.Name = "nud_SizeX";
this.nud_SizeX.Size = new System.Drawing.Size(95, 21);
this.nud_SizeX.TabIndex = 4;
this.nud_SizeX.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// btn_Action
//
this.btn_Action.Location = new System.Drawing.Point(14, 218);
this.btn_Action.Name = "btn_Action";
this.btn_Action.Size = new System.Drawing.Size(161, 23);
this.btn_Action.TabIndex = 1;
this.btn_Action.Text = "执行动作";
this.btn_Action.UseVisualStyleBackColor = true;
this.btn_Action.Click += new System.EventHandler(this.btn_Action_Click);
//
// btn_ToZero
//
this.btn_ToZero.Location = new System.Drawing.Point(17, 99);
this.btn_ToZero.Name = "btn_ToZero";
this.btn_ToZero.Size = new System.Drawing.Size(161, 23);
this.btn_ToZero.TabIndex = 0;
this.btn_ToZero.Text = "三轴回零";
this.btn_ToZero.UseVisualStyleBackColor = true;
this.btn_ToZero.Click += new System.EventHandler(this.btn_ToZero_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(885, 806);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "晶圆对位验证程序";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Load += new System.EventHandler(this.Form1_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.cogRecordDisplay1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeR)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeY)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_SizeX)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private Cognex.VisionPro.CogRecordDisplay cogRecordDisplay1;
private System.Windows.Forms.Button btn_ToZero;
private System.Windows.Forms.Label lbl_R;
private System.Windows.Forms.NumericUpDown nud_SizeR;
private System.Windows.Forms.Label lbl_Y;
private System.Windows.Forms.NumericUpDown nud_SizeY;
private System.Windows.Forms.Label lbl_X;
private System.Windows.Forms.NumericUpDown nud_SizeX;
private System.Windows.Forms.Button btn_Action;
private System.Windows.Forms.Button btn_RunTest;
private System.Windows.Forms.Label lbl_RotationY;
private System.Windows.Forms.TextBox txt_RY;
private System.Windows.Forms.Label lbl_RotationX;
private System.Windows.Forms.TextBox txt_RX;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Label lbl_DY;
private System.Windows.Forms.TextBox txt_DY;
private System.Windows.Forms.Label lbl_DX;
private System.Windows.Forms.TextBox txt_DX;
private System.Windows.Forms.Label lbl_DR;
private System.Windows.Forms.TextBox txt_DR;
private System.Windows.Forms.Label lbl_CameraState;
private System.Windows.Forms.Label lbl_Camera;
private System.Windows.Forms.Label lbl_CommunState;
private System.Windows.Forms.Label lbl_Commun;
private System.Windows.Forms.Label lbl_RotationR;
private System.Windows.Forms.TextBox txt_RR;
private System.Windows.Forms.Label lbl_RMS;
private System.Windows.Forms.TextBox txt_RMS;
private System.Windows.Forms.Label lbl_Times;
private System.Windows.Forms.TextBox txt_Times;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.Label lbl_Time;
private System.Windows.Forms.TextBox txt_Time;
}
}

1072
WaferAlignment/Form1.cs Normal file

File diff suppressed because it is too large Load Diff

143
WaferAlignment/Form1.resx Normal file
View File

@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="cogRecordDisplay1.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAtwAAAAIB
AAAAAQAAAAAAAAAAAAAAAKIAAAAAAQAAeFsAAKw5AAATAAoKZAALAAAACwAAAAsA//8DAAAAAAADAAEA
AAAFAAAAAAAAAAAABQAAAAAAAAAAAAUAAAAAAAAA8D8TAAAAwAALAP//CwD//xMAAIAAAAMAAwAAAAsA
//8LAAAAAAAAAAAA4D8AAAAAAADgPwAAAAAAAOA/AAAAAAAA4D8BAAAAAQAAAAsA//8LAAAACwAAAAsA
//8L
</value>
</data>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column4.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

Binary file not shown.

22
WaferAlignment/Program.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WaferAlignment
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("WaferAlignment")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("WaferAlignment")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("1e41d94a-8082-46d2-83cd-92d60d48d97a")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WaferAlignment.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WaferAlignment.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WaferAlignment.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

290
WaferAlignment/TCP.cs Normal file
View File

@@ -0,0 +1,290 @@
using FlyTcpFramework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace WaferAlignment
{
class TCP
{
// 用于通讯的本地连接的IP地址
private string ipServer = "192.168.2.200";
// 定义IP服务器
private TcpSvr m_Svc;
// 允许连接的客户端IP地址列表
private List<string> allowedClientIps = new List<string> { "192.168.2.100" };
// 接收数据事件的委托
public event EventHandler<DataReceivedEventArgs> DataReceived;
// 用于存储客户端的字典
private Dictionary<string, TcpClientState> clientDictionary = new Dictionary<string, TcpClientState>();
// 启动服务器
public void StartServer()
{
try
{
ushort _port = 3000;
m_Svc = new TcpSvr(IPAddress.Parse(ipServer), _port, 10, new Coder(Coder.EncodingMothord.Default), AppDomain.CurrentDomain.BaseDirectory);
// 订阅事件
m_Svc.RecvData += new NetEvent(RecvData);
m_Svc.ClientConn += new NetEvent(ClientConnect);
m_Svc.ClientClose += new NetEvent(ClientClosed);
// 启动服务器
m_Svc.Start();
if (m_Svc.IsRun)
{
Console.WriteLine("Server已上线");
}
else
{
Console.WriteLine("Server未能上线");
}
}
catch (Exception ex)
{
throw new Exception("启动服务器失败!" + ex);
}
}
// 停止服务器
public void StopServer()
{
try
{
if (m_Svc != null)
{
// 取消订阅事件
m_Svc.RecvData -= RecvData;
m_Svc.ClientConn -= ClientConnect;
m_Svc.ClientClose -= ClientClosed;
// 停止服务器
m_Svc.Stop();
m_Svc = null;
Console.WriteLine("Server已下线");
}
}
catch (Exception ex)
{
throw new Exception("停止服务器失败!" + ex);
}
}
// 服务器接收数据TCPIP
private void RecvData(object sender, NetEventArgs e)
{
try
{
//string info = Encoding.ASCII.GetString(e.Client.Datagram); // 解码为 ASCII 字符串
string info = e.Client.Datagram; // 收到的数据
string ip = ((IPEndPoint)e.Client.ClientSocket.RemoteEndPoint).Address.ToString();
// 触发处理收到的数据
OnDataReceived(new DataReceivedEventArgs(ip, info));
}
catch (Exception ex)
{
throw new Exception("接收数据失败!" + ex.Message);
}
}
// 触发数据接收事件
protected virtual void OnDataReceived(DataReceivedEventArgs e)
{
// 将空条件运算符改为传统的 null 检查
EventHandler<DataReceivedEventArgs> handler = DataReceived;
if (handler != null)
{
handler(this, e);
}
}
// 发送数据到指定客户端
public void SendData(string clientIp, string data)
{
TcpClientState clientState;
if (clientDictionary.TryGetValue(clientIp, out clientState))
{
byte[] dataBytes = Encoding.Default.GetBytes(data);
clientState.ClientSocket.Send(dataBytes);
Console.WriteLine("向客户端 {0} 发送数据: {1}", clientIp, data);
}
else
{
throw new Exception("客户端未连接");
}
}
//// 触发数据接收事件
//protected virtual void OnDataReceived(DataReceivedEventArgs e)
//{
// DataReceived?.Invoke(this, e);
//}
//// 发送数据到指定客户端
//public void SendData(string clientIp, string data)
//{
// if (clientDictionary.TryGetValue(clientIp, out TcpClientState clientState))
// {
// byte[] dataBytes = Encoding.Default.GetBytes(data);
// clientState.ClientSocket.Send(dataBytes);
// Console.WriteLine($"向客户端 {clientIp} 发送数据: {data}");
// }
// else
// {
// throw new Exception("客户端未连接");
// }
//}
// 客户端是否链接判断
private void ClientConnect(object sender, NetEventArgs e)
{
try
{
string ip = ((IPEndPoint)e.Client.ClientSocket.RemoteEndPoint).Address.ToString();
// 检查客户端IP是否在允许列表中
if (allowedClientIps.Contains(ip))
{
TcpClientState clientState = new TcpClientState(e.Client.ClientSocket, ip);
clientDictionary[ip] = clientState;
//Console.WriteLine($"客户端 {ip} 已连接");
}
else
{
// 拒绝不在允许列表中的客户端连接
//Console.WriteLine($"拒绝客户端 {ip} 的连接");
e.Client.ClientSocket.Close();
}
}
catch (Exception ex)
{
throw new Exception("TCP连接失败" + ex);
}
}
// 客户端链接断开判断
private void ClientClosed(object sender, NetEventArgs e)
{
try
{
string ip = ((IPEndPoint)e.Client.ClientSocket.RemoteEndPoint).Address.ToString();
if (clientDictionary.ContainsKey(ip))
{
clientDictionary.Remove(ip);
//Console.WriteLine($"客户端 {ip} 已断开");
}
}
catch (Exception ex)
{
throw new Exception("通信断开失败!" + ex);
}
}
///// <summary>
///// 客户端是否链接判断
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//void ClientConnect(object sender, NetEventArgs e)
//{
// try
// {
// ip = ((IPEndPoint)e.Client.ClientSocket.RemoteEndPoint).Address.ToString();
// if (ip == ip1)
// {
// //lb_ClientOnlineStatus.Text = "客户端已连接";
// //lb_ClientOnlineStatus.BackColor = Color.GreenYellow;
// }
// }
// catch (Exception ex)
// {
// throw new Exception("TCP连接失败"+ ex.Message);
// }
//}
///// <summary>
///// 客户端链接断开判断
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//void ClientClosed(object sender, NetEventArgs e)
//{
// try
// {
// ip = ((IPEndPoint)e.Client.ClientSocket.RemoteEndPoint).Address.ToString();
// if (ip == ip1)
// {
// //lb_ClientOnlineStatus.Text = "客户端已断开";
// //lb_ClientOnlineStatus.BackColor = Color.Yellow;
// }
// }
// catch (Exception ex)
// {
// throw new Exception("通信断开失败!"+ ex.Message);
// }
//}
}
public class DataReceivedEventArgs : EventArgs
{
public string ClientIp { get; private set;}
public string Data { get; private set; }
public DataReceivedEventArgs(string clientIp, string data)
{
ClientIp = clientIp;
Data = data;
}
}
public class TcpClientState
{
/// <summary>
/// 客户端的套接字
/// </summary>
public Socket ClientSocket { get; private set; }
/// <summary>
/// 客户端的IP地址
/// </summary>
public string ClientIp { get; private set; }
/// <summary>
/// 客户端连接的时间
/// </summary>
public DateTime ConnectionTime { get; private set; }
/// <summary>
/// 客户端的唯一标识符
/// </summary>
public string ClientId { get; private set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="clientSocket">客户端的套接字</param>
/// <param name="clientIp">客户端的IP地址</param>
public TcpClientState(Socket clientSocket, string clientIp)
{
ClientSocket = clientSocket;
ClientIp = clientIp;
ConnectionTime = DateTime.Now;
ClientId = Guid.NewGuid().ToString();
}
}
}

View File

@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{941B8ABC-436F-457D-95DA-A79E23C8CA5D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WaferAlignment</RootNamespace>
<AssemblyName>WaferAlignment</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cognex.VisionPro, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.Caliper, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505, processorArchitecture=AMD64" />
<Reference Include="Cognex.VisionPro.Controls, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505, processorArchitecture=AMD64" />
<Reference Include="Cognex.VisionPro.Core, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.CorePlus, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.Dimensioning, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505, processorArchitecture=AMD64" />
<Reference Include="Cognex.VisionPro.Display.Controls, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.FGGigE, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.ImageFile, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.ImageProcessing, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro.PMAlign, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505, processorArchitecture=AMD64" />
<Reference Include="Cognex.VisionPro.ToolGroup, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro3D, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro3D.Core, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro3D.Display.Controls, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="Cognex.VisionPro3D.Graphic, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505" />
<Reference Include="FlyTcpFramework">
<HintPath>.\FlyTcpFramework.dll</HintPath>
</Reference>
<Reference Include="HslCommunication">
<HintPath>.\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="MvCameraControl.Net">
<HintPath>..\..\..\..\..\..\Program Files (x86)\MVS\Development\DotNet\win64\net40\MvCameraControl.Net.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="QWhale.Common, Version=1.62.4104.36375, Culture=neutral, PublicKeyToken=da632fd1713dff10" />
<Reference Include="QWhale.Editor, Version=1.62.4104.36377, Culture=neutral, PublicKeyToken=da632fd1713dff10" />
<Reference Include="QWhale.Syntax, Version=1.62.4104.36376, Culture=neutral, PublicKeyToken=da632fd1713dff10" />
<Reference Include="QWhale.Syntax.Parsers, Version=1.62.4104.36376, Culture=neutral, PublicKeyToken=da632fd1713dff10" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Camera.cs" />
<Compile Include="CenterOfRotation.cs" />
<Compile Include="ConfigStore.cs" />
<Compile Include="DataPostbox.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCP.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>