I am working on a Xamarin.Forms app, to connect to a bluetooth device and then to select a known service the device is broadcasting. I am using the Monkey.Robotics plugin, which contains an adaptor. That triggers certain Async events, such as DeviceConnected, once this happens I then want to be able to reference the device id variable, so that I can scan for the services. How do I get the device variable from the NewDeviceButton.Clicked code, to the DeviceConnected code? Bear in mind that I would rather not modify the adapter, as it comes with the component, and I would rather not miss out on future updates.
-
namespace Gas_Sense
-
{
-
public partial class HomePage : ContentPage
-
{
-
-
IAdapter adapter;
-
{
-
InitializeComponent ();
-
this.adapter = adapter;
-
this.devices = new ObservableCollection<IDevice>();
-
-
NewDeviceButton.Clicked += async (sender, e) => {
-
-
adapter.StartScanningForDevices (0x180D.UuidFromPartial ());
-
//rest of the choose correct device code
-
-
adapter.ConnectToDevice (device);
-
}
-
};
-
-
adapter.DeviceConnected += (s, e) => {
-
-
device.DiscoverServices ();
-
-
};
-
-
}
-
}
-
}
-
Thanks very much.