adabru / BleWinrtDll

BLE for Unity 3d in Windows without UWP.
Do What The F*ck You Want To Public License
169 stars 53 forks source link

Subscribe never finishes #9

Open brunocoimbrar opened 3 years ago

brunocoimbrar commented 3 years ago

I have a custom device that I am trying to interact with and using another plugin (for android and ios) I got it to work nicely ( https://assetstore.unity.com/packages/tools/network/bluetooth-le-for-ios-tvos-and-android-26661 ) but now I am trying to get support for Windows too (and especially inside the Unity Editor for quick prototyping).

On the demo scene after selecting my device, the correct service, and the correct characteristic, hitting Subscribe does nothing (by "does nothing" I mean that "if I change it to "block: true" it just freezes the demo scene).

Any idea here?

adabru commented 3 years ago

To further investigate you can install Visual Studio Community with C++ Desktop and UWP components., modify the UUIDs in DebugBle/Program.cs and run the DebugBle program.

If it also freezes there, you can download and run the Microsoft's Bluetooth Low Energy sample and see whether that works out. If the demo works, it should be fixable in this repo.

jadware commented 2 years ago

Looking at Demo.cs line 128. This looks like the app could easily get stuck in an infinite loop (on the main thread) if PollData is doing something unexpected like trying to deal with subscribing to a characteristic that isn't subscribable. Guessing the error is here!


{
    BleApi.BLEData res = new BleApi.BLEData();
    while (BleApi.PollData(out res, false))
    {
        subcribeText.text = BitConverter.ToString(res.buf, 0, res.size);
        // subcribeText.text = Encoding.ASCII.GetString(res.buf, 0, res.size);
    }
}
adabru commented 2 years ago

This could have been fixed by https://github.com/adabru/BleWinrtDll/pull/25.