Exemplo n.º 1
0
    //chronopic init should not touch  gtk, for the threads
    public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success)
    {
        LogB.Information("starting connection with chronopic");

        CancelledByUser = false;
        success         = true;

        LogB.Information("chronopicInit-1");
        LogB.Information(string.Format("chronopic port: {0}", myPort));
        mySp = new SerialPort(myPort);
        try {
            mySp.Open();
            LogB.Information("chronopicInit-2");
            //-- Create chronopic object, for accessing chronopic
            myCp = new Chronopic(mySp);

            LogB.Information("chronopicInit-2.1");
            myCp.Flush();

            //if myCp has been cancelled
            if (myCp.AbortFlush)
            {
                LogB.Information("chronopicInit-2.2 cancelled");
                success = false;
                myCp    = new Chronopic();              //fake constructor
            }
            else
            {
                LogB.Information("chronopicInit-3");
                //on windows, this check make a crash
                //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
                //the Read_platform comes too much soon (when cp is not totally created), and this makes crash

                //-- Obtener el estado inicial de la plataforma

                bool ok = false;
                LogB.Information("chronopicInit-4");
                do
                {
                    LogB.Information("chronopicInit-5");
                    ok = myCp.Read_platform(out myPS);
                    LogB.Information("chronopicInit-6");
                } while(!ok && !CancelledByUser);
                LogB.Information("chronopicInit-7");
                if (!ok)
                {
                    //-- Si hay error terminar
                    LogB.Error(string.Format("Error: {0}", myCp.Error));
                    success = false;
                }
            }
        } catch {
            LogB.Error("chronopicInit-2.a catched");
            success = false;
            myCp    = new Chronopic();          //fake constructor
        }

        returnString = "";
        return(success);
    }
Exemplo n.º 2
0
    protected Chronopic.Plataforma chronopicInitialValue(Chronopic cp)
    {
        Chronopic.Plataforma myPlatformState = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
        bool ok        = false;
        int  timeWait  = 50;                                                //wait 50ms between calls to Read_platform
        int  timeLimit = 1000;
        int  count     = 0;

        do
        {
            try {
                ok = cp.Read_platform(out myPlatformState);
            } catch {
                LogB.Warning("Manage called after finishing constructor, do later");
            }
            Thread.Sleep(timeWait);             //wait 50ms
            count += timeWait;
        } while (!ok && count < timeLimit);

        return(myPlatformState);
    }
Exemplo n.º 3
0
    protected void simulateChangePlatform()
    {
        LogB.Information("Changing!");
        LogB.Information(string.Format("PRE timeLast: {0}, timerCount: {1}, timeAccumulated: {2}", simulatedTimeLast, timerCount, simulatedTimeAccumulatedBefore));

        simulatedTimeLast = timerCount - simulatedTimeAccumulatedBefore;
        //simulatedTimeAccumulatedBefore = timerCount;
        simulatedTimeAccumulatedBefore = Math.Round(timerCount, 2);
        LogB.Information(string.Format("POST: timeLast: {0}, timerCount: {1}, timeAccumulated: {2}", simulatedTimeLast, timerCount, simulatedTimeAccumulatedBefore));

        //change the boolean who points to 'which are the MINs and the MAXs
        simulatedCurrentTimeIntervalsAreContact = !simulatedCurrentTimeIntervalsAreContact;

        if (platformState == Chronopic.Plataforma.ON)
        {
            platformState = Chronopic.Plataforma.OFF;
        }
        else
        {
            platformState = Chronopic.Plataforma.ON;
        }

        LogB.Information("Changed!");
    }
Exemplo n.º 4
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
        }
    }
Exemplo n.º 5
0
    /*
     * //onTimer allow to update progressbar_time every 50 milliseconds
     * //also can change platform state in simulated mode
     * //protected void onTimer( Object source, ElapsedEventArgs e )
     * protected override void onTimer( )
     * {
     *      timerCount = timerCount + .05; //0,05 segons == 50 milliseconds, time between each call of onTimer
     * }
     */


    public override void Manage()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (chronopics > 0)
        {
            platformState = chronopicInitialValue(cp);

            if (platformState == Chronopic.Plataforma.ON)
            {
                loggedState  = States.ON;
                cp1StartedIn = true;
            }
            else if (platformState == Chronopic.Plataforma.OFF)
            {
                loggedState  = States.OFF;
                cp1StartedIn = false;
            }
            else                 //UNKNOW (Chronopic disconnected, port changed, ...)
            {
                chronopicHasBeenDisconnected();
                return;
            }

            //prepare jump for being cancelled if desired
            cancel = false;

            //prepare jump for being finished earlier if desired
            finish = false;

            if (chronopics > 1)
            {
                platformState2 = chronopicInitialValue(cp2);

                if (platformState2 == Chronopic.Plataforma.ON)
                {
                    loggedState2 = States.ON;
                    cp2StartedIn = true;
                }
                else if (platformState2 == Chronopic.Plataforma.OFF)
                {
                    loggedState2 = States.OFF;
                    cp2StartedIn = false;
                }
                else                     //UNKNOW (Chronopic disconnected, port changed, ...)
                {
                    chronopicHasBeenDisconnected();
                    return;
                }

                if (chronopics > 2)
                {
                    platformState3 = chronopicInitialValue(cp3);

                    if (platformState3 == Chronopic.Plataforma.ON)
                    {
                        loggedState3 = States.ON;
                        cp3StartedIn = true;
                    }
                    else if (platformState3 == Chronopic.Plataforma.OFF)
                    {
                        loggedState3 = States.OFF;
                        cp3StartedIn = false;
                    }
                    else                         //UNKNOW (Chronopic disconnected, port changed, ...)
                    {
                        chronopicHasBeenDisconnected();
                        return;
                    }

                    if (chronopics > 3)
                    {
                        platformState4 = chronopicInitialValue(cp4);

                        if (platformState4 == Chronopic.Plataforma.ON)
                        {
                            loggedState4 = States.ON;
                            cp4StartedIn = true;
                        }
                        else if (platformState4 == Chronopic.Plataforma.OFF)
                        {
                            loggedState4 = States.OFF;
                            cp4StartedIn = false;
                        }
                        else                             //UNKNOW (Chronopic disconnected, port changed, ...)
                        {
                            chronopicHasBeenDisconnected();
                            return;
                        }
                    }
                }
            }
        }

        string platformsProblems = "";

        if (type == Constants.RunAnalysisName)
        {
            string sep = "";
            if (platformState == Chronopic.Plataforma.ON)
            {
                platformsProblems = Catalog.GetString("Photocells");
                sep = ", ";
            }
            if (platformState2 == Chronopic.Plataforma.ON)
            {
                platformsProblems += sep + Catalog.GetString("Platform");
            }
        }


        if (platformsProblems.Length > 0)
        {
            ConfirmWindow confirmWin;
            confirmWin = ConfirmWindow.Show(
                string.Format(Catalog.GetString("There's contact in {0}. Please leave."), platformsProblems), "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn, gstreamer);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);

            //if confirmWin.Button_cancel is pressed retuen
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
        else
        {
            firstValue = true;
            //writingStarted = false;

            //start thread
            if (chronopics > 0)
            {
                //prepare variables to allow being cancelled or finished
                if (!simulated)
                {
                    Chronopic.InitCancelAndFinish();
                }

                thread = new Thread(new ThreadStart(waitEventPre));
                if (chronopics > 1)
                {
                    thread2 = new Thread(new ThreadStart(waitEventPre2));
                    if (chronopics > 2)
                    {
                        thread3 = new Thread(new ThreadStart(waitEventPre3));
                        if (chronopics > 3)
                        {
                            thread4 = new Thread(new ThreadStart(waitEventPre4));
                        }
                    }
                }
            }

            GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

            if (chronopics > 0)
            {
                LogB.ThreadStart();
                thread.Start();

                if (chronopics > 1)
                {
                    thread2.Start();
                    if (chronopics > 2)
                    {
                        thread3.Start();
                        if (chronopics > 4)
                        {
                            thread4.Start();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 6
0
    //chronopic init should not touch  gtk, for the threads
    public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success)
    {
        LogB.Information("starting connection with chronopic");

        CancelledByUser = false;
        success         = true;

        LogB.Information("chronopicInit-1");
        LogB.Information(string.Format("chronopic port: {0}", myPort));
        mySp = new SerialPort(myPort);
        try {
            mySp.Open();
            LogB.Information("chronopicInit-2");
            //-- Create chronopic object, for accessing chronopic
            myCp = new Chronopic(mySp);

            LogB.Information("chronopicInit-2.1");
            myCp.Flush();

            //if myCp has been cancelled
            if (myCp.AbortFlush)
            {
                LogB.Information("chronopicInit-2.2 cancelled");
                success = false;
                myCp    = new Chronopic();              //fake constructor
            }
            else
            {
                LogB.Information("chronopicInit-3");
                //on windows, this check make a crash
                //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
                //the Read_platform comes too much soon (when cp is not totally created), and this makes crash

                //-- Obtener el estado inicial de la plataforma

                bool ok = false;
                LogB.Information("chronopicInit-4");
                do
                {
                    LogB.Information("chronopicInit-5");
                    ok = myCp.Read_platform(out myPS);
                    LogB.Information("chronopicInit-6");
                } while(!ok && !CancelledByUser);
                LogB.Information("chronopicInit-7");
                if (!ok)
                {
                    //-- Si hay error terminar
                    LogB.Error(string.Format("Error: {0}", myCp.Error));
                    success = false;
                }
            }
        } catch {
            LogB.Error("chronopicInit-2.a catched");
            success = false;
            myCp    = new Chronopic();          //fake constructor
        }

        bool connected = false;

        returnString = "";
        if (success)
        {
            if (currentCp == 1)
            {
                connected = true;
            }
            returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort);
        }
        else
        {
            returnString = Catalog.GetString("Problems communicating to chronopic.");
            if (currentCp == 1)
            {
                returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
                returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable.");
            }

            //this will raise on_radiobutton_simulated_ativate and
            //will put cpRunning to false, and simulated to true and cp.Close()
            if (currentCp == 1)
            {
                connected = false;
            }
        }

        return(connected);
    }
Exemplo n.º 7
0
    /*
    //onTimer allow to update progressbar_time every 50 milliseconds
    //also can change platform state in simulated mode
    //protected void onTimer( Object source, ElapsedEventArgs e )
    protected override void onTimer( )
    {
        timerCount = timerCount + .05; //0,05 segons == 50 milliseconds, time between each call of onTimer
    }
    */
    public override void Manage()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if(chronopics > 0) {
            platformState = chronopicInitialValue(cp);

            if (platformState==Chronopic.Plataforma.ON) {
                loggedState = States.ON;
                cp1StartedIn = true;
            } else if (platformState==Chronopic.Plataforma.OFF) {
                loggedState = States.OFF;
                cp1StartedIn = false;
            } else { //UNKNOW (Chronopic disconnected, port changed, ...)
                chronopicHasBeenDisconnected();
                return;
            }

            //prepare jump for being cancelled if desired
            cancel = false;
            totallyCancelledMulti1 = false;

            //prepare jump for being finished earlier if desired
            finish = false;
            totallyFinishedMulti1 = false;

            if(chronopics > 1) {
                platformState2 = chronopicInitialValue(cp2);

                if (platformState2==Chronopic.Plataforma.ON) {
                    loggedState2 = States.ON;
                    cp2StartedIn = true;
                } else if (platformState2==Chronopic.Plataforma.OFF) {
                    loggedState2 = States.OFF;
                    cp2StartedIn = false;
                } else { //UNKNOW (Chronopic disconnected, port changed, ...)
                    chronopicHasBeenDisconnected();
                    return;
                }

                totallyCancelledMulti2 = false;
                totallyFinishedMulti2 = false;

                if(chronopics > 2) {
                    platformState3 = chronopicInitialValue(cp3);

                    if (platformState3==Chronopic.Plataforma.ON) {
                        loggedState3 = States.ON;
                        cp3StartedIn = true;
                    } else if (platformState3==Chronopic.Plataforma.OFF) {
                        loggedState3 = States.OFF;
                        cp3StartedIn = false;
                    } else { //UNKNOW (Chronopic disconnected, port changed, ...)
                        chronopicHasBeenDisconnected();
                        return;
                    }

                    totallyCancelledMulti3 = false;
                    totallyFinishedMulti3 = false;

                    if(chronopics > 3) {
                        platformState4 = chronopicInitialValue(cp4);

                        if (platformState4==Chronopic.Plataforma.ON) {
                            loggedState4 = States.ON;
                            cp4StartedIn = true;
                        } else if (platformState4==Chronopic.Plataforma.OFF) {
                            loggedState4 = States.OFF;
                            cp4StartedIn = false;
                        } else { //UNKNOW (Chronopic disconnected, port changed, ...)
                            chronopicHasBeenDisconnected();
                            return;
                        }

                        totallyCancelledMulti4 = false;
                        totallyFinishedMulti4 = false;
                    }
                }
            }
        }

        string platformsProblems = "";
        if(type == Constants.RunAnalysisName) {
            string sep = "";
            if(platformState==Chronopic.Plataforma.ON) {
                platformsProblems = Catalog.GetString("Photocells");
                sep = ", ";
            }
            if(platformState2==Chronopic.Plataforma.ON)
                platformsProblems += sep + Catalog.GetString("Platform");
        }

        if(platformsProblems.Length > 0) {
            ConfirmWindow confirmWin;
            confirmWin = ConfirmWindow.Show(
                    string.Format(Catalog.GetString("There's contact in {0}. Please leave."), platformsProblems), "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);

            //if confirmWin.Button_cancel is pressed retuen
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        } else {
            firstValue = true;
            //writingStarted = false;

            //start thread
            if(chronopics > 0) {
                thread = new Thread(new ThreadStart(waitEventPre));
                if(chronopics > 1) {
                    thread2 = new Thread(new ThreadStart(waitEventPre2));
                    if(chronopics > 2) {
                        thread3 = new Thread(new ThreadStart(waitEventPre3));
                        if(chronopics > 3) {
                            thread4 = new Thread(new ThreadStart(waitEventPre4));
                        }
                    }
                }
            }

            GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));

            if(chronopics > 0) {
                thread.Start();
                if(chronopics > 1) {
                    thread2.Start();
                    if(chronopics > 2) {
                        thread3.Start();
                        if(chronopics > 4) {
                            thread4.Start();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 8
0
    protected void simulateChangePlatform()
    {
        Log.Write("Changing!");
        Log.WriteLine(string.Format("PRE timeLast: {0}, timerCount: {1}, timeAccumulated: {2}", simulatedTimeLast, timerCount, simulatedTimeAccumulatedBefore));

        simulatedTimeLast = timerCount - simulatedTimeAccumulatedBefore;
        //simulatedTimeAccumulatedBefore = timerCount;
        simulatedTimeAccumulatedBefore = Math.Round(timerCount,2);
        Log.WriteLine(string.Format("POST: timeLast: {0}, timerCount: {1}, timeAccumulated: {2}", simulatedTimeLast, timerCount, simulatedTimeAccumulatedBefore));

        //change the boolean who points to 'which are the MINs and the MAXs
        simulatedCurrentTimeIntervalsAreContact = ! simulatedCurrentTimeIntervalsAreContact;

        if(platformState == Chronopic.Plataforma.ON)
            platformState = Chronopic.Plataforma.OFF;
        else
            platformState = Chronopic.Plataforma.ON;

        Log.WriteLine("Changed!");
    }