Example #1
0
    protected void waitEvent(Chronopic myCP, Chronopic.Plataforma myPS, States myLS, out string inStr, out string outStr, int cpNum)
    {
        double timestamp = 0;
        bool   success   = false;
        bool   ok;
        string inEqual  = "";
        string outEqual = "";

        inStr = ""; outStr = "";
        int runAnalysisTcCount = 0;
        int runAnalysisTfCount = 0;

        bool isFirstOut = true;
        bool isFirstIn  = true;

        syncStates syncing = syncStates.DONE;

        if (syncFirst)
        {
            syncing                 = syncStates.NOTHING;
            feedbackMessage         = Catalog.GetString("Press and maintain Test button in all Chronopics simultaneously.");
            needShowFeedbackMessage = true;
        }

        do
        {
            ok = myCP.Read_event(out timestamp, out myPS);

            //if chronopic signal is Ok and state has changed
            if (ok && (
                    (myPS == Chronopic.Plataforma.ON && myLS == States.OFF) ||
                    (myPS == Chronopic.Plataforma.OFF && myLS == States.ON)) &&
                !cancel && !finish)
            {
                //while no finished time or jumps, continue recording events
                if (!success)
                {
                    //don't record the time until the first event of the first Chronopic
                    //this is only executed on the first chronopic that receives a change
                    if (firstValue)
                    {
                        firstValue = false;
                        initializeTimer();                         //this is for first Chronopic and only for simulated

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }

                    if (syncing == syncStates.NOTHING && myPS == Chronopic.Plataforma.ON && myLS == States.OFF)
                    {
                        syncing                 = syncStates.CONTACTED;
                        feedbackMessage         = Catalog.GetString("Release Test button in all Chronopics simultaneously.");
                        needShowFeedbackMessage = true;
                    }
                    else if (syncing == syncStates.CONTACTED && myPS == Chronopic.Plataforma.OFF && myLS == States.ON)
                    {
                        syncing         = syncStates.DONE;
                        feedbackMessage = Catalog.GetString("Synchronization done.") + "\n" +
                                          Catalog.GetString("Test starts now.");
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        if (type != Constants.RunAnalysisName)
                        {
                            needSensitiveButtonFinish = true;
                        }

                        if (myPS == Chronopic.Plataforma.ON && myLS == States.OFF)
                        {
                            //this is for runAnalysis, delete first tf on 2nd cp (jump cp)
                            if (cpNum == 2 && type == Constants.RunAnalysisName && runAnalysisTfCount == 0)
                            {
                                runAnalysisTfCount++;
                            }
                            //this is for multiChronopic, not for runAnalysis
                            else if (deleteFirst && isFirstOut)
                            {
                                isFirstOut = false;
                            }
                            else
                            {
                                double lastOut = timestamp / 1000.0;
                                LogB.Information(cpNum.ToString() + " landed: " + lastOut.ToString());
                                outStr   = outStr + outEqual + lastOut.ToString();
                                outEqual = "=";
                            }

                            /*
                             * if it's a runAnalysis,
                             * should end when arrive at 2n photocell (controlled by cp1)
                             */
                            if (cpNum == 1 && type == Constants.RunAnalysisName)
                            {
                                runAnalysisTcCount++;
                                if (runAnalysisTcCount >= 2)
                                {
                                    success = true;
                                    //better call also finish
                                    //then all cps know about ending
                                    finish = true;
                                }
                            }
                        }
                        else if (myPS == Chronopic.Plataforma.OFF && myLS == States.ON)
                        {
                            //this is for multiChronopic, not for runAnalysis
                            if (deleteFirst && isFirstIn)
                            {
                                isFirstIn = false;
                            }
                            else
                            {
                                double lastIn = timestamp / 1000.0;
                                LogB.Information(cpNum.ToString() + " jumped: " + lastIn.ToString());
                                inStr   = inStr + inEqual + lastIn.ToString();
                                inEqual = "=";
                            }
                        }

                        PrepareEventGraphMultiChronopicObject = new PrepareEventGraphMultiChronopic(
                            //timestamp/1000.0,
                            cp1StartedIn, cp2StartedIn, cp3StartedIn, cp4StartedIn,
                            cp1InStr, cp1OutStr, cp2InStr, cp2OutStr,
                            cp3InStr, cp3OutStr, cp4InStr, cp4OutStr);
                        needUpdateGraphType = eventType.MULTICHRONOPIC;
                        needUpdateGraph     = true;


                        updateProgressBar = new UpdateProgressBar(
                            true,                                  //isEvent
                            false,                                 //means activity mode
                            -1                                     //don't show text
                            );
                        needUpdateEventProgressBar = true;
                    }
                }

                if (myPS == Chronopic.Plataforma.OFF)
                {
                    myLS = States.OFF;
                }
                else
                {
                    myLS = States.ON;
                }
            }
        } while (!success && !cancel && !finish);

        if (finish)
        {
            finishThisCp();

            //call write on gui/chronojump.cs, because if done in execute/MultiChronopic,
            //will be called n times if n chronopics are working
            //write(false); //tempTable
        }
    }
    protected void waitEvent(Chronopic myCP, Chronopic.Plataforma myPS, States myLS, out string inStr, out string outStr, int cpNum)
    {
        double timestamp = 0;
        bool success = false;
        bool ok;
        string inEqual = "";
        string outEqual = "";

        inStr = ""; outStr = "";
        int runAnalysisTcCount = 0;
        int runAnalysisTfCount = 0;

        bool isFirstOut = true;
        bool isFirstIn = true;

        syncStates syncing = syncStates.DONE;
        if(syncFirst) {
            syncing = syncStates.NOTHING;
            feedbackMessage = Catalog.GetString("Press and mantain Test button in all Chronopics simultaneously.");
            needShowFeedbackMessage = true;
        }

        do {
            ok = myCP.Read_event(out timestamp, out myPS);

            //if chronopic signal is Ok and state has changed
            if (ok && (
                    (myPS == Chronopic.Plataforma.ON && myLS == States.OFF) ||
                    (myPS == Chronopic.Plataforma.OFF && myLS == States.ON) )
                        && !cancel && !finish) {

                //while no finished time or jumps, continue recording events
                if ( ! success) {
                    //don't record the time until the first event of the first Chronopic
                    //this is only executed on the first chronopic that receives a change
                    if (firstValue) {
                        firstValue = false;
                        initializeTimer(); //this is for first Chronopic and only for simulated

                        feedbackMessage = "";
                        needShowFeedbackMessage = true;
                    }

                    if(syncing == syncStates.NOTHING && myPS == Chronopic.Plataforma.ON && myLS == States.OFF) {
                        syncing = syncStates.CONTACTED;
                        feedbackMessage = Catalog.GetString("Release Test button in all Chronopics simultaneously.");
                        needShowFeedbackMessage = true;
                    }
                    else if (syncing == syncStates.CONTACTED && myPS == Chronopic.Plataforma.OFF && myLS == States.ON) {
                        syncing = syncStates.DONE;
                        feedbackMessage = Catalog.GetString("Synchronization done.") + "\n" +
                            Catalog.GetString("Test starts now.");
                        needShowFeedbackMessage = true;
                    }
                    else {
                        if(type != Constants.RunAnalysisName)
                            needSensitiveButtonFinish = true;

                        if(myPS == Chronopic.Plataforma.ON && myLS == States.OFF) {
                            //this is for runAnalysis, delete first tf on 2nd cp (jump cp)
                            if(cpNum == 2 && type == Constants.RunAnalysisName && runAnalysisTfCount == 0)
                                runAnalysisTfCount ++;
                            //this is for multiChronopic, not for runAnalysis
                            else if(deleteFirst && isFirstOut)
                                isFirstOut = false;
                            else {
                                double lastOut = timestamp/1000.0;
                                Log.WriteLine(cpNum.ToString() + " landed: " + lastOut.ToString());
                                outStr = outStr + outEqual + lastOut.ToString();
                                outEqual = "=";
                            }
                            /*
                               if it's a runAnalysis,
                               should end when arrive at 2n photocell (controlled by cp1)
                               */
                            if(cpNum == 1 && type == Constants.RunAnalysisName) {
                                runAnalysisTcCount ++;
                                if(runAnalysisTcCount >= 2) {
                                    success = true;
                                    //better call also finish
                                    //then all cps know about ending
                                    finish = true;
                                }
                            }
                        }
                        else if(myPS == Chronopic.Plataforma.OFF && myLS == States.ON) {
                            //this is for multiChronopic, not for runAnalysis
                            if(deleteFirst && isFirstIn)
                                isFirstIn = false;
                            else {
                                double lastIn = timestamp/1000.0;
                                Log.WriteLine(cpNum.ToString() + " jumped: " + lastIn.ToString());
                                inStr = inStr + inEqual + lastIn.ToString();
                                inEqual = "=";
                            }
                        }

                        PrepareEventGraphMultiChronopicObject = new PrepareEventGraphMultiChronopic(
                                //timestamp/1000.0,
                                cp1StartedIn, cp2StartedIn, cp3StartedIn, cp4StartedIn,
                                cp1InStr, cp1OutStr, cp2InStr, cp2OutStr,
                                cp3InStr, cp3OutStr, cp4InStr, cp4OutStr);
                        needUpdateGraphType = eventType.MULTICHRONOPIC;
                        needUpdateGraph = true;

                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                false, //means activity mode
                                -1 //don't show text
                                );
                        needUpdateEventProgressBar = true;
                    }
                }

                if(myPS == Chronopic.Plataforma.OFF)
                    myLS = States.OFF;
                else
                    myLS = States.ON;

            }
        } while ( ! success && ! cancel && ! finish );

        if (finish) {
            finishThisCp(cpNum);

            //call write on gui/chronojump.cs, because if done in execute/MultiChronopic,
            //will be called n times if n chronopics are working
            //write(false); //tempTable

            //event will be raised, and managed in chronojump.cs
            //only one call (that comes from first chronopic)
            if(cpNum == 1)
                fakeButtonFinished.Click();
        }
        if(cancel) {
            //event will be raised, and managed in chronojump.cs
            fakeButtonFinished.Click();
            cancelThisCp(cpNum);
        }
    }