Mailbox Send and Receive on Android

HomeForumsMonoBrick Communication LibraryMailbox Send and Receive on Android

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3741
    Author Image
    Greg Roll
    Participant

    Hi,

    Firstly thank you for such wonderful software, support and instructions. Using MonoBrickAndroid I can connect to an NXT device and EV3 device.

    Where I am struggling is reading and writing to and from mailboxes on both NXT and EV3. I am not sure what to input as the values for mailbox.open (on EV3) and mailbox.read (on EV3). When I try mailbox.readstring (on NXT) it crashes but again not sure what to put under the values. So far I have tried NXT.Box.Box0 but that doesn’t allow me to enter the mailbox name.

    Is there any chance you could post some sample code (even if it’s quick and dirty).

    Thanks again,
    Greg

    #3744
    Author Image
    Anders Søborg
    Keymaster

    Hi

    For the EV3 you would do something like this (taken from the programming guide)

    using System;
    using MonoBrick.EV3;
    using System.Threading;
    public static class Program{
      static void Main(string[] args)
      {
          var ev3 = new Brick<Sensor,Sensor,Sensor,Sensor<("usb");
          ev3.Connection.Open();
          ConsoleKeyInfo cki;
          Console.WriteLine("Press Q to quit");    
          do     
          {    
              cki = Console.ReadKey(true); //press a key    
              switch(cki.Key){
                case ConsoleKey.M:
                    Console.WriteLine("String to send to mailbox");
                    string input = Console.ReadLine();
                    ev3.Mailbox.Send("mailbox1", input, false);
                    break;                                 
              }    
          } while (cki.Key != ConsoleKey.Q);  
          ev3.Connection.Close();
      }
    }

    On the NXT you need to know that in NXT-G mailbox numbers range from 1 to 10, while Monobrick ranges from 0 to 9 so sending to mailbox 0 will be mailbox 1 in NXT-G.

    Hope this helps

    Anders

    #3762
    Author Image
    Greg Roll
    Participant

    Hi Anders

    Thank you for the quick reply. I can write to the mailbox OK where I get stuck is reading then. Is this possible for both? If so do you have examples? I couldn’t find one.

    Thanks
    Greg

    #3763
    Author Image
    Anders Søborg
    Keymaster

    For NXT it is possible – but support for this on the EV3 has not been added. On the NXT you can ask for new messages but this is not how it works on the EV3 – so the communication layer has to be refactored – it can be done I just haven’t had the time. If you need to send data back and forth between a PC and the EV3 you could consider trying the MonoBrick firmware – with this you could send data with unlimited length.

    Anders

    #3764
    Author Image
    Greg Roll
    Participant

    Hi Anders,

    Thanks again for the quick response. That’s for making this and actively supporting it. It’s people like you that make mindstorm awesome!

    Greg

    #3853
    Author Image
    Marcin Krzewski
    Participant

    Hi Greg

    in your first post you said you can connect to EV3 using MonoBrickAndroid so I assume you created an app for that. I’m trying to do that to, my app is supposed to control a car via bluetooth, but I’m having truble establishing connection. Could you share your code? If not whole maybe just the connection part?

    Marcin

    #3856
    Author Image
    Anders Søborg
    Keymaster

    Hi Marcin

    Try to use the code shown in this thread.

    Anders

    #3941
    Author Image
    Greg Roll
    Participant

    Hi Marcin,

    Sorry for missing this. I haven’t been around for a while.

    Hopefully the above helps you out.

    Greg

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Posted in

Make a donation