簡體   English   中英

C#uwp讀取多個值(BLE)

[英]c# uwp reading more than one value (BLE)

private async void CharacteristicReadButton_Click()
        {
             // BT_Code: Read the actual value from the device by using Uncached.
            GattReadResult result = await selectedCharacteristic.ReadValueAsync(BluetoothCacheMode.Uncached);
            if (result.Status == GattCommunicationStatus.Success)
            {
                string formattedResult = FormatValueByPresentation(result.Value, presentationFormat);

                rootPage.NotifyUser($"Read result: {formattedResult}", NotifyType.StatusMessage);  
            }
            else
            {
                rootPage.NotifyUser($"Read failed: {result.Status}", NotifyType.ErrorMessage);
            }     
        }

我有一個問題,每當我按“讀取”時,它只讀取一個值。 我已經用rfduino設置了一個mpu6050。 因此,它應該讀取x,y,z值。 但是,就我而言,它僅讀取“ z”值。 如何使其讀取所有三個值?

在我的c#中:(僅讀取z值) 在此處輸入圖片說明

在我的arduino中: 在此處輸入圖片說明

看起來問題出在FormatValueByPresentation中。 以字節數組形式返回的值,函數將其簡單格式化為int或float。

首先檢查您的特征演示格式。 然后檢查返回值的長度。

之后,可以修復您的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM