Reply To: How to handle when a brick is turned off & back on?

HomeForumsMonoBrick Communication LibraryHow to handle when a brick is turned off & back on?Reply To: How to handle when a brick is turned off & back on?

#3753
Author Image
Mike O’C
Participant

Huh! I’d swear in the past I had written code which tried to call Brick.Connection.Close(), and that did not work – yet when I just updated my class here, now the process works. Good news, regardless!

The updated “GenericBrick.txt” class is attached. I refactored the brick connection code into its own method (rather than being in the constructor), so I could reuse it in the ‘reset’ method, e.g.:

public int resetBrokenState()
{
    if (state == STATE_BROKEN)
    {
        if (ev3Brick != null)
        {
            ev3Brick.Connection.Close();
            connectToBrick(true, false);
            //state = STATE_EV3;
        }
        else
        {
            nxtBrick.Connection.Close();
            connectToBrick(false, false);
            //state = STATE_NXT;
        }
    }

    return state;
}
Attachments:
You must be logged in to view attached files.
Posted in

Make a donation