Tuesday, April 20, 2010

MindSqualls rocks! NXTasy.org does, too!

Now that I decided on using MindSqualls, let's get coding. First stumble block was the MessageRead() method takes as a second argument the local mailbox. What is the local mailbox? I decided to ask in the NXTasy forum and John Hansen promptly replied saying that the local mailbox should be ignored because there isn't one. He also mentioned something else that at the time I didn't understand:
The call to SendResponseString will simply write the value of out (S1, S2, etc...) to the outbound or response mailbox numbered 11. Response mailboxes have numbers equal to the specified mailbox number plus 10. You actually have to pass the response mailbox number (i.e., 10..19) rather than the "regular" mailbox number (0..9), unless Mindsquals is doing something weird and adding 10 to the number you pass in (which it should not do).
On the NXT side I stuck with the code I mentioned in my previous post (page 43 of Daniele Benedettelli's tutorial at bricxcc site):

#define BT_CONN 1
#define INBOX 5
#define OUTBOX 1

task main(){
  string in, out, iStr;
  int i = 0;
    iStr = NumToStr(i);
    out = StrCat("S",iStr);
    ReceiveRemoteString(INBOX, true, in);

On the PC side I wrote something really simple (please note that I am using this code only as a rough example, it is by no means 100% functional, large sections were left out):
using NKH.MindSqualls;

namespace BTMasterMessage
    public partial class Form1 : Form
        private void GetMessage()
            byte comPort = byte.Parse(this.txtComPort.Text);
            NxtCommunicationProtocol comm = new NxtBluetoothConnection(comPort);
            string msg = comm.MessageRead(NxtMailbox2.Box1, NxtMailbox.Box0, true);
            this.Text = msg;

Well, nothing worked, there was no message displayed PC side. Then I read more closely what John mentioned in his answer and I decided to change the first argument of MessageRead from Box1 to Box11:
string msg = comm.MessageRead(NxtMailbox2.Box11, NxtMailbox.Box0, true);

It was a magical moment when I ran the program and I got an "S173" or something like it on my screen. It was so awesome!

The conclusion: MindSqualls rocks and the helpful and friendly people in the NXTasy forum do as well! Big thanks to both teams!

No comments:

Post a Comment