Home→Forums→MonoBrick Communication Library→How to handle when a brick is turned off & back on?→Reply To: How to handle when a brick is turned off & back on?
January 4, 2014 at 20:21
#3753
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;
}
Follow