Mike O'C

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: How to handle when a brick is turned off & back on? #3758
    Author Image
    Mike O’C
    Participant

    Not quite in place; the “GenericBrick.cs” class has a constructor which doesn’t take a bool ‘isEv3’, but tries to automatically detect whether a brick is NXT or EV3. This also has not worked yet. I tried updating it to do a similar thing to the ‘resetConnection()’ method, but so far no luck:

    public GenericBrick(string newBrickName, string newConnName)
    {
        brickName = newBrickName + "";
        connName = newConnName + "";
        state = STATE_NEW;
    
        // first, try to connect as if it is an NXT
        connectToBrick(false, true);
        if (state == STATE_NXT)
            return;
    
        // not a found NXT?
        if (nxtBrick != null)
        {
            if (nxtBrick.Connection != null)
                nxtBrick.Connection.Close();
        }
        nxtBrick = null;
    
        // try to connect as if it is an EV3
        connectToBrick(true, true);
    }
    

    However, in the meantime I wrote the Winforms UI to pop a dialog box asking if a brick is EV3 or NXT. That will work for the near term.

    Attachments:
    You must be logged in to view attached files.
    in 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.
    in reply to: How to handle when a brick is turned off & back on? #3747
    Author Image
    Mike O’C
    Participant

    Whoops, it wouldn’t let me attach *.cs files. Trying again with *.txt files – if these work, just rename them to *.cs and drop them into the “\TestApplication” folder in the MonoBrick Test Project.

    – Mike

    Edit: And also, I apologize in advance for any bad coding practices you see. I’m brand-new to C# development. ^_^;;

    • This reply was modified 9 years, 1 month ago by Author ImageMike O'C.
    Attachments:
    You must be logged in to view attached files.
Viewing 3 posts - 1 through 3 (of 3 total)
Posted in

Make a donation