Forum Replies Created
-
AuthorPosts
-
Mike O’CParticipantNot 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.
Mike O’CParticipantHuh! 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.
Mike O’CParticipantWhoops, 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 10 years, 11 months ago by Mike O'C.
Attachments:
You must be logged in to view attached files. -
AuthorPosts
Follow