Example #1
0
        /// <summary>
        ///     The section of the user process.
        ///     用户自定义流程函数。
        ///     Please write your process in the following method.
        ///     请在以下函数中定义您的工艺流程。
        /// </summary>
        /// <param name="Apas"></param>
        /// <returns></returns>
        private static void UserProc(SystemServiceClient Apas, CamRemoteAccessContractClient Camera = null,
                                     Options opts = null)
        {
            try
            {
                Apas.__SSC_LogInfo($"目标功率:{opts.PowerThreTerminate:F2}dBm");

                var sw      = new Stopwatch();
                var swTotal = new Stopwatch();
                swTotal.Start();

                // 初始化功率计状态
                Apas.__SSC_LogInfo("初始化光功率计...");
                Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);
                Apas.__SSC_Powermeter_SetUnit(opts.PowerMeterCaption, SSC_PMUnitEnum.dBm);

                // 等待功率计稳定
                Thread.Sleep(500);


                // 读取初始功率
                var power = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                Apas.__SSC_LogInfo($"初始光 {power:F2}dBm");


                // STEP 1: RECT Area Scan
                if (power < -25)
                {
                    if (opts.IgnoreBlindSearch == false)
                    {
                        sw.Restart();

                        Step1(Apas, opts);

                        sw.Stop();
                        Apas.__SSC_LogInfo($"耗时: {sw.Elapsed.TotalSeconds:F1}s");
                    }
                    else
                    {
                        Apas.__SSC_LogWarn($"忽略BlindSearch,当前功率:{power:F2}dBm");
                    }
                }


                // Step 2: Fast Focus Scan
                if (power < 0)
                {
                    if (opts.IgnoreFastFocusScan == false)
                    {
                        sw.Restart();

                        Step2(Apas, opts);

                        sw.Stop();
                        Apas.__SSC_LogInfo($"耗时: {sw.Elapsed.TotalSeconds:F1}s");
                    }
                    else
                    {
                        Apas.__SSC_LogWarn($"忽略快速焦距扫描,,当前功率:{power:F2}dBm");
                    }
                }

                // STEP 3: Profile ND to fine-tune.

                // 等待功率计稳定
                Thread.Sleep(500);
                power = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                if (opts.IgnoreLensProfileScan == false && power < opts.PowerThreTerminate)
                {
                    sw.Restart();

                    Step3(Apas, opts);

                    sw.Stop();
                    Apas.__SSC_LogInfo($"耗时: {sw.Elapsed.TotalSeconds:F1}s");
                }
                else
                {
                    Apas.__SSC_LogWarn($"忽略Lens线性Profile扫描,,当前功率:{power:F2}dBm");
                }

                // STEP 4: 双边耦合
                // 等待功率计稳定
                Thread.Sleep(500);
                power = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                if (opts.IgnoreReceptLensDualScan == false && power < opts.PowerThreTerminate)
                {
                    sw.Restart();

                    Step4(Apas, opts);

                    sw.Stop();
                    Apas.__SSC_LogInfo($"耗时: {sw.Elapsed.TotalSeconds:F1}s");
                }
                else
                {
                    Apas.__SSC_LogWarn($"忽略Receptacle-Lens双边扫描,,当前功率:{power:F2}dBm");
                }


                // STEP 5: 最终位置优化
                // 等待功率计稳定
                Thread.Sleep(500);
                power = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                if (opts.IgnoreFinalFineTune == false && power < opts.PowerThreTerminate)
                {
                    sw.Restart();

                    Step5(Apas, opts);

                    sw.Stop();
                    Apas.__SSC_LogInfo($"耗时: {sw.Elapsed.TotalSeconds:F1}s");
                }
                else
                {
                    Apas.__SSC_LogWarn($"忽略最终微调,,当前功率:{power:F2}dBm");
                }

                swTotal.Stop();
                Apas.__SSC_LogInfo($"总耗时: {swTotal.Elapsed.TotalSeconds:F1}s");


                // 检查光功率是否达标
                Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);
                Thread.Sleep(500);

                power = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                Apas.__SSC_LogInfo($"最终光功率为 {power:F2}dBm");

                if (TARGET_POWER_MIN_DBM <= power)
                {
                    Apas.__SSC_LogInfo("脚本运行完成");
                }
                else
                {
                    var msg = $"无法耦合到目标功率 {TARGET_POWER_MIN_DBM}dBm";
                    Apas.__SSC_LogError(msg);
                    throw new Exception(msg);
                }
            }
            catch (Exception ex)
            {
                //Apas.__SSC_LogError(ex.Message);
                throw new Exception(ex.Message);
            }

            // Thread.Sleep(100);
        }