diff --git a/WaferAlignment.sln b/WaferAlignment.sln
new file mode 100644
index 0000000..a4027fc
--- /dev/null
+++ b/WaferAlignment.sln
@@ -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
diff --git a/WaferAlignment/App.config b/WaferAlignment/App.config
new file mode 100644
index 0000000..4bfa005
--- /dev/null
+++ b/WaferAlignment/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/WaferAlignment/CalibForm.Designer.cs b/WaferAlignment/CalibForm.Designer.cs
new file mode 100644
index 0000000..aa94a2e
--- /dev/null
+++ b/WaferAlignment/CalibForm.Designer.cs
@@ -0,0 +1,39 @@
+namespace WaferAlignment
+{
+ partial class CalibForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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
+ }
+}
\ No newline at end of file
diff --git a/WaferAlignment/CalibForm.cs b/WaferAlignment/CalibForm.cs
new file mode 100644
index 0000000..726754e
--- /dev/null
+++ b/WaferAlignment/CalibForm.cs
@@ -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();
+ }
+ }
+}
diff --git a/WaferAlignment/Camera.cs b/WaferAlignment/Camera.cs
new file mode 100644
index 0000000..0b75418
--- /dev/null
+++ b/WaferAlignment/Camera.cs
@@ -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 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 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客户端发送数据失败"));
+ }
+ }
+ }
+}
diff --git a/WaferAlignment/CenterOfRotation.cs b/WaferAlignment/CenterOfRotation.cs
new file mode 100644
index 0000000..7c61a34
--- /dev/null
+++ b/WaferAlignment/CenterOfRotation.cs
@@ -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; }
+ }
+ }
+}
diff --git a/WaferAlignment/ConfigStore.cs b/WaferAlignment/ConfigStore.cs
new file mode 100644
index 0000000..a223eee
--- /dev/null
+++ b/WaferAlignment/ConfigStore.cs
@@ -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);
+ }
+ }
+ }
+}
diff --git a/WaferAlignment/DataPostbox.cs b/WaferAlignment/DataPostbox.cs
new file mode 100644
index 0000000..d814cad
--- /dev/null
+++ b/WaferAlignment/DataPostbox.cs
@@ -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 字段
+ ///
+ /// 图像队列:来存储数据信封(CogImage8Grey)的队列。
+ ///
+ private ConcurrentQueue _queue;
+ ///
+ /// 判断线程状态
+ ///
+ private AutoResetEvent _autoReset = null;
+ ///
+ /// 线程
+ ///
+ private Task _task;
+ ///
+ /// 控制任务启动
+ ///
+ private CancellationTokenSource RuningToken;
+ ///
+ /// 控制任务终止
+ ///
+ private CancellationTokenSource StopToken;
+ ///
+ /// 最大队列容量
+ ///
+ private int _maxQueueSize = 10;
+ #endregion
+
+ #region 事件
+ ///
+ /// 当有信件被派发时触发的事件。
+ ///
+ public event Action DeliverLetterEvent;
+ ///
+ /// 当发生错误时触发的事件。
+ ///
+ public event Action ErrorEvent;
+ #endregion
+
+ #region 公开的方法
+ ///
+ /// 构造函数
+ ///
+ public DataPostbox()
+ {
+ _queue = new ConcurrentQueue();
+ _autoReset = new AutoResetEvent(false);//线程非终止状态
+ }
+ ///
+ /// 启动派发
+ ///
+ public void Start()
+ {
+ RuningToken = new CancellationTokenSource();//创建启动
+ _task = new Task(() => EnvelopeProcessing(), RuningToken.Token);
+ _task.Start();//线程启动
+ }
+ ///
+ /// 停止派发
+ ///
+ public async void Stop()
+ {
+ try
+ {
+ RuningToken.Cancel();
+ _autoReset.Set();//为了避免线程正在执行或等待状态
+ await _task;
+ }
+ catch (OperationCanceledException ex)
+ {
+ _task.Dispose();
+ _task = null;
+ }
+ }
+ ///
+ /// 邮寄信件
+ ///
+ /// 信息信件
+ 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
+
+
+ }
+}
diff --git a/WaferAlignment/FlyTcpFramework.dll b/WaferAlignment/FlyTcpFramework.dll
new file mode 100644
index 0000000..0a93f1e
Binary files /dev/null and b/WaferAlignment/FlyTcpFramework.dll differ
diff --git a/WaferAlignment/Form1.Designer.cs b/WaferAlignment/Form1.Designer.cs
new file mode 100644
index 0000000..80069f2
--- /dev/null
+++ b/WaferAlignment/Form1.Designer.cs
@@ -0,0 +1,562 @@
+namespace WaferAlignment
+{
+ partial class Form1
+ {
+ ///
+ /// 必需的设计器变量。
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// 清理所有正在使用的资源。
+ ///
+ /// 如果应释放托管资源,为 true;否则为 false。
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows 窗体设计器生成的代码
+
+ ///
+ /// 设计器支持所需的方法 - 不要
+ /// 使用代码编辑器修改此方法的内容。
+ ///
+ 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;
+
+ }
+}
+
diff --git a/WaferAlignment/Form1.cs b/WaferAlignment/Form1.cs
new file mode 100644
index 0000000..2b027bd
--- /dev/null
+++ b/WaferAlignment/Form1.cs
@@ -0,0 +1,1072 @@
+using Cognex.VisionPro;
+using Cognex.VisionPro.Dimensioning;
+using Cognex.VisionPro.ImageFile;
+using Cognex.VisionPro.ToolBlock;
+using Cognex.VisionPro.ImageProcessing;
+using Cognex.VisionPro.Caliper;
+using ConVX.VXData;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml.Serialization;
+using System.Diagnostics;
+using Cognex.VisionPro.PMAlign;
+
+
+namespace WaferAlignment
+{
+ public partial class Form1 : Form
+ {
+ Camera _cam;
+ SiemensS7 _s7;
+ DataPostbox ImageData;
+ TCP _tcp;
+
+ string arSizeX = "DB7.DBD48";
+ string arSizeY = "DB7.DBD52";
+ string arSizeR = "DB7.DBD56";
+ string arSpeedX = "DB7.DBD60";
+ string arSpeedY = "DB7.DBD64";
+ string arSpeedR = "DB7.DBD68";
+ ///
+ /// 执行模式
+ ///
+ string arMode = "DB7.DBW72";//
+ ///
+ /// 执行上面设置的动作
+ ///
+ string arAction = "DB7.DBX74.0";
+ ///
+ ///动作执行完成
+ ///
+ string arOver = "DB7.DBX74.1";
+ string arLED = "M3.0";
+ ///
+ /// 偏转角度
+ ///
+ string arAngle = "DB7.DBD76";//设置触发拍照的偏转角度
+
+
+
+ string vppPath;
+ CogToolBlock mTB;
+ CogToolBlock mTB_1;
+ CogToolBlock mTB_2;
+
+
+ float R = 11.25F;//1024->12
+ //CogImage8Grey OutputImg;
+
+ //旋转中心的坐标应将标定的数据保存后获取
+ double circleCenterX;
+ double circleCenterY;
+ //XML文件读取与写入
+ ConfigStore _ConfigStore = new ConfigStore();
+ CenterOfRotation _center = new CenterOfRotation();
+ //偏差量
+ double deviationX;
+ double deviationY;
+
+ //
+ string TCP_time = "0";
+ string TCP_X = "0";
+ string TCP_Y = "0";
+ string TCP_R = "0";
+ string TCP_RMS = "0";
+
+ bool OKorNG = false;//判断检查是否完成
+ //
+
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+ private void Form1_Load(object sender, EventArgs e)
+ {
+
+ // 连接相机
+ try
+ {
+ _cam = new Camera();
+ _cam.Connect();
+ _cam.OutputImageEvent += _cam_OutputImageEvent;
+ lbl_CameraState.BackColor = Color.Lime;
+ lbl_CameraState.Text = "已连接";
+ }
+ catch (Exception ex)
+ {
+ lbl_CameraState.BackColor = Color.Red;
+ lbl_CameraState.Text = "连接失败";
+ MessageBox.Show(ex.Message);
+ }
+ // 连接通信
+ try
+ {
+ _s7 = new SiemensS7("192.168.1.10");
+ _s7.Connect();
+ while (!_s7.OK)
+ {
+
+ }
+ _s7.SetValue(arSpeedX, (float)2);//5
+ _s7.SetValue(arSpeedY, (float)2);//2
+ _s7.SetValue(arSpeedR, (float)360);//100
+ _s7.SetValue(arSizeX, (float)0);
+ _s7.SetValue(arSizeY, (float)0);
+ _s7.SetValue(arSizeR, (float)0);
+ _s7.SetValue(arAngle, Convert.ToSingle(R));//角度为10
+ lbl_CommunState.BackColor = Color.Lime;
+ lbl_CommunState.Text = "已连接";
+ }
+ catch (Exception ex)
+ {
+ lbl_CommunState.BackColor = Color.Red;
+ lbl_CommunState.Text = "连接失败";
+ MessageBox.Show(ex.Message);
+ }
+ //链接TCP通信
+ try
+ {
+ //通信初始化
+ _tcp = new TCP();
+ _tcp.DataReceived += _tcp_DataReceived;
+ _tcp.StartServer();
+
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+
+ }
+ try
+ {
+ // 加载VPP文件
+ vppPath = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "vpp", "ToolBlock.vpp");
+
+ mTB = CogSerializer.LoadObjectFromFile(vppPath) as CogToolBlock;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ try
+ {
+ ImageData = new DataPostbox();
+
+ //启动
+ ImageData.Start();
+ // 注册事件处理程序到 DeliverLetterEvent 事件中
+ ImageData.DeliverLetterEvent += MonitorSpot;//查找所有点
+ ImageData.ErrorEvent += ImageData_ErrorEvent;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+
+ }
+
+ // 指定XML文件路径
+ string filePath = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "vpp", "CenterOfRotation.xml"); //@"D:\晶圆寻边机\XML文件\CenterOfRotation.xml";
+ _center = _ConfigStore.ReadConfigFromFile(_center.GetType(), filePath) as CenterOfRotation;
+ circleCenterX = _center.Center_X;
+ circleCenterY = _center.Center_Y;
+ }
+ ///
+ /// 接收到TCP数据时,根据接收到的数据,进行不同操作
+ ///
+ ///
+ ///
+ private void _tcp_DataReceived(object sender, DataReceivedEventArgs e)
+ {
+ if (this.InvokeRequired)
+ {
+ // 如果当前线程不是UI线程,则使用Invoke在UI线程上执行
+ this.Invoke(new Action