IMetaWearBoard

The IMetaWearBoard interface is a software representation of the MbientLab sensor boards and is the central class of the MetaWear API.

Initialization

Before using any API features, first call InitializeAsync to initialize the object state. This function will also establish the Bluetooth LE connection and must be called after each disconnection.

await metawear.InitializeAsync();
Console.WriteLine("Board initialized");

Unexpected Disconnects

Sometimes the BLE connection will unexepectedly drop i.e. the BLE connection was not closed by the API. You can add a handler for such events by settng the OnUnexpectedDisconnect property.

metawear.OnUnexpectedDisconnect = () => Console.WriteLine("Unexpectedly lost connection");

Model

Despite the name, the IMetaWearBoard interface communicates with all MetaSensor boards, not just MetaWear boards. Because of this, the interface provides a Model property that determines exactly which board the interface is currently connected to.

Console.WriteLine("Board model: " + metawear.Model);

GATT Characteristics

Some GATT characetristics (battery level, device information) can be read from the MetaWearBoard interface using ReadBatteryLevelAsync and ReadDeviceInformationAsync respectively.

var deviceInfo = await board.ReadDeviceInformationAsync();
Console.WriteLine("Device Information: " + deviceInfo);

Modules

MetaWear modules, represented by the IModule interface, are sensors, peripherals, or on-board firmware features. To interact with the underlying MetaWear modules, retrieve a reference to the desired interface with the GetModule method. A null pointer will be returned if any of the following conditions are true:

  • Requested module is not supported on the board
  • Board is in MetaBoot mode
  • Has not yet connected
using MbientLab.MetaWear.Peripheral;

ILed led;
if ((led = metawear.GetModule<ILed>()) == null) {
    Console.WriteLine("LED module is present on this board");
}

Tear Down

When you are done using your board, call TearDown to remove resources allocated by the firmware and API such as routes, loggers, and data processors. this method does not reset the board so any configuration changes are preserved.