A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
connected Device Get Service always return null
Babu R
81
Reputation points
I want to connect bluetooth device (JDY-23) for serial communication and my device is connecting and shows id also.
But when I tried to get service it always return null. Is there any problem with my code below
var adapter = CrossBluetoothLE.Current.Adapter;
var ble = CrossBluetoothLE.Current;
adapter.ScanTimeout = 2000;
adapter.ScanMode = Plugin.BLE.Abstractions.Contracts.ScanMode.LowPower;
await adapter.StartScanningForDevicesAsync();
if (adapter.DiscoveredDevices.Count == 0)
{
string text = "Unable to find Bluetooth";
lbl.Text = text;
return;
}
else
{
string text = "Found Devices";
lbl.Text = text;
IDevice device = adapter.DiscoveredDevices.Where(x => x.Name == "JDY-23").FirstOrDefault();
if (device != null)
{
var connectedDevice = await adapter.ConnectToKnownDeviceAsync(device.Id);
lbl_Device.Text = device.Name;
var service = await connectedDevice.GetServiceAsync(device.Id);
var characteristic = await service.GetCharacteristicAsync(device.Id);
var bytes = await characteristic.ReadAsync();
//await characteristic.WriteAsync();
}
}
Developer technologies | .NET | .NET Multi-platform App UI
Developer technologies | .NET | .NET Multi-platform App UI
Sign in to answer