Reply To: Monobrick on Android

HomeForumsMonoBrick Communication LibraryMonobrick on AndroidReply To: Monobrick on Android

#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

Posted in

Make a donation