Skip to content
Snippets Groups Projects

App now has a basic structure and BLE support

Merged plw1g21 requested to merge app-bluetooth-connection into main
4 files
+ 87
11
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -346,21 +346,36 @@ namespace RobobinApp.ViewModels
_connectedDevice = await TryConnectAsync(Guid.Parse(SelectedDevice.MacAddress));
Debug.WriteLine($"Successfully connected to {SelectedDevice.Name}.");
// Try to get services
var services = await _connectedDevice.GetServicesAsync();
if (services != null && services.Count > 0)
// Iterate through the discovered services
foreach (var service in services)
{
foreach (var service in services)
Debug.WriteLine($"Service: ID={service.Id}, Name={service.Name}");
// Check if this is the Generic Access service
if (service.Id == Guid.Parse("00001800-0000-1000-8000-00805f9b34fb"))
{
Debug.WriteLine($"Service: ID={service.Id}, Name={service.Name}");
Debug.WriteLine("Found Generic Access service!");
// Get the characteristic for the device name
var deviceNameCharacteristic = service.GetCharacteristicAsync(Guid.Parse("00002a00-0000-1000-8000-00805f9b34fb"));
if (deviceNameCharacteristic != null)
{
// Read the device name characteristic
Debug.WriteLine($"Device Name: {deviceNameCharacteristic}");
await Application.Current.MainPage.DisplayAlert("Device Name", $"Device Name: Paul", "OK");
}
else
{
Debug.WriteLine("Device name characteristic not found.");
}
}
}
else
{
Debug.WriteLine("No services found.");
}
// Optional: Handle other services or characteristics if needed
}
catch (DeviceConnectionException ex)
{
@@ -381,8 +396,6 @@ namespace RobobinApp.ViewModels
}
}
private async void OnDisconnect()
{
if (_connectedDevice != null)
Loading