Selaa lähdekoodia

optimize the measure thread

gsp 4 vuotta sitten
vanhempi
commit
c1770077ee

+ 4 - 4
DBManager/MeasureDB.cs

@@ -340,10 +340,10 @@ namespace DBManager
             for (int i = 0; i < 2000; i++)
             {
                 byte[] temps = BitConverter.GetBytes(XrayData[i]);
-                bArray[i] = temps[0];
-                bArray[i + 1] = temps[1];
-                bArray[i + 2] = temps[2];
-                bArray[i + 3] = temps[3];
+                bArray[i*4] = temps[0];
+                bArray[i*4 + 1] = temps[1];
+                bArray[i*4 + 2] = temps[2];
+                bArray[i*4 + 3] = temps[3];
             }
             //开启一个事务
             using (SQLiteTransaction tr = m_db.BeginTransaction())

+ 1 - 1
HOZProject/FormHOZMain.cs

@@ -227,7 +227,7 @@ namespace HOZProject
                 // add by zjx 2020-12-18 为了测试只做能谱部分 end
 
                 
-                m_Ms.InitMeas(m_MeasureFile);
+                m_Ms.InitMeasure(m_MeasureFile);
                 //注册事件
                 m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
                 //注册事件

+ 13 - 10
HOZProject/MeasureMsgDispose/MeasureMsgManage.cs

@@ -32,25 +32,28 @@ namespace HOZProject
             {
                 case "0-0":
                     //停止线程
-                    if (formHOZ.m_BackgroundWorker.IsBusy)
-                    {
-                        formHOZ.m_BackgroundWorker.CancelAsync();
-                        //是否关闭窗体的标识
-                        if (formHOZ.IsClose)
-                        {
-                            formHOZ.Close();
-                        }
-                    }
+                    //if (formHOZ.m_BackgroundWorker.IsBusy)
+                    //{
+                    //    formHOZ.m_BackgroundWorker.CancelAsync();
+                    //    //是否关闭窗体的标识
+                    //    if (formHOZ.IsClose)
+                    //    {
+                    //        formHOZ.Close();
+                    //    }
+                    //}
                     break;
                 case "0-1":
                     //初始化失败
                     if (formHOZ.m_BackgroundWorker.IsBusy)
                     {
                         //修改切孔状态
-                        formHOZ.ChangeCutHoleState(args.HoleName, (int)ThreadState.Failed);
+                        formHOZ.ChangeCutHoleState(args.HoleName, (int)ThreadState.InProcess);
                     }
                     break;
                 case "0-8":
+
+
+
                 case "0-9":
                     if (!args.Picture_Information.Picture_FullPath.Equals(""))
                     {

+ 53 - 0
MeasureData/CutHole.cs

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
 
 using FileManager;
 using System.Xml;
+using System.IO;
 
 namespace MeasureData
 {
@@ -45,6 +46,16 @@ namespace MeasureData
         /// 切割孔名
         /// </summary>
         private string m_HoleName;
+        public int HoleNo;
+        public string data_path;
+        public string focus_path;
+        public string StigX_path;
+
+        public string StigY_path;
+
+        public string EDS_path;
+
+        public string workingFolder;
 
         public string HoleName
         {
@@ -115,6 +126,48 @@ namespace MeasureData
             m_state = State.Ready;
             m_switch = false;
             Position = new SemPosition();
+        }
+        public void InitPath(int holeNo,string currentWorkingFolder)
+        {
+            HoleNo = holeNo;
+            // arg.HoleName = this.HoleName;
+            //最终数据存放目录
+            workingFolder = currentWorkingFolder;
+            data_path = workingFolder + "\\" + this.HoleName;
+          
+            //对焦数据存放目录
+            focus_path = workingFolder + "\\" + this.HoleName + "\\Focus";
+            //MParam.AutoFocus.Path = focus_path;
+            if (!Directory.Exists(focus_path))
+            {
+                Directory.CreateDirectory(focus_path);
+            }
+            //StigX数据存放目录
+            StigX_path = workingFolder + "\\" + this.HoleName + "\\StigX";
+            //MParam.AutoStigX.Path = StigX_path;
+            if (!Directory.Exists(StigX_path))
+            {
+                Directory.CreateDirectory(StigX_path);
+            }
+            //StigY数据存放目录
+            StigY_path = workingFolder + "\\" + this.HoleName + "\\StigY";
+            //MParam.AutoStigY.Path = StigY_path;
+            if (!Directory.Exists(StigY_path))
+            {
+                Directory.CreateDirectory(StigY_path);
+            }
+            //EDS数据存放路径
+          
+                EDS_path = workingFolder + "\\" + this.HoleName + "\\EDS";
+               // MParam.EDSParam.Path = EDS_path;
+                if (!Directory.Exists(EDS_path))
+                {
+                    Directory.CreateDirectory(EDS_path);
+                }
+           
+
+
+
         }
 
         //样品孔存储xml文档

+ 64 - 12
MeasureThread/Focus.cs

@@ -31,15 +31,43 @@ namespace MeasureThread
             }
             return prm;
         }
+        public bool SetMagnification(float newMag)
+        {
+            bool mRetMag = iSEM.SetMagnification(newMag);
+
+
+            // 
+            float set = newMag;
+            Thread.Sleep(2000);
+            float current = iSEM.GetMagnification();
+            Thread.Sleep(200);
+            while (Math.Abs(current - set) > 1)
+            {
+                iSEM.SetMagnification(set);
+                Thread.Sleep(200);
+                current = iSEM.GetMagnification();
+            }
+
+            return true;
+        }
         public bool DoFocusByNewMagnification(float newMag)
         {
 
             // set magnification
             bool mRetMag = iSEM.SetMagnification(newMag);
 
-            Thread.Sleep(500);
+         
             // 
-           
+            float set = newMag;
+            Thread.Sleep(1000);
+            float current = iSEM.GetMagnification();
+            Thread.Sleep(200);
+            while (Math.Abs(current - set) > 1)
+            {
+                iSEM.SetMagnification(set);
+                Thread.Sleep(200);
+                current = iSEM.GetMagnification();
+            }
 
             // set the window of focusing.
             iSEM.SetReduced(prm.reduceWindowPos.X, prm.reduceWindowPos.Y, (int)prm.reduceWinWidth, (int)prm.reduceWinHeight);
@@ -47,8 +75,13 @@ namespace MeasureThread
             iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//
             if (prm.IfAutoBrightnessAndContrast)
             {
+                iSEM.SetAutoBright(100);
+                Thread.Sleep(200);
+                iSEM.SetAutoContrast(100);
+                Thread.Sleep(200);
                 iSEM.SetAutoVideoBrightnessAndContrast();
-                Thread.Sleep(5000);
+                Thread.Sleep(6000);
+                iSEM.SetAutoVideoOff();
             }
             else
             {
@@ -59,7 +92,12 @@ namespace MeasureThread
                 iSEM.SetContrast(prm.contrast);//30.0f
                 Thread.Sleep(200);
             }
-            if (!ImageFocus1(false))
+            bool ifStig=false;
+            if (newMag > 5000)
+            {
+                ifStig = true;
+            }
+            if (!ImageFocus1(ifStig))
             {
                 log.Error("自动对焦失败,程序退出。", false);
 
@@ -69,10 +107,10 @@ namespace MeasureThread
             iSEM.CloseReduced();
             Thread.Sleep(200);
 
-            iSEM.SetAutoVideoBrightnessAndContrast();
+        
 
-            float cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
+            //float cycle_time = iSEM.GetCycleTime();
+            //Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
 
             return true;
 
@@ -114,8 +152,13 @@ namespace MeasureThread
             iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//
             if (prm.IfAutoBrightnessAndContrast)
             {
+                iSEM.SetAutoBright(100);
+                Thread.Sleep(200);
+                iSEM.SetAutoContrast(100);
+                Thread.Sleep(200);
                 iSEM.SetAutoVideoBrightnessAndContrast();
-                Thread.Sleep(5000);
+                Thread.Sleep(6000);
+                iSEM.SetAutoVideoOff();
             }
             else
             {
@@ -126,7 +169,16 @@ namespace MeasureThread
                 iSEM.SetContrast(prm.contrast);//30.0f
                 Thread.Sleep(200);
             }
-            if (!ImageFocus1(prm.ifStig))
+            bool ifStig = false;
+            if (prm.mag > 5000)
+            {
+                ifStig = true;
+            }
+            else
+            {
+                ifStig = prm.ifStig;
+            }
+            if (!ImageFocus1(ifStig))
             {
                 log.Error("自动对焦失败,程序退出。", false);
                 
@@ -136,10 +188,10 @@ namespace MeasureThread
             iSEM.CloseReduced();
             Thread.Sleep(200);           
 
-            iSEM.SetAutoVideoBrightnessAndContrast();
+           // iSEM.SetAutoVideoBrightnessAndContrast();
            
-           float cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
+           //float cycle_time = iSEM.GetCycleTime();
+           // Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
 
             return true;
         }

+ 120 - 21
MeasureThread/Locate.cs

@@ -25,6 +25,7 @@ namespace MeasureThread
         private ISEMControl iSEM;
         const float Z_Min = 0;
         const float Z_Max = 0.05f;
+        const float fSateyZ = (float)0.007;//单位是米
         public Locate(ISEMControl iSEM)
         {
             this.log = NLog.LogManager.GetCurrentClassLogger();
@@ -32,14 +33,116 @@ namespace MeasureThread
            
             this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
         }
-        //public Locate( LocateParam prm, ISEMControl iSEM)
-        //{
-        //    this.log = NLog.LogManager.GetCurrentClassLogger();
+
+        public bool LocateCutHolePosition(MeasureData.CutHole currHole, bool ifTilt)
+        {
+            if (ifTilt)//如果是倾斜样品台,移动Z轴
+            {
+                //0、先移动Z轴到比较低的位置上。
+                if (!MoveZAxis(fSateyZ, Locate.ZAxisDirection.down))
+                {
+
+                    log.Error("测量线程报错:样品台Z轴移动失败,Z移动" + fSateyZ.ToString(), false);
+
+                    return false;
+                }
+
+
+            }
+
+            //1、移动样品台到第一个观测点,先移动R轴,再移动XY轴
+
+            if (!MoveRAxis(currHole.Position.R))
+            {
+
+                log.Error("测量线程报错:样品台R轴移动失败,R为" + currHole.Position.ToString(), false);
+
+                //continue;
+                return false;
+            }
+
+
+            //2、移动XY轴
+            // lo.MoveToPixByMoveStage(currHole.Position.X,currHole.Position.Y)
+            if (!iSEM.MoveStageXY(currHole.Position.X, currHole.Position.Y))
+            {
+
+                log.Error("测量线程报错:样品台XY轴移动失败,(X,Y)为"
+                    + currHole.Position.X.ToString() + ","
+                    + currHole.Position.Y.ToString() + ")", false);
+
+                return false;
+            }
+            while (true)
+            {
+                Thread.Sleep(1000);
+
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+            //判断是否停止进程
+           
+
+            //3、恢复Z轴
+            if (ifTilt)
+            {
+                //恢复Z轴 
+
+                if (!MoveZAxisByAbs(currHole.Position.Z))
+                {
+
+                    log.Error("测量线程报错:样品台Z轴移动失败,Z为" + currHole.Position.Z.ToString(), false);
+
+                    return false;
+                }
+
+            }
+
            
-        //    this.log = log ?? throw new ArgumentNullException(nameof(log));
-        //    this.prm = prm ?? throw new ArgumentNullException(nameof(prm));
-        //    this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
-        //}
+
+            //4、设置WD
+            iSEM.SetWorkingDistance(currHole.Position.WD);
+            Thread.Sleep(1000);
+            return true;
+
+
+        }
+
+        public bool RotateStageByDeltaR(float deltaR)
+        {
+            float Zpos = iSEM.GetStageAtZ();
+            Thread.Sleep(200);
+
+            log.Info("测量线程:当前Z轴位置" + Zpos.ToString() + "m", true);
+            Locate lo = new Locate(iSEM);
+            //选择之前,先降Z轴
+            lo.MoveZAxis(fSateyZ, Locate.ZAxisDirection.down);
+
+           
+
+            iSEM.SetStageDeltaR(deltaR);
+            while (true)
+            {
+                Thread.Sleep(1000);
+
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+            Thread.Sleep(1000);
+            if (!MoveZAxisByAbs(Zpos))
+            {
+                log.Error("测量线程报错:样品台Z回到安全位置失败", false);
+                return false;
+            }
+
+            return true;
+
+
+        }
         public void RecordCurrentBeamShiftAndStagePosition()
         {
             #region 记录初始设置的BeamShift的百分比和样品台XY位置
@@ -138,7 +241,7 @@ namespace MeasureThread
 
             while (true)
             {
-                Thread.Sleep(2000);
+                Thread.Sleep(1000);
                 if (iSEM.GetStageIs() == 0)
                 {
                     break;
@@ -155,7 +258,7 @@ namespace MeasureThread
             }
             while (true)
             {
-                Thread.Sleep(4000);
+                Thread.Sleep(1000);
                 if (iSEM.GetStageIs() == 0)
                 {
                     break;
@@ -184,7 +287,7 @@ namespace MeasureThread
 
             while (true)
             {
-                Thread.Sleep(2000);
+                Thread.Sleep(1000);
                 if (iSEM.GetStageIs() == 0)
                 {
                     break;
@@ -240,7 +343,7 @@ namespace MeasureThread
                 //判断是否移动完成
                 while (true)
                 {
-                    Thread.Sleep(5000);
+                    Thread.Sleep(1000);
                     if (iSEM.GetStageIs() == 0)
                     {
                         break;
@@ -259,7 +362,7 @@ namespace MeasureThread
                 //判断是否移动完成
                 while (true)
                 {
-                    Thread.Sleep(5000);
+                    Thread.Sleep(1000);
                     if (iSEM.GetStageIs() == 0)
                     {
                         break;
@@ -348,7 +451,7 @@ namespace MeasureThread
                 //判断是否移动完成
                 while (true)
                 {
-                    Thread.Sleep(4000);
+                    Thread.Sleep(1000);
                     if (iSEM.GetStageIs() == 0)
                     {
                         break;
@@ -396,7 +499,7 @@ namespace MeasureThread
                 //判断是否移动完成
                 while (true)
                 {
-                    Thread.Sleep(4000);
+                    Thread.Sleep(1000);
                     if (iSEM.GetStageIs() == 0)
                     {
                         break;
@@ -416,11 +519,9 @@ namespace MeasureThread
             }
             this.prm.PositionX = x;
             this.prm.PositionY = y;
-            //this.prm.PixelSize_Y_cur = pixelSize_Y_cur;
+            
              MoveToPixByMoveStage();
-            Thread.Sleep(1000);
-            iSEM.SetAutoVideoBrightnessAndContrast();
-            Thread.Sleep(3000);
+            Thread.Sleep(200);
             return true;
 
         }
@@ -435,9 +536,7 @@ namespace MeasureThread
             this.prm.PositionY = y;
             this.prm.PixelSize_Y_cur = pixelSize_Y_cur;
              MoveToPix();
-            Thread.Sleep(1000);
-            iSEM.SetAutoVideoBrightnessAndContrast();
-            Thread.Sleep(3000);
+            Thread.Sleep(200);
             return true;
         }
         public LocateParam GetParam()

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 134 - 744
MeasureThread/Measure.cs


+ 21 - 15
MeasureThread/Photo.cs

@@ -33,8 +33,7 @@ namespace MeasureThread
             }
             return prm;
         }
-        public bool TakePhoto()
-        {
+        public bool TakePhoto()        {
             
 
             if (!iSEM.SetMagnification(prm.Mag))
@@ -42,30 +41,37 @@ namespace MeasureThread
                 return false;
             }
 
+
+            float set = prm.Mag;
             Thread.Sleep(500);
-            //iSEM.SetReduced(402, 384, 200, 200);
-            iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");
-            iSEM.SetAutoVideoBrightnessAndContrast();
-            Thread.Sleep(3000);
-            //iSEM.CloseReduced();
-            iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//iSEM.CmdSaveRate();
-          
-            //add by sun 2020 - 12 - 15 增加不同样品扫描速度参数,每大类样品3种扫描速度 end
-            Thread.Sleep(200);
-          float  cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
+            float current = iSEM.GetMagnification();
+            while (Math.Abs(current - set) > 1)
+            {
+                iSEM.SetMagnification(set);
+                Thread.Sleep(200);
+                current = iSEM.GetMagnification();
+            }
 
+            iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//iSEM.CmdSaveRate();
+            Thread.Sleep(500);
 
 
+            //拍照前改变速度,延时          
+            iSEM.CmdLineScan();
+            Thread.Sleep(200);
+             float   cycle_time = iSEM.GetCycleTime();
+            Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
             if (!GetImage(prm.savePath))
             {
 
                 log.Error("SEM拍照失败", false);
                 return false;
             }
+            iSEM.CmdPixelScan();
+            Thread.Sleep(200);
             iSEM.CmdFocusScanSpeed("CMD_SCANRATE4");//CmdFocusRate(4);
-            cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
+            Thread.Sleep(500);
+
            
             return true;
         }

+ 1 - 54
OxfordTest/Form1.cs

@@ -287,60 +287,7 @@ namespace OxfordTest
 
             ShowData(XrayData, listElement);
             li++;
-           // Console.WriteLine(li.ToString());
-            //byte[] bArray = new byte[8000];
-
-            //for (int i = 0; i < 2000; i++)
-            //{
-            //    byte[] temps = BitConverter.GetBytes(XrayData[i]);
-            //    bArray[i * 4] = temps[0];
-            //    bArray[i * 4 + 1] = temps[1];
-            //    bArray[i * 4 + 2] = temps[2];
-            //    bArray[i * 4 + 3] = temps[3];
-            //}
-
-            //SQLiteConnection m_db = new SQLiteConnection("data source =" + @"E:\HOZ\Test\MeasureDB.db");
-            //m_db.Open();
-
-            ////开启一个事务
-            //using (SQLiteTransaction tr = m_db.BeginTransaction())
-            //{
-            //    //向能谱数据表插入数据
-            //    string sql = "INSERT INTO XrayData(ID, APID, Type, X, Y, AreasID, ElementNum, XrayData) values ("
-            //        + 2.ToString() + ","
-            //        + 3.ToString() + ","
-            //        + 0.ToString() + ","
-            //        + 111.ToString() + ","
-            //        + 222.ToString() + ","
-            //        + (-1).ToString() + ","
-            //        + listElement.Count.ToString() + ",:XrayData)";
-
-            //    SQLiteCommand command = new SQLiteCommand(sql, m_db);
-            //    command.Parameters.Add("XrayData", System.Data.DbType.Binary).Value = bArray;  // BLOB
-            //    command.ExecuteNonQuery();
-
-            //    //向能谱元素表插入数据
-            //    int i = 0;
-            //    foreach (KeyValuePair<string, double> element in listElement)
-            //    {
-
-            //        sql = "INSERT INTO Element(XayID, ElementNum, ElementID, Name, Percent) values ("
-            //           + 2.ToString() + ","
-            //           + listElement.Count.ToString() + ","
-            //           + i.ToString() + ",'"
-            //           + element.Key + "',"
-            //           + element.Value.ToString() + ")";
-
-            //        command = new SQLiteCommand(sql, m_db);
-            //        command.ExecuteNonQuery();
-            //        i++;
-            //    }
-
-            //    tr.Commit();
-            //}
-
-            //m_db.Close();
-            //m_db.Dispose();
+          
         }
 
         void ShowData(long[] XrayData, Dictionary<string, double> listElement)

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä