-2

enter image description here

Can somebody help me to extract the data from value field in

I want to just show bytes data. Read method

            public async Task<NSData> ReadValue(CBPeripheral peripheral, CBCharacteristic characteristic)
    {
        BTProgressHUD.Show("Loading...", 1000, ProgressHUD.MaskType.Gradient);
        var taskCompletion = new TaskCompletionSource<bool>();
        var task = taskCompletion.Task;
        EventHandler<CBCharacteristicEventArgs> handler = (s, e) =>
        {
            if (e.Characteristic.UUID?.Uuid == characteristic.UUID?.Uuid)
            {
               // e.Characteristic.Value = characteristic.Value;
                taskCompletion.SetResult(true);
            }
        };

        try
        {
            peripheral.UpdatedCharacterteristicValue += handler;
            System.Threading.Thread.Sleep(900);

            peripheral.ReadValue(characteristic);

            BTProgressHUD.Dismiss();
            await Task.Delay(200);

            return characteristic.Value;

        }
        finally
        {

//to get the updated characteristics value.

            peripheral.UpdatedCharacterteristicValue -= handler;
            BTProgressHUD.Dismiss();
        }
    }
zombie
  • 59
  • 1
  • 10
  • Did you do a readValue and get the delegate method to be called? – Larme Apr 01 '20 at 10:13
  • @Larme yes i did. – zombie Apr 01 '20 at 10:28
  • And that's the screenshot from where? From that delegate method? Could you print exactly the value of the bytes (it's 87 length), not only a screenshof of the debugguer, because value should be a Data, not a String, so there is some kind of interpretation, and what is it supposed to be? – Larme Apr 01 '20 at 10:30
  • I need to get bytes = 0x22222222 22222222 22222222 22222222 ... 22222222 22222222 to be displayed – zombie Apr 01 '20 at 10:34
  • Value is a `Data` (https://learn.microsoft.com/fr-fr/dotnet/api/corebluetooth.cbcharacteristic.value?view=xamarin-ios-sdk-12#CoreBluetooth_CBCharacteristic_Value), just print it. Do no think that the debugger is not interpreting the value. – Larme Apr 01 '20 at 10:35
  • But if i am trying to get the characteristics.value it is {""""""""""""""""""""""""""""}.Note this characteristics is cbcharacteristics not cbmutable charateristics – zombie Apr 01 '20 at 10:37
  • It doesn't matter. CBMutableCharacteristic is just a mutable version of CBCharacteristic Could you add code, and from what method you are reading the value?. – Larme Apr 01 '20 at 10:38

1 Answers1

0

You could convert it to string

var value = characteristic.Value;
NSString dataValue = NSString.FromData(value, NSStringEncoding.UTF8);
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22
  • -As u can see the value field is empty.characteristic.Value is {"""""""""""""""""""""""""""""} but CBCharacteristics have the field value from which i need to get the byte=0x22222222222 data and display it – zombie Apr 01 '20 at 09:23
  • Check https://stackoverflow.com/questions/40269248/how-to-get-exact-value-from-a-cbcharacteristic – Lucas Zhang Apr 01 '20 at 09:29
  • the problem here is characteristic.Value is {"""""""""""""""""""""""""""""""""""""""} – zombie Apr 01 '20 at 09:31