Bio Radio SDK - Xamarin Android
Bio Radio SDK - Xamarin Android Documentation

Welcome to the BioRadio Xamarin API from Great Lakes NeuroTechnologies. This guide is intended for developers seeking to incorporate the BioRadio into their own applications.

The API provides methods to scan, connect, configure, and stream data from the device.

Prerequisites

Getting Started

      The first task when working with a BioRadio is to identify its MAC address in order to establish a connection. If you already know your MAC ID, you can get a reference to a BioRadioDevice by instantiating a BioRadioDeviceManager and calling GetBluetoothDevice(Int64).

{C#}
using GLNeuroTech.Devices.BioRadio;
using GLNeuroTech.Devices.BioRadio.Configuration;
//You need a string _macID for the bluetooth device in format: "AA:BB:CC:DD:EE:FF"
string _macId = "AA:BB:CC:DD:EE:FF";
//Step 1: Create an android transport provider.
AndroidTransportProvider trans = new AndroidTransportProvider();
//Step 2: Create a BioRadio device manager.
BioRadioDeviceManager mgr = new BioRadioDeviceManager(trans);
//Step 3:Create a device using the _macID and dispaly the device info.
BioRadioDevice _device;
using (_device = mgr.GetBluetoothDevice(_macId))
{
BatteryInfo battery = _device.GetBatteryInfo();
Console.WriteLine("Voltage: " + battery.Voltage.ToString());
DateTime deviceTime = _device.GetDeviceTime();
Console.WriteLine("Current Device Time: " + deviceTime.ToString());
//Update the device date and time if is off with more than 5 seconds.
if (deviceTime < DateTime.Now.AddSeconds(-5) || deviceTime > DateTime.Now.AddSeconds(5))
{
_device.SetDeviceTime();
deviceTime = _device.GetDeviceTime();
Console.WriteLine("New Device Time: " + deviceTime.ToString());
}
}
_device.Disconnect();
.

      If you do not know the MAC ID of your device, you can initiate a scan using the DiscoverBluetoothDevices() method. This method will return a list of discovered devices by their device ID and MAC ID.

Configuring the Device

      The BioRadio can be configured in various ways depending on the intended application. The BioRadioConfiguration class is used to define the configuration of a device. The device's current configuration can be retrieved by calling GetConfiguration() and it can be programmed using SetConfiguration()

{C#}
//Setting the configuration using an xml file.
_device.SetConfiguration(GetExternalFilesDir(null) + @"/ExampleBioRadioConfiguration.xml");
//Getting the device configuration:
BioRadioConfiguration config;
config = _device.GetConfiguration();
//Display some of configurations:
Console.WriteLine("Termination: " + config.Termination);
Console.WriteLine("Name: " + config.Name);
Console.WriteLine("PatientGroundDriven: " + config.PatientGroundDriven);
Console.WriteLine("PerformLeadOffDetection: " + config.PerformLeadOffDetection);
Console.WriteLine("SampleRate: " + config.SampleRate);
.

Acquiring Data

      Once your device has been located and configured, you may start acquisition by calling StartAcquisition(). The device will then begin streaming signal data to your application. The BioRadio API receives the data from the BioRadio and makes it available to applications using the various Signal groups. Signal groups are collections of signals that share certain properties, such as sample rate or physical location on the device. Each signal group contains zero or more signals, based on the configuration of the device. There are various ways to retrieve the data from the signals, based on your application requirements. A common method that can be used for this purpose is GetScaledValueArray().

{C#}
//Start acquisition and display the scaled values. (for 20 seconds)
Console.WriteLine("Feel free to press a BioRadio button");
DateTime endTime = DateTime.Now.AddSeconds(20);
_device.StartAcquisition();
bool continueLoop = true;
while (DateTime.Now < endTime && continueLoop)
{
foreach (var signalGroup in _device.SignalGroups)
{
foreach (BioRadioSignal signal in signalGroup)
{
var samples = signal.GetScaledValueArray();
foreach (var val in samples)
{
Console.Write(val.ToString("##.#### "));
}
}
}
}
_device.StopAcquisition();
_device.Disconnect();
.

Memory Mode

      Data recorded to the BioRadio internal memory can be consumed using this API. To get started, create a VirtualDeviceAdapter using CreateVirtualDevice(String). The VirtualDeviceAdapter serves as a wrapper around a device object from which data can be read.

{C#}
//Using a DAT file - ex:8F142215.DAT
Console.WriteLine("Will now try to open a dat file");
var virtualDevice = mgr.CreateVirtualDevice(GetExternalFilesDir(null) + @"/8F142215.DAT");
var deviceInstance = (BioRadioDevice)virtualDevice.BaseDevice;
// Loop over the file until we reach the end.
while (!virtualDevice.EndOfFileReached)
{
// Feed the next chunk of file data. This causes the VirtualDeviceAdapter to parse the next set
// of data and make it available on its BaseDevice's Signal instances.
virtualDevice.FeedNextChunk(10240);
// Iterate through the BioPotential signals and read all samples.
// This example assumes the input file only contains biopotential data, and no data in the other device signal groups.
foreach (var signal in deviceInstance.BioPotentialSignals)
{
var data = signal.GetScaledValueArray();
foreach (var value in data)
{
Console.Write("{0} ", value);
}
}
}
.