Replies: 3 comments
-
Hi @babucr, I'm the friendly issue checker. If you think it's fine to make an exception, just ignore this message. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Its not likely that the You probably want to get all the services, which doesn't require any id, then take the id from the service you want and get it. |
Beta Was this translation helpful? Give feedback.
-
Both of these lines are a misuse of the API. If you don't know the ID of the desired service, or whether the device supports it, you might want to get the list of services first: Same for the characteristics: Once you have a service, you can retrieve the supported characteristics via: Alternatively, to find the ID of any standardized service or characteristic, check the BLE specs or the KnownServices and KnownCharacteristics classes in this library. |
Beta Was this translation helpful? Give feedback.
-
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. I am using Plugin.ble.
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; //working up to here
var service = await connectedDevice.GetServiceAsync(device.Id);
var characteristic = await service.GetCharacteristicAsync(device.Id);
var bytes = await characteristic.ReadAsync();
//await characteristic.WriteAsync();
}
}
Beta Was this translation helpful? Give feedback.
All reactions