Monobrick on Android

HomeForumsMonoBrick Communication LibraryMonobrick on Android

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3311
    Author Image
    Edgard Neto
    Participant

    Hello all,

    I’ve been using monobrick for a while now but I’ve decided to start using it with android.
    Although I dont understand how to get it to work in android ? I’ve been trying to use Xamarin Studio Android, but I can’t understand how to add the libraries (monobrick for Android) into my project.
    Can anyone help me to do that ? Or at least a good tutorial for Monobrick for Android.

    Thanks.

    #3316
    Author Image
    Anders Søborg
    Keymaster

    Hi – thanks for using MonoBrick Communication library

    Start off by downloading the Monobrick Communication Library for Android. The first thing you need to do is to check if Bluetooth is turned on. This can be done by using the static property on the Bluetooth class as shown below.

    
    MonoBrick.Bluetooth<BrickCommand,BrickReply>.IsEnabled
    

    If Bluetooth is not turned on use the following code to turn it on

    
    MonoBrick.Bluetooth<BrickCommand,BrickReply>.Enable();
    

    Once Bluetooth has been turned on use the following code to get a list of paired devices

    
    MonoBrick.Bluetooth.BondDevices
    

    If you know the device name you can also call

    
    MonoBrick.Bluetooth.GetBondDevice(string deviceName);
    

    Use the Bluetooth device to create a Bluetooth connection instance and create a brick class followed by opening the connection. The code below sums it all up.

    
    var device = MonoBrick.Bluetooth<MonoBrick.EV3.Command, MonoBrick.EV3.Reply>.GetBondDevice("youDeviceName");
    var connection = new Bluetooth<MonoBrick.EV3.Command, MonoBrick.EV3.Reply>(device);
    var brick = new MonoBrick.EV3.Brick<MonoBrick.EV3.Sensor,MonoBrick.EV3.Sensor,MonoBrick.EV3.Sensor,MonoBrick.EV3.Sensor>(connection);
    brick.Connection.Open();
    

    Replace EV3 namespace with NXT namespace depending on your device

    Let me know how it goes

    Anders

    #3671
    Author Image
    Jacek S
    Participant

    Hi,
    Do I need to buy license for xamarin studio? I think xamarin free starter limitation to 64kb IL size is not sufficient (monobrick library have more than 100kb). Are there any alternatives to use monobrick library for android without buying xamarin license?

    Jacek

    #3676
    Author Image
    Anders Søborg
    Keymaster

    Hi Jacek

    Are there any alternatives to use monobrick library for android without buying xamarin license?

    No Sorry – but if you are a student you can get a discount…

    Anders

    #3852
    Author Image
    Marcin Krzewski
    Participant

    Hi Anders

    I did as you said and I’m getting an error in the line var device = MonoBrick.Bluetooth<MonoBrick.EV3.Command, MonoBrick.EV3.Reply>.GetBondDevice("youDeviceName");
    saying 'MonoBrick.Bluetooth<MonoBrick.EV3.Command,MonoBrick.EV3.Reply>' does not contain a definition for 'GetBondDevice' D:\Projekty\EV3\Kama2\Kama2\Activity1.cs
    I copied the bluetooth class from the test project. Do you know the solution to that? How should the definition of the GetBondDevice method look like?

    Marcin

    #3857
    Author Image
    Anders Søborg
    Keymaster

    Hi Marcin

    You need to use the Android DLL. This DLL has another implementation of the Bluetooth connection. One of the differences is the GetBondDevice…

    Anders

    #3865
    Author Image
    Marcin Krzewski
    Participant

    Hi Anders

    I still can’t connect.
    "youDeviceName"
    Should it be my phone name or my ev3 brick name? And does it matter if I turn on bluetooth and pair devices before I run the app on my phone? Or should I do it in the app using the code you provided? Btw. I dont exactly know what you mean by "This can be done by using the static property on the Bluetooth class"

    Sorry if my questions are dumb, I’m still learning.

    Marcin

    #3868
    Author Image
    Anders Søborg
    Keymaster

    Hi Again

    There are no such things as dumb questions! I am just happy that people are using me software…

    Should it be my phone name or my ev3 brick name? And does it matter if I turn on bluetooth and pair devices before I run the app on my phone?

    Yes you need to pair you phone with the brick before running the program…

    Just quoting what I wrote above

    Once Bluetooth has been turned on use the following code to get a list of paired devices

    MonoBrick.Bluetooth.BondDevices
    If you know the device name you can also call

    MonoBrick.Bluetooth.GetBondDevice(string deviceName);

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

You must be logged in to reply to this topic.

Posted in

Make a donation