Example #1
0
        public ServiceCallback <byte[]> SendAppMsg(AppInfo app, byte[] data, AppMsgRecipient recipient)
        {
            return(new ServiceCallback <byte[]>(() =>
            {
                MainMessage mainMsg = new MainMessage();
                mainMsg.AppMsg = new AppMsg();
                mainMsg.AppMsg.AppId = app.ID;
                mainMsg.AppMsg.Data = ByteString.CopyFrom(data);
                MainMessage response = null;
                switch (recipient)
                {
                case AppMsgRecipient.FORWARDER:
                    response = _api.OpenAPI.Networking.Send(mainMsg, _api.Services.Room.ForwarderAddress);
                    break;

                case AppMsgRecipient.PROVIDER:
                    response = _api.OpenAPI.Networking.Send(mainMsg, _api.OpenAPI.Config.MainServer);
                    break;
                }
                if (response == null)
                {
                    throw new AppServiceException("Unknown response.");
                }
                if (SystemServiceClient.IsErrorMsg(response))
                {
                    throw new AppServiceException(response.SystemMsg.ErrorMsg.ErrorMsg_);
                }
                AppMsg appMsg = response.AppMsg;
                if (appMsg == null)
                {
                    throw new AppServiceException("Unknown response.");
                }
                return appMsg.Data.ToByteArray();
            }));
        }
Example #2
0
        private static void Main(string[] args)
        {
            var client = new SystemServiceClient();

            try
            {
                var response = new GetAllTaskControllersResponse();

                client.GetAllTaskControllers(new MetaRequest(), new GetAllTaskControllersRequest(), out response);

                foreach (var muleTask in response.TaskControllers)
                {
                    if (!muleTask.IsOnlinek__BackingField || muleTask.IsSuspendedk__BackingField)
                    {
                        SendEmailToUsers(muleTask);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                SendNotificationEmail(
                    string.Format(
                        "Unable to reach Turniverse mule server: {0}, please check and restart all three mule services.",
                        client.Endpoint.ListenUri));
            }
        }
Example #3
0
        static SingleAxisInfo GenerateSingleAxisInfo(SystemServiceClient Service, string aliger, string axisname, int speed = 100, int rank = 1)
        {
            axisname = axisname.ToUpper();
            double positon = Service.__SSC_GetAbsPosition(aliger, axisname);

            return(new SingleAxisInfo(axisname, positon, speed, rank));
        }
Example #4
0
        static void MoveToPosition(SystemServiceClient Service, string pName)
        {
            string filepath = programDataFile + $"\\{pName}.json";

            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException($"{ pName }.json is not found");
            }
            string    data      = File.ReadAllText(filepath);
            PointInfo pointInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <PointInfo>(data);

            int maxRank = pointInfo.AxisInfos.Last().Rank;

            for (int i = 0; i < maxRank; i++)
            {
                List <Task> tasks = new List <Task>();
                foreach (var mem in pointInfo.AxisInfos)
                {
                    if (mem.Rank == i + 1)
                    {
                        var m = Service.__SSC_MoveAxisAsync(pointInfo.Aliger, mem.AxisName, SSC_MoveMode.ABS, mem.Speed, mem.Position);
                        // Task t = new Task(() => { Service.__SSC_MoveAxisAsync(pointInfo.Aliger, mem.AxisName, SSC_MoveMode.ABS, mem.Speed, mem.Position); });
                        //   t.Start();

                        tasks.Add(m);
                    }
                }

                Task.WaitAll(tasks.ToArray());
            }
        }
Example #5
0
        private static void Main(string[] args)
        {
            try
            {
                // connect to the APAS.
                var client = new SystemServiceClient();
                client.Open();

                var helpText = new StringBuilder();
                var stream   = new StringWriter(helpText);
                var parser   = new Parser(config =>
                {
                    config.EnableDashDash = true;
                    config.CaseSensitive  = false;
                    config.HelpWriter     = stream;
                });

                parser.ParseArguments <Option>(args)
                .MapResult(
                    (Option opts) =>
                {
                    UserProc(client, opts: opts);
                    return(0);
                },
                    errs =>
                {
                    var erring = "";

                    if (errs.IsHelp() || errs.IsVersion())
                    {
                        erring = "";
                    }
                    else
                    {
                        erring = "脚本启动参数错误。\r\n";
                    }

                    client.__SSC_LogError(erring + helpText.ToString());
                    throw new Exception(erring + helpText.ToString());
                });
            }
            catch (AggregateException ae)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.BackgroundColor = ConsoleColor.Red;

                var ex = ae.Flatten();

                ex.InnerExceptions.ToList().ForEach(e =>
                {
                    Console.WriteLine($"Error occurred, {e.Message}");
                });

                Console.ResetColor();
            }
            //Console.WriteLine("Press any key to exit.");

            //Console.ReadKey();
        }
Example #6
0
 public SystemControlClient(IApplicationPropertiesWrapper appPropertiesWrapper)
 {
     if (appPropertiesWrapper == null)
     {
         throw new ArgumentNullException("appPropertiesWrapper");
     }
     _appPropertiesWrapper = appPropertiesWrapper;
     _systemServiceCient   = new SystemServiceClient(SystemServiceClient.EndpointConfiguration.BasicHttpBinding_ISystemService);
 }
Example #7
0
        private static void PerformAlignment(SystemServiceClient Service, Func <string, object>[] AlignmentHandlers,
                                             Options opts, string[] Profiles, SSC_PMRangeEnum PMRange, double BreakPowerDiff_dBm,
                                             double BreakPowerMax_dBm = double.MaxValue, int MaxCycle = 5)
        {
            if (AlignmentHandlers.Length != Profiles.Length)
            {
                throw new Exception("Handler和Profile的数量不一致。");
            }

            var cycle     = 0;
            var currPower = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);
            var lastPower = currPower;

            while (true)
            {
                Service.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, PMRange);

                Thread.Sleep(200);

                for (var i = 0; i < AlignmentHandlers.Length; i++)
                {
                    AlignmentHandlers[i](Profiles[i]);
                }

                Thread.Sleep(200);

                // 计算耦合后和耦合前的功率差值
                currPower = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                var diffPower = currPower - lastPower;
                lastPower = currPower;

                if (double.IsNaN(BreakPowerDiff_dBm) == false)
                {
                    if (diffPower <= BreakPowerDiff_dBm || currPower >= BreakPowerMax_dBm)
                    {
                        // if the delta power is less than 2dB, jump out of the loop.
                        break;
                    }

                    cycle++;
                    if (cycle > MaxCycle)
                    {
                        throw new Exception("初始光太小。");
                    }
                }
                else
                {
                    break;
                }
            }

            // wait until the powermeter is stable.
            Thread.Sleep(500);
        }
Example #8
0
        protected override void SetupServiceClient()
        {
            var ipAddress = new ConnectionChecker().GetServerAddress();

            var binding = new NetTcpBinding(SecurityMode.None);

            binding.Security.Message.ClientCredentialType   = MessageCredentialType.None;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;

            Client = new SystemServiceClient(binding, new EndpointAddress("net.tcp://" + ipAddress + ":8749/PiFormance/"));
            // Client = new SystemServiceClient(binding, new EndpointAddress("net.tcp://localhost:8749/PiFormance/"));
            Connect();
        }
Example #9
0
        /// <summary>
        /// Lens慢速线性扫描
        /// </summary>
        /// <param name="Service"></param>
        /// <param name="opts"></param>
        private static void Step3(SystemServiceClient Service, Options opts)
        {
            var cycle = 0;

            Service.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);

            Thread.Sleep(500);

            Service.__SSC_LogInfo("开始执行线性扫描....");

            while (true)
            {
                // PowerMeterAutoRange(Service, PM_CAPTION);

                var pBeforeAlign = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);

                if (opts.UseHillClimbInLensAlign)
                {
                    Service.__SSC_DoHillClimb(opts.ProfileNameLineScanLens);
                }
                else
                {
                    Service.__SSC_DoProfileND(opts.ProfileNameLineScanLens);
                }

                Thread.Sleep(500);

                var pAfterAlign = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                Service.__SSC_LogInfo($"光功率:{pAfterAlign:F2}dBm");

                var powerDiff = pAfterAlign - pBeforeAlign;
                Service.__SSC_LogInfo($"Power Diff: {powerDiff:F2}dB, {pAfterAlign:F2}dBm/{pBeforeAlign:F2}dBm");

                //if (power > 0 && (powerDiff > -0.2 && powerDiff < 0.2))
                if (powerDiff > opts.PowerThreLineScanN && powerDiff < opts.PowerThreLineScanP)
                {
                    break;
                }
                if (pAfterAlign >= opts.PowerThreTerminate)
                {
                    break;
                }

                cycle++;

                if (cycle > 10)
                {
                    throw new Exception("慢速扫描执行失败,无法找到稳定光功率。");
                }
            }
        }
Example #10
0
        ///  <summary>
        ///  The section of the user process 2.
        /// 用户函数2,当命令行启动参数中的命令为Command2时,执行此函数。
        ///
        ///  Please write your process in the following method.
        ///  请在以下函数中定义您的工艺流程。
        ///
        ///  </summary>
        /// <param name="apas">APAS主程序Service</param>
        /// <param name="camera">相机程序Service</param>
        /// <param name="opts">启动参数</param>
        ///  <returns></returns>
        private static void UserProc2(SystemServiceClient apas, CamRemoteAccessContractClient camera = null, Command2 opts = null)
        {
            try
            {
                #region 请在这里编写实际的用户脚本


                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <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)
        {
            if (string.IsNullOrEmpty(PARAM) || PARAM.ToUpper() != "ON" && PARAM.ToUpper() != "OFF")
            {
                var err = "参数错误,请输入参数[ON]或[OFF]。";
                Apas.__SSC_LogError(err);
                throw new Exception(err);
            }

            if (PARAM == "ON")
            {
                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 3");

                Thread.Sleep(500);

                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 2");
                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 1");

                Thread.Sleep(2000);

                // 检查VCC1和VCC3电流
                var ICC1 = Apas.__SSC_MeasurableDevice_Read(DP800_READ_CURR_CH1);
                var ICC3 = Apas.__SSC_MeasurableDevice_Read(DP800_READ_CURR_CH3);

                if (ICC1 >= 0.04 && ICC3 >= 0.008)
                {
                }
                else
                {
                    var err = "ICC1或ICC3未达到指定值。";
                    throw new Exception(err);
                }
            }
            else
            {
                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 1");
                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 2");


                Thread.Sleep(500);

                Apas.__SSC_EquipmentPluginControl(DP800_CAPTION, $"{PARAM} 3");
            }
        }
Example #12
0
        /// <summary>
        /// 执行爬山算法微调
        /// </summary>
        /// <param name="Apas"></param>
        /// <param name="opts"></param>
        private static void Step5(SystemServiceClient Apas, Options opts)
        {
            Apas.__SSC_LogInfo("开始执行最终位置优化...");

            try
            {
                Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);
                if (opts.UseHillClimbInFinalFineTune)
                {
                    Apas.__SSC_DoHillClimb(opts.ProfileNameFinalFineTune);
                }
                else
                {
                    Apas.__SSC_DoProfileND(opts.ProfileNameFinalFineTune);
                }
            }
            catch (Exception)
            {
            }
        }
        static void Main(string[] args)
        {
            // Camera Remote Access Service.
            var camClient = new CamRAC.CamRemoteAccessContractClient();

            // APAS Remote Access Service.
            var client = new SystemServiceClient();

            try
            {
                client.Open();

                client.__SSC_Connect();

                // perform the user process.
                UserProc(client, camClient);

                client.__SSC_Disonnect();
            }
            catch (AggregateException ae)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.BackgroundColor = ConsoleColor.Red;

                var ex = ae.Flatten();

                ex.InnerExceptions.ToList().ForEach(e =>
                {
                    Console.WriteLine($"Error occurred, {e.Message}");
                });

                Console.ResetColor();
            }
            finally
            {
                client.Close();
            }
            //Console.WriteLine("Press any key to exit.");

            //Console.ReadKey();
        }
Example #14
0
        static void GetAwgVerticalHeight(SystemServiceClient service, HObject _image)
        {
            double rRow          = 941;
            double rColumn       = 601;
            double rPhi          = -1.57;
            double rLength1      = 75;
            double rLength2      = 383;
            HTuple minScaleValue = 130;
            HTuple maxScaleValue = 190;

            visionFun.scale_image_range(_image, out HObject scaleImage, minScaleValue, maxScaleValue);
            visionFun.findline(scaleImage, out HObject line, rRow, rColumn, rPhi, rLength1, rLength2, "nearest_neighbor", 1.5, 30, "positive", "first");
            HOperatorSet.AreaCenter(line, out HTuple area, out HTuple row, out HTuple column);
            HOperatorSet.GetRegionPoints(line, out HTuple rows, out HTuple columns);
            visionFun.HObject2Bpp8(_image, out Bitmap bitmap);
            var rtnImage = BitMapZd.DrawLine(bitmap, columns[0], rows[0], columns[columns.Length - 1], rows[rows.Length - 1], 40, Color.LightGreen);

            service.__SSC_ShowImage(rtnImage);
            bitmap.Dispose();
            Console.WriteLine($"the awg height is  {row.D},");
            Console.WriteLine($"the awg vertical offset is  {row.D-954},");
        }
Example #15
0
        /// <summary>
        /// The section of the user process.
        /// 用户自定义流程函数。
        ///
        /// Please write your process in the following method.
        /// 请在以下函数中定义您的工艺流程。
        ///
        /// </summary>
        /// <param name="Service"></param>
        /// <returns></returns>
        static void BenchMarkSet(SystemServiceClient Service, CamRemoteAccessContractClient Camera = null)
        {
            string message = "";


            double pdX = 0, pdY = 0, pdAngle = 0;
            double offsetX, offsetY, offsetAngle;

            Camera.SetExposure("AWG", 30000);
            Camera.SetExposure("Left", 16000);


            try
            {
                if (!Directory.Exists(programDataFile))
                {
                    Directory.CreateDirectory(programDataFile);
                }

                if (!File.Exists(programDataFile + "\\calibratedata.tup"))
                {
                    throw new Exception("cannot find the calibratedata  file");
                }

                if (!File.Exists(programDataFile + "\\Model"))
                {
                    throw new Exception("cannot find the  model file");
                }

                HOperatorSet.ReadTuple(programDataFile + "\\calibratedata.tup", out calibratedata);
                HOperatorSet.ReadShapeModel(programDataFile + "\\Model", out HTuple model);

                PointInfo pdOriginAngle = new PointInfo();
                pdOriginAngle.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "R"));
                pdOriginAngle.Aliger    = Aliger;
                pdOriginAngle.PointName = "pd初始角度";
                pdOriginAngle.Save(programDataFile, "pd初始角度.json");

                PointInfo awgCouplingLower = new PointInfo();
                awgCouplingLower.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Z", 20));
                awgCouplingLower.Aliger    = Aliger;
                awgCouplingLower.PointName = "Awg耦合低位";
                awgCouplingLower.Save(programDataFile, "Awg耦合低位.json");

                Service.__SSC_MoveAxis(Aliger, "Z", SSC_MoveMode.REL, 100, -500);

                PointInfo awgCouplingHigher = new PointInfo();
                awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "X"));
                awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Y"));
                awgCouplingHigher.AxisInfos.Add(GenerateSingleAxisInfo(Service, Aliger, "Z", 100, 2));
                awgCouplingHigher.Aliger    = Aliger;
                awgCouplingHigher.PointName = "Awg耦合高位";
                awgCouplingHigher.Save(programDataFile, "Awg耦合高位.json");



                #region  pd初始位置获取并保存
                Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "pd拍照位置");
                var     image2 = Camera.GrabOneFrame("Left");
                HObject pdImage;
                visionFun.Bitmap2HObjectBpp32(image2, out pdImage);
                GetPdOriginPosition(pdImage, out double pdx, out double pdy, out double pdangle, out Bitmap pdresultImage);
                Service.__SSC_ShowImage(pdresultImage);
                HTuple PdOrigin = new HTuple();
                PdOrigin.Append(pdx);
                PdOrigin.Append(pdy);
                PdOrigin.Append(pdangle);
                HOperatorSet.WriteTuple(PdOrigin, programDataFile + "\\PdOrigin.tup");

                #endregion


                #region awg初始位置获取并保存
                Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "awg拍照位置");
                Thread.Sleep(100);
                var     image1 = Camera.GrabOneFrame("AWG");
                HObject awgImage;
                visionFun.Bitmap2HObjectBpp32(image1, out awgImage);
                GetAwgOriginPosition(awgImage, out double awgX, out double awgY, out double awgAngle, out Bitmap awgimage);
                Service.__SSC_ShowImage(awgimage);
                HTuple AwgOrigin = new HTuple();
                AwgOrigin.Append(awgX);
                AwgOrigin.Append(awgY);
                AwgOrigin.Append(awgAngle);
                HOperatorSet.WriteTuple(AwgOrigin, programDataFile + "\\AwgOrigin.tup");
                #endregion
            }
            catch (Exception ex)
            {
                Service.__SSC_LogError(ex.Message);
            }

            System.Threading.Thread.Sleep(100);
        }
Example #16
0
 public SystemAPI(SystemServiceClient systemService)
 {
     this._systemService = systemService;
 }
Example #17
0
        /// <summary>
        ///     Fast Focus Scan.
        /// </summary>
        /// <param name="Service"></param>
        private static void Step2(SystemServiceClient Service, Options opts)
        {
            var    powerZHistory = new List <PointF>();
            var    powerXYHistory = new Queue <double>();
            var    cycle = 0;
            double zMoved = 0, nextZMoveStep = opts.FocusScanStep;

            Service.__SSC_LogInfo("开始执行快速扫描....");

            var range      = SSC_PMRangeEnum.RANGE3;
            var originZPos = Service.__SSC_GetAbsPosition(LMC_LENS, LMC_LENS_AXIS_Z);
            var power      = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);

            while (true)
            {
                #region XY Scan

                powerXYHistory.Clear();
                cycle = 0;
                while (true)
                {
                    // XY Scan
                    PerformAlignment(Service,
                                     new Func <string, object>[] { Service.__SSC_DoFastND, Service.__SSC_DoFastND },
                                     opts,
                                     new[] { opts.ProfileNameFocusScanLens, opts.ProfileNameFocusScanRecept },
                                     range, 0.2, power, 10);

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

                    if (power > opts.PowerThreFocusScan)
                    {
                        Service.__SSC_LogInfo("功率达到阈值,耦合结束。");
                        return;
                    }

                    powerXYHistory.Enqueue(power);
                    if (powerXYHistory.Count > 5)
                    {
                        powerXYHistory.Dequeue();
                    }

                    if (powerXYHistory.Count > 2)
                    {
                        DataAnalysis.CheckSlope(powerXYHistory.ToArray(), out var trend);
                        Service.__SSC_LogInfo($"功率变化趋势:{trend}");

                        if (trend == DataAnalysis.SlopeTrendEnum.Ripple)
                        {
                            break;
                        }
                    }

                    cycle++;

                    if (cycle > 20)
                    {
                        // throw new Exception("快速扫描失败,无法找到稳定光功率。");
                        break;
                    }
                }

                #endregion

                power = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                var currZPos = Service.__SSC_GetAbsPosition(LMC_LENS, LMC_LENS_AXIS_Z);
                Service.__SSC_LogInfo($"XY平面功率: {currZPos - originZPos:F4}um, {power:F2}dBm");

                if (power > 0) // exit if the power > 0dBm
                {
                    break;
                }

                powerZHistory.Add(new PointF((float)currZPos, (float)power));

                if (powerZHistory.Count >= 2)
                {
                    power = powerZHistory[powerZHistory.Count - 1].Y;
                    var lastlastPower = powerZHistory[powerZHistory.Count - 2].Y;
                    var diff          = power - lastlastPower;
                    Service.__SSC_LogInfo($"功率差: {diff:F2}dBm/{power:F2}dBm/{lastlastPower:F2}dBm");
                    if (diff < -1)
                    {
                        Service.__SSC_LogInfo("功率降低,开始反向搜索...");
                        nextZMoveStep *= -1;
                        nextZMoveStep /= 2;

                        if (Math.Abs(nextZMoveStep) < opts.FocusScanFinalStep)
                        {
                            Service.__SSC_LogInfo("搜索步进收敛至最小,结束搜索!");
                            break;
                        }
                    }
                }

                Service.__SSC_MoveAxis(LMC_LENS, LMC_LENS_AXIS_Z, SSC_MoveMode.REL, 20, nextZMoveStep);

                // accum the total distance of the Z axis moved,
                // be sure it never move out of the RANGE.
                zMoved += nextZMoveStep;
                if (zMoved > opts.FocusScanRange)
                {
                    Service.__SSC_LogWarn("焦点扫描Z轴范围达到最大值。");
                    break;
                }
            }
        }
Example #18
0
        private static void Main(string[] args)
        {
            var errText           = "";
            var isExceptionThrown = false;
            var wcfClient         = new SystemServiceClient();

            try
            {
                // client.Open();
                wcfClient.__SSC_Connect();

                // print the script version
                wcfClient.__SSC_LogInfo($"Script Version: v{Assembly.GetExecutingAssembly().GetName().Version}");

                var helpWriter = new StringWriter();
                var parser     = new Parser(with => with.HelpWriter = helpWriter);

                var parserResult = parser.ParseArguments <Options>(args);
                parserResult.WithParsed(opts =>
                {
                    // perform the user process.
                    UserProc(wcfClient, opts: opts);
                })
                .WithNotParsed(errs =>
                {
                    DisplayHelp(errs, helpWriter);

                    var err = "解析启动参数错误。";
                    wcfClient.__SSC_LogError(err);
                    throw new Exception(err);
                });


                wcfClient.__SSC_Disconnect();
            }
            catch (AggregateException ae)
            {
                var ex = ae.Flatten();
                ex.InnerExceptions.ToList().ForEach(e =>
                {
                    errText = ex.Message;
                    Console.Error.WriteLine(errText);
                });
                isExceptionThrown = true;
            }
            catch (TimeoutException timeProblem)
            {
                errText = "The service operation timed out. " + timeProblem.Message;
                Console.Error.WriteLine(errText);
            }
            // Catch unrecognized faults. This handler receives exceptions thrown by WCF
            // services when ServiceDebugBehavior.IncludeExceptionDetailInFaults
            // is set to true.
            catch (FaultException faultEx)
            {
                errText = "An unknown exception was received. "
                          + faultEx.Message
                          + faultEx.StackTrace;
                Console.Error.WriteLine(errText);
            }
            // Standard communication fault handler.
            catch (CommunicationException commProblem)
            {
                errText = "There was a communication problem. " + commProblem.Message + commProblem.StackTrace;
                Console.Error.WriteLine(errText);
            }
            catch (Exception ex)
            {
                errText = ex.Message;
                Console.Error.WriteLine(errText);
                isExceptionThrown = true;
            }
            finally
            {
                wcfClient.Abort();
                if (isExceptionThrown)
                {
                    // try to output the error message to the log.
                    try
                    {
                        using (wcfClient = new SystemServiceClient())
                        {
                            wcfClient.__SSC_LogError(errText);
                            wcfClient.Abort();
                        }
                    }
                    catch (Exception)
                    {
                        // ignore
                    }


                    Environment.ExitCode = -1;
                }
            }
        }
        private void Init()
        {
            try
            {
                camClient = new CamRAC.CamRemoteAccessContractClient();
                service   = new SystemServiceClient();
                camClient.SetExposure("AWG", 30000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "CalibrateData"))
            {
                HTuple cameraX = new HTuple();
                HTuple cameraY = new HTuple();
                HTuple robotX  = new HTuple();
                HTuple robotY  = new HTuple();
                string _path   = AppDomain.CurrentDomain.BaseDirectory + "CalibrateData";

                HOperatorSet.ReadTuple(_path + "\\cameraX.tup", out cameraX);
                HOperatorSet.ReadTuple(_path + "\\cameraY.tup", out cameraY);
                HOperatorSet.ReadTuple(_path + "\\robotX.tup", out robotX);
                HOperatorSet.ReadTuple(_path + "\\robotY.tup", out robotY);

                for (int i = 0; i < 9; i++)
                {
                    DataGridViewRow dataGridViewRow = new DataGridViewRow();
                    dataGridViewRow.CreateCells(dGV_machinePoint);
                    dataGridViewRow.Cells[0].Value = (i + 1).ToString();
                    dataGridViewRow.Cells[1].Value = robotX[i].S;
                    dataGridViewRow.Cells[2].Value = robotY[i].S;
                    dGV_machinePoint.Rows.Add(dataGridViewRow);
                }
                for (int i = 0; i < 9; i++)
                {
                    DataGridViewRow dataGridViewRow = new DataGridViewRow();
                    dataGridViewRow.CreateCells(dGV_pixelPoint);
                    dataGridViewRow.Cells[0].Value = (i + 1).ToString();
                    dataGridViewRow.Cells[1].Value = cameraX[i].S;
                    dataGridViewRow.Cells[2].Value = cameraY[i].S;
                    dGV_pixelPoint.Rows.Add(dataGridViewRow);
                }
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    DataGridViewRow dataGridViewRow = new DataGridViewRow();
                    dataGridViewRow.CreateCells(dGV_machinePoint);
                    dataGridViewRow.Cells[0].Value = (i + 1).ToString();

                    dGV_machinePoint.Rows.Add(dataGridViewRow);
                }
                for (int i = 0; i < 9; i++)
                {
                    DataGridViewRow dataGridViewRow = new DataGridViewRow();
                    dataGridViewRow.CreateCells(dGV_pixelPoint);
                    dataGridViewRow.Cells[0].Value = (i + 1).ToString();

                    dGV_pixelPoint.Rows.Add(dataGridViewRow);
                }
            }
        }
Example #20
0
 public SystemServiceClient() :
     base(SystemServiceClient.GetDefaultBinding(), SystemServiceClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.NetTcpBinding_ISystemService.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #21
0
 public SystemServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(SystemServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #22
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(SystemServiceClient.GetBindingForEndpoint(EndpointConfiguration.NetTcpBinding_ISystemService));
 }
Example #23
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(SystemServiceClient.GetEndpointAddress(EndpointConfiguration.NetTcpBinding_ISystemService));
 }
Example #24
0
        /// <summary>
        /// Receptacle和准直Lens同时调整。
        /// </summary>
        /// <param name="Apas"></param>
        private static void Step4(SystemServiceClient Apas, Options opts)
        {
            var cycle = 0;

            Apas.__SSC_LogInfo("开始Rept和准直Lens双边调整...");

            Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);

            while (true)
            {
                var pBeforeAlign = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);

                #region 调整Receptacle

                if (opts.UseProfileNdInReceptLensDualScan == false)
                {
                    Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.RANGE4);
                    Apas.__SSC_DoFastND(opts.ProfileNameDualLineScanRecept);
                }
                else
                {
                    Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);
                    Apas.__SSC_DoProfileND(opts.ProfileNameDualLineScanRecept);
                }

                #endregion

                Thread.Sleep(200);

                #region 调整Lens

                Apas.__SSC_Powermeter_SetRange(opts.PowerMeterCaption, SSC_PMRangeEnum.AUTO);
                if (opts.UseHillClimbInLensAlign)
                {
                    Apas.__SSC_DoHillClimb(opts.ProfileNameDualLineScanLens);
                }
                else
                {
                    Apas.__SSC_DoProfileND(opts.ProfileNameDualLineScanLens);
                }
                #endregion

                Thread.Sleep(500);

                var pAfterAlign = Apas.__SSC_Powermeter_Read(opts.PowerMeterCaption);
                var pDiff       = pAfterAlign - pBeforeAlign;

                Apas.__SSC_LogInfo($"Power Diff: {pDiff:F2}dB, {pAfterAlign:F2}dBm, {pBeforeAlign:F2}dBm");

                //if (power > 3.5 && (powerDiff > -0.2 && powerDiff < 0.2))
                if (pDiff > opts.PowerThreDualLineScanN && pDiff < opts.PowerThreDualLineScanP)
                {
                    break;
                }
                if (pAfterAlign >= opts.PowerThreTerminate)
                {
                    break;
                }
                if (pDiff < -0.3)
                {
                    break;               // 如果耦合功率开始变小超过-0.3dBm,则停止扫描
                }
                cycle++;

                if (cycle > 10)
                {
                    var msg = "无法调整稳定功率位置。";
                    Apas.__SSC_LogError(msg);
                    throw new Exception(msg);
                }
            }
        }
Example #25
0
 public SystemServiceClient(EndpointConfiguration endpointConfiguration) :
     base(SystemServiceClient.GetBindingForEndpoint(endpointConfiguration), SystemServiceClient.GetEndpointAddress(endpointConfiguration))
 {
 }
Example #26
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);
        }
        private static void Main(string[] args)
        {
            var isExceptionThrown = false;
            var errText           = "";
            var wcfClient         = new SystemServiceClient();

            try
            {
                wcfClient.Open();
                wcfClient.__SSC_Connect();

                // print the script version
                wcfClient.__SSC_LogInfo($"Script Version: v{Assembly.GetExecutingAssembly().GetName()}");

                var helpWriter = new StringWriter();
                var parser     = new Parser(with =>
                {
                    with.CaseSensitive  = false;
                    with.EnableDashDash = true;
                    with.HelpWriter     = helpWriter;
                });

                parser.ParseArguments <TurnOnOptions, TurnOffOptions>(args)
                .MapResult(
                    (TurnOnOptions opts) =>
                {
                    TurnOn(wcfClient, opts.Channel, opts.IBias);
                    return(0);
                },
                    (TurnOffOptions opts) =>
                {
                    TurnOff(wcfClient, opts.Channel);
                    return(0);
                },
                    errs =>
                {
                    var myErr = "";
                    if (errs.IsHelp() || errs.IsVersion())
                    {
                        myErr = helpWriter.ToString();
                    }
                    else
                    {
                        myErr = $"启动参数错误。\r\n{helpWriter}";
                    }

                    throw new Exception(myErr);
                });

                wcfClient.__SSC_Disconnect();
            }
            catch (AggregateException ae)
            {
                var ex = ae.Flatten();
                ex.InnerExceptions.ToList().ForEach(e =>
                {
                    errText = ex.Message;
                    Console.Error.WriteLine(errText);
                });
                isExceptionThrown = true;
            }
            catch (TimeoutException timeProblem)
            {
                errText = "The service operation timed out. " + timeProblem.Message;
                Console.Error.WriteLine(errText);
            }
            // Catch unrecognized faults. This handler receives exceptions thrown by WCF
            // services when ServiceDebugBehavior.IncludeExceptionDetailInFaults
            // is set to true.
            catch (FaultException faultEx)
            {
                errText = "An unknown exception was received. "
                          + faultEx.Message
                          + faultEx.StackTrace;
                Console.Error.WriteLine(errText);
            }
            // Standard communication fault handler.
            catch (CommunicationException commProblem)
            {
                errText = "There was a communication problem. " + commProblem.Message + commProblem.StackTrace;
                Console.Error.WriteLine(errText);
            }
            catch (Exception ex)
            {
                errText = ex.Message;
                Console.Error.WriteLine(errText);
                isExceptionThrown = true;
            }
            finally
            {
                wcfClient.Abort();
                if (isExceptionThrown)
                {
                    // try to output the error message to the log.
                    try
                    {
                        using (wcfClient = new SystemServiceClient())
                        {
                            wcfClient.__SSC_LogError(errText);
                            wcfClient.Abort();
                        }
                    }
                    catch (Exception)
                    {
                        // ignore
                    }


                    Environment.ExitCode = -1;
                }
            }
        }
Example #28
0
 public SystemServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(SystemServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
 }
Example #29
0
        static HTuple model;         //模板数据
        #endregion

        #region User Process

        /// <summary>
        /// The section of the user process.
        /// 用户自定义流程函数。
        ///
        /// Please write your process in the following method.
        /// 请在以下函数中定义您的工艺流程。
        ///
        /// </summary>
        /// <param name="Service"></param>
        /// <returns></returns>
        static void UserProc(SystemServiceClient Service, CamRemoteAccessContractClient Camera = null)
        {
            string message          = "";
            int    cycles           = 0;
            bool   goodAlign        = false;
            string alignmentProfile = "";

            double awgX = 0, awgY = 0, awgAngle = 0;
            double pdX = 0, pdY = 0, pdAngle = 0;
            double offsetX, offsetY, offsetAngle;

            Camera.SetExposure("AWG", 30000);
            Camera.SetExposure("Left", 16000);
            Init();

            try
            {
                // 抬起针筒
                Service.__SSC_WriteIO(Conditions.IO_INJECTOR, SSC_IOStatusEnum.Disabled);

                // 识别AWG角度
                Service.__SSC_LogInfo("移动到AWG角度识别位置...");
                Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "awg拍照位置");

                MoveToPosition(Service, "pd初始角度");
                // Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "pd初始角度");
                Thread.Sleep(100);

                Service.__SSC_LogInfo("识别AWG角度...");
                var image1 = Camera.GrabOneFrame("AWG");

                HObject awgImage;

                visionFun.Bitmap2HObjectBpp32(image1, out awgImage);
                GetAwgOffset(awgImage, ref awgX, ref awgY, ref awgAngle, out Bitmap awgimage);
                Service.__SSC_ShowImage(awgimage);
                awgImage.Dispose();
                awgimage.Dispose();
                awgImage = null;
                awgimage = null;

                Service.__SSC_MoveAxis(Conditions.ALIGNER, "R", SSC_MoveMode.REL, 100, -awgAngle);
                Thread.Sleep(100);

                // 识别PD Array角度
                Service.__SSC_LogInfo("移动到PD Array角度识别位置...");
                Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "pd拍照位置");
                Thread.Sleep(100);
                Service.__SSC_LogInfo("识别PA Array角度...");
                var image2 = Camera.GrabOneFrame("Left");

                HObject pdImage;

                visionFun.Bitmap2HObjectBpp32(image2, out pdImage);
                GetPdOffset(pdImage, ref pdX, ref pdY, ref pdAngle, out Bitmap pdimage);
                Service.__SSC_ShowImage(pdimage);
                pdImage.Dispose();
                pdimage.Dispose();
                pdImage = null;
                pdimage = null;

                offsetX = -awgX - pdX;
                offsetY = -awgY - pdY;

                Service.__SSC_LogInfo($"x 方向总偏移量 {offsetX}");
                Service.__SSC_LogInfo($"y 方向总偏移量 {offsetY}");

                MoveToPosition(Service, "Awg耦合高位");
                // Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "耦合高位");
                Thread.Sleep(100);


                Service.__SSC_MoveAxis(Conditions.ALIGNER, "X", SSC_MoveMode.REL, 100, -awgX);
                Thread.Sleep(100);

                Service.__SSC_MoveAxis(Conditions.ALIGNER, "X", SSC_MoveMode.REL, 100, -pdX);
                Thread.Sleep(100);


                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Y", SSC_MoveMode.REL, 100, -awgY);
                Thread.Sleep(100);

                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Y", SSC_MoveMode.REL, 100, -pdY);
                Thread.Sleep(100);

                var image3 = Camera.GrabOneFrame("Rear");

                HObject awgImage1;

                visionFun.Bitmap2HObjectBpp32(image3, out awgImage1);
                GetAwgVerticalHeight(Service, awgImage1);



                Console.WriteLine("Press any key to go to 耦合位置.");
                Console.ReadKey();
                Thread.Sleep(100);

                MoveToPosition(Service, "Awg耦合低位");
                //  Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "耦合位置");

                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();


                int      xmaxpath = 0;
                double[] data     = new double[4];
                data[0] = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},0");
                data[1] = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},1");
                data[2] = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},2");
                data[3] = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},3");

                message = "预对准初始响应度:";
                for (int i = 0; i < 4; i++)
                {
                    message += $"[{i}]{data[i]}  ";
                }
                Service.__SSC_LogInfo(message);

                if (data[0] < Conditions.Resp_After_VisionAlign)
                {
                    Service.__SSC_LogError("视觉对准初始光功率过低,请检查产品。");
                    return;
                }

                #region 粗耦合

                // 如果初始响应度大于阈值,跳过粗找光。
                if (data[0] < Conditions.Resp_After_RoughAlign)
                {
                    cycles    = 0;
                    goodAlign = false;

                    Service.__SSC_LogInfo("开始粗找光...");

                    while (cycles < 5)
                    {
                        cycles++;

                        alignmentProfile = "x&y_roughScan";
                        Service.__SSC_LogInfo($"执行Profile-ND,参数[{alignmentProfile}],Cycle {cycles}/5...");
                        Service.__SSC_DoProfileND(alignmentProfile);

                        var resp = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},0");
                        Service.__SSC_LogInfo($"响应度:{resp}/目标值: {Conditions.Resp_After_RoughAlign}");

                        if (resp >= Conditions.Resp_After_RoughAlign)
                        {
                            goodAlign = true;
                            break;
                        }
                    }

                    if (!goodAlign)
                    {
                        Service.__SSC_LogError("CH1响应度无法达到规格。");
                        return;
                    }
                }

                #endregion

                #region 精细耦合

                cycles    = 0;
                goodAlign = false;

                Service.__SSC_LogInfo("开始细找光...");

                while (cycles < 5)
                {
                    cycles++;

                    alignmentProfile = "x&y_detailScan";
                    Service.__SSC_LogInfo($"执行Profile-ND,参数[{alignmentProfile}],Cycle {cycles}/5...");
                    Service.__SSC_DoProfileND(alignmentProfile);

                    var resp = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},0");
                    Service.__SSC_LogInfo($"响应度:{resp}/目标值: {Conditions.Resp_After_AccuracyAlign}");

                    if (resp >= Conditions.Resp_After_AccuracyAlign)
                    {
                        goodAlign = true;
                        break;
                    }
                }

                if (!goodAlign)
                {
                    Service.__SSC_LogError("CH1响应度无法达到规格。");
                    return;
                }

                #endregion

                #region 角度调整

                cycles    = 0;
                goodAlign = false;

                Service.__SSC_LogInfo("开始角度调整...");

                while (cycles < 5)
                {
                    cycles++;

                    alignmentProfile = "mercury";
                    Service.__SSC_LogInfo($"执行Angle Tuning,参数[{alignmentProfile}],Cycle {cycles}/5...");
                    var diff = (double)Service.__SSC_DoAngleTuning(alignmentProfile);
                    Service.__SSC_LogInfo($"1-4通道峰值位置误差:{diff.ToString("F3")}um/目标值: {Conditions.Resp_After_AngleTuning_PeakPosDiff}");

                    if (Math.Abs(diff) <= Conditions.Resp_After_AngleTuning_PeakPosDiff)
                    {
                        goodAlign = true;
                        break;
                    }
                }

                if (!goodAlign)
                {
                    Service.__SSC_LogError("1-4通道峰值位置误差无法达到规格!");
                }

                #endregion

                #region 角度调整后精细耦合

                cycles    = 0;
                goodAlign = false;

                Service.__SSC_LogInfo("开始Final找光...");

                while (cycles < 5)
                {
                    cycles++;

                    alignmentProfile = "x&y_detailScan";
                    Service.__SSC_LogInfo($"执行Profile-ND,参数[{alignmentProfile}],Cycle {cycles}/5...");
                    Service.__SSC_DoProfileND(alignmentProfile);

                    var resp = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},0");
                    Service.__SSC_LogInfo($"响应度:{resp}/目标值: {Conditions.Resp_Final}");

                    if (resp >= Conditions.Resp_Final)
                    {
                        goodAlign = true;
                        break;
                    }
                }

                if (!goodAlign)
                {
                    Service.__SSC_LogError("CH1响应度无法达到规格。");
                    return;
                }

                #endregion

                #region 检查四个通道响应度

                double[] finalResp = new double[4];
                for (int i = 0; i < 4; i++)
                {
                    finalResp[i] = Service.__SSC_MeasurableDevice_Read($"{EQUIP_CAPTION},{i}");
                }

                if (finalResp.Min() < Conditions.Resp_Final)
                {
                    Service.__SSC_LogError($"最小响应度低于规格,规格:{Conditions.Resp_Final}");
                    return;
                }
                else if (finalResp.Max() - finalResp.Min() > Conditions.Resp_Final_Diff)
                {
                    Service.__SSC_LogError($"通道平衡无法达到规格,规格:{Conditions.Resp_Final_Diff}");
                    return;
                }
                else
                {
                    Service.__SSC_LogInfo("耦合完成!");
                }


                #endregion

                #region 保存当前位置

                Service.__SSC_LogInfo("保存当前位置...");

                var final_x = Service.__SSC_GetAbsPosition(Conditions.ALIGNER, "X");
                var final_y = Service.__SSC_GetAbsPosition(Conditions.ALIGNER, "Y");
                var final_z = Service.__SSC_GetAbsPosition(Conditions.ALIGNER, "Z");

                Service.__SSC_LogInfo($"X: {final_x}, Y: {final_y}, Z: {final_z}");

                #endregion
                Console.WriteLine("请点胶");
                Console.ReadKey();
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Z", SSC_MoveMode.REL, 100, -10000);
                Thread.Sleep(100);
                Console.WriteLine("点胶完成,按任意键继续");
                Console.ReadKey();
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Z", SSC_MoveMode.REL, 100, 9500);
                Thread.Sleep(100);
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Z", SSC_MoveMode.REL, 20, 500);
                Thread.Sleep(100);
                return;

                #region 点胶

                Service.__SSC_LogInfo("开始点胶...");

                // 上提Z轴,AWG退到安全位置
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Z", SSC_MoveMode.REL, 20, -1000);

                // 移动到点胶位置
                Service.__SSC_MoveToPresetPosition(Conditions.ALIGNER, "点胶位置");
                Thread.Sleep(200);

                // 降下针筒
                Service.__SSC_WriteIO(Conditions.IO_INJECTOR, SSC_IOStatusEnum.Enabled);
                Thread.Sleep(200);

                // 启动点胶机
                Service.__SSC_LogInfo("点胶...");

                // 抬起针筒
                Service.__SSC_WriteIO(Conditions.IO_INJECTOR, SSC_IOStatusEnum.Disabled);

                #endregion

                #region 恢复AWG位置,重新对准

                Service.__SSC_LogInfo("恢复AWG位置...");

                Service.__SSC_MoveAxis(Conditions.ALIGNER, "X", SSC_MoveMode.ABS, 100, final_x);
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Y", SSC_MoveMode.ABS, 100, final_y);
                Service.__SSC_MoveAxis(Conditions.ALIGNER, "Z", SSC_MoveMode.ABS, 100, final_z);

                #endregion
            }
            catch (Exception ex)
            {
                Service.__SSC_LogError(ex.Message);
            }

            System.Threading.Thread.Sleep(100);
        }
Example #30
0
        /// <summary>
        /// 执行忙扫。
        /// </summary>
        /// <param name="Service"></param>
        /// <param name="opts"></param>
        private static void Step1(SystemServiceClient Service, Options opts)
        {
            var cycle = 0;

            var powerPrev = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);

__redo_rectscan:
            Service.__SSC_LogInfo($"开始面扫描搜索初始光...cycle({cycle})");
            cycle++;

            //PerformAlignment(Service,
            //    new Func<string, object>[] {Service.__SSC_DoRectAreaScan},
            //    opts,
            //    new[] {opts.ProfileNameBlindSearch},
            //    SSC_PMRangeEnum.RANGE1, double.NaN, 2);

            var ret = Service.__SSC_DoRectAreaScan(opts.ProfileNameBlindSearch);

            Thread.Sleep(200);

            // Service.__SSC_Powermeter_SetRange(PM_CAPTION, SSC_PMRangeEnum.AUTO);
            //var power = Service.__SSC_Powermeter_Read(opts.PowerMeterCaption);
            var power = ret.PeakValue;

            Service.__SSC_LogInfo($"最大功率:{power}mV");

            // The exit condition is power > -15dBm
            //if (power < opts.PowerThreRectAreaScan)
            if (power < 3000)
            {
                if (power - powerPrev > 5)
                {
                    cycle--;
                    powerPrev = power;
                    goto __redo_rectscan;
                }

                if (cycle == 1)
                {
                    Service.__SSC_LogWarn("搜索失败,Z轴-20um重新搜索...");
                    Service.__SSC_MoveAxis("Lens", "Z", SSC_MoveMode.REL, 100, -20);
                    goto __redo_rectscan;
                }

                if (cycle == 2)
                {
                    Service.__SSC_LogWarn("搜索失败,Z轴+40um重新搜索...");
                    Service.__SSC_MoveAxis("Lens", "Z", SSC_MoveMode.REL, 100, 40);
                    goto __redo_rectscan;
                }

                throw new Exception("无法找到初始功率, 请检查Lens位置。");
            }
            else
            {
                Service.__SSC_LogInfo("重新搜索峰值...");
                var maxCycle = 0;
                while (true)
                {
                    ret = Service.__SSC_DoRectAreaScan(opts.ProfileNameBlindSearchSmallStep);
                    if (ret.PeakValue > 3000)
                    {
                        break;
                    }
                    else
                    {
                        if (maxCycle > 5)
                        {
                            throw new Exception("无法找到初始功率, 请检查Lens位置。");
                        }
                    }

                    maxCycle++;
                }
            }
        }