1

I am using BLE device with respect to Xamarin.Forms. Can you please help to resolve the below issue? I am using this Package

Steps to reproduce

  1. After scanning I have some set of devices . I am selecting the device. After selecting, i am connecting to that device.

  2. I got some list of services. so i am iterating one service and i got that service characteristics

  3. I got some list of characteristics. I am iterating first characteristics and reading. Application crashed.

Expected behavior

Tell us what should happen

Actual behavior

Instead of crash, it should read and give bytes

Crashlog

Excepotion is not thrown. These are the details i got in output screen

12-20 17:54:18.170 D/BluetoothGatt(20372): onConnectionUpdated() - Device=98:07:2D:45:76:83 interval=39 latency=0 timeout=500 status=0
12-20 17:54:22.020 D/BluetoothGatt(20372): onConnectionUpdated() - Device=98:07:2D:45:76:83 interval=798 latency=0 timeout=1000 status=0
12-20 17:54:22.290 I/Choreographer(20372): Skipped 248 frames!  The application may be doing too much work on its main thread.
12-20 17:54:22.292 W/Looper  (20372): Slow Frame: doFrame is 4148ms late
12-20 17:54:24.763 F/        (20372): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mono/mini/debugger-agent.c:4931, condition `is_ok (error)' not met, function:get_this_async_id, Could not execute the method because the containing type is not fully instantiated. assembly:<unknown assembly> type:<unknown type> member:(null)

Configuration

Version of the Plugin: e.g. 2.1.1 (Latest)

Platform: Android 8.1 API - 27

Device: Redmi Note

Xamarin.Forms: 4.4.0.991265(Latest)

I couldn't attach sample. Here are my snippets

private async void Button_Clicked(object sender, EventArgs e)
        {
            var services = await _connectedDevice.GetServicesAsync();
            if (services != null)
            {
                var characteristics = await services[0].GetCharacteristicsAsync();
                if (characteristics != null)
                {
                    foreach (var character in characteristics)
                   {
                                var byteValue = await character.ReadAsync(); /// Crashed while reading this line
                                 var str = Encoding.UTF8.GetString(byteValue);
                                 output.Text = str;
                            }                  
                }
            }
}

Thanks in advance

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
rizwika
  • 115
  • 1
  • 8
  • Try to change your log level to "Diagnostics" and really try to get more information from before the crash. The first is not a crash, so you can figure this out. Perhaps you can also use a profiler. Also, try to invoke this line on main thread: `var byteValue = await character.ReadAsync();` – Saamer Dec 20 '19 at 21:26
  • i have invoked in main thread also. the same crash. it couldn't read it. 12-21 11:29:28.585 F/ (32560): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mono/mini/debugger-agent.c:4931, condition `is_ok (error)' not met, function:get_this_async_id, Could not execute the method because the containing type is not fully instantiated. assembly: type: member:(null) 12-21 11:29:28.586 F/libc (32560): Fatal signal 6 (SIGABRT), code -6 in tid 32560 (e.Bluetoothdemo), pid 32560 (e.Bluetoothdemo) – rizwika Dec 21 '19 at 06:00
  • Resolved pending breakpoint at 'Characteristic.cs:47,1' to void Plugin.BLE.Android.Characteristic.d__17.MoveNext () [0x00011]. Resolved pending breakpoint at 'Characteristic.cs:54,1' to void Plugin.BLE.Android.Characteristic.<>c__DisplayClass17_0.b__6 (object sender, Plugin.BLE.Android.CallbackEventArgs.CharacteristicReadCallbackEventArgs args) [0x00023]. Resolved pending breakpoint at 'Characteristic.cs:61,1' to void Plugin.BLE.Android.Characteristic.<>c__DisplayClass17_1.b__7 (object sender, System.EventArgs args) [0x00001]. – rizwika Dec 21 '19 at 06:01

1 Answers1

0

If i read the characteristics through ViewModel it is working good. Instead of button click , i created a set of services in listview and on item tapped , i am listing out set of characteristics and then i am reading

rizwika
  • 115
  • 1
  • 8