none
Windows 8.1 (Desktop) Bluetooth: GattCharacteristic.ValueChanged - Der Wert liegt außerhalb des erwarteten Bereichs. RRS feed

  • Allgemeine Diskussion

  • Hallo Leute,

    ich möchte in einer Desktop-App Daten eines Bluetooth-LE. Dazu habe ich die Namespaces

    Windows.Devices.Enumeration;
    Windows.Devices.Bluetooth.GenericAttributeProfile;
    Windows.Storage.Streams;

    in meine Windows-Forms-Anwendung eingebunden.

    Ich schaffe es auch die Services sowie die GattCharacteristics des Bluetooth-Gerätes auszulesen. Leider kommt beim Hinzufügen des EventHandlers zum Auslesen der Werte, die das Bluetooth-Gerät sendet, einen Fehler:


    ---------------------------
    Unhandled Thread Exception
    ---------------------------
    Der Wert liegt außerhalb des erwarteten Bereichs.
    
       bei Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic.add_ValueChanged(TypedEventHandler`2 valueChangedHandler)
    
       bei System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.AddEventHandler[T](Func`2 addMethod, Action`1 removeMethod, T handler)
    
       bei System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.AddEventHandler[T](Func`2 addMethod, Action`1 removeMethod, T handler)
    
       bei Bluetooth_Test.Form1.button6_Click(Object sender, EventArgs e)
    
       bei System.Windows.Forms.Control.OnClick(EventArgs e)
    
       bei System.Windows.Forms.Button.OnClick(EventArgs e)
    
       bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    
       bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    
       bei System.Windows.Forms.Control.WndProc(Message& m)
    
       bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
    
       bei System.Windows.Forms.Button.WndProc(Message& m)
    
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    
       bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ---------------------------
    OK   
    ---------------------------




    Der Code sieht bisher so aus, in der Zeile accData.ValueChanged += AccData_ValueChanged; kommt die Exception:

                ushort service = 0xfff0;
                ushort chara = 0xfff1;
    
                var findAllDevicesTask = DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(service)).AsTask();
    
                Task.WaitAll(findAllDevicesTask);
    
                foreach (var info in findAllDevicesTask.Result)
                {
                    if (info.Name.Equals("device4711", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var accService = GattDeviceService.FromIdAsync(info.Id).AsTask();
                        Task.WaitAll(accService);
                        IReadOnlyList<GattCharacteristic> characteristicList = accService.Result.GetCharacteristics(GattCharacteristic.ConvertShortIdToUuid(chara));
    
    
                        var accData = characteristicList.First();
                        if (accData != null)
                        {
                            if (accData.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Read))
                            {
                                accData.ValueChanged += AccData_ValueChanged;
                            }
                        }
                    }
                }

    Trotz langem langer Rechercher und Ausprobierens sämtlicher Services und Characterisics Ich kann mir nicht erklären woher die Exception kommt. Habt Ihr eine Idee wie ich das Problem lösen kann?

    Danke!

    Gruß Markus




    Mittwoch, 29. Juni 2016 16:12

Alle Antworten