adabru / BleWinrtDll

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

Write to FTMS Device #26

Open serramat opened 2 years ago

serramat commented 2 years ago

Hi, I am using your library to read the data from the BLE sensors and I was able to receive the information correctly. Now I would also need to write data on some devices (such as assigning the friction to a roller). I am using the WritePackage but I can never write! I also tried your example but without any success.

To be precise I'm trying to write on the 00002ad9-0000-1000-8000-00805f9b34fb characteristics of the 00001826-0000-1000-8000-00805f9b34fb service

Thank you so much. Matteo.

adabru commented 2 years ago

Hi @serramat , you could try the things mentioned in https://github.com/adabru/BleWinrtDll/issues/20#issuecomment-898939454 .

ShuohengZhang commented 7 months ago

Hi @serramat , you could try the things mentioned in #20 (comment) .

Hi adabru, thanks for your great work on this BLE.dll! By the way I have the similar problem as @serramat had. The whole DLL worked very well since I use it, and since October the write value is down. There's no errors but only the FTMS indoorbike doesn't react to the value it received. Specifically I want to change 2 Bytes ('0x11, 0x00, 0x00, Byte1, Byte2, 0x00, 0x00'). I tried changing GattWriteOption::WriteWithoutResponse to GattWriteOption::WriteWithResponse at https://github.com/adabru/BleWinrtDll/blob/main/BleWinrtDll/BleWinrtDll.cpp#L536 . , this doesn't work in my case, but I tried with nRF Connect on iOS system. Where I write '110000DC050000' would make the FTMS indoorbike change its inclination grade to '15' correctly. I even wrote a UWP application to test the function, and surprisingly it works. But as I use the UWP specific API, I cannot make it into a dll and import to Unity. And I'm stucking to this problem for a month but I still cannot figure out where's the problem. Could u please help me out ?

adabru commented 7 months ago

Hi @ShuohengZhang , it's good that your UWP application works. The dll in this repository is a c++ winrt wrapper for UWP code so the step from your UWP app to the dll should be small.

You can compare the UWP function calls from https://github.com/adabru/BleWinrtDll/blob/main/BleWinrtDll/BleWinrtDll.cpp with your UWP app. If your UWP app uses another API-call, you can change that in BleWinrtDll.cpp. Or you can change the API-call in your UWP app to the same as in BleWinrtDll.cpp.

As reference for converting UWP code to c++ winrt and vice versa, you can use https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cppwinrt/Scenario2_Client.cpp and https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cs Those are functionally the same.

ShuohengZhang commented 7 months ago

Hi @adabru, Thanks for your reply!! And yeah, I was a bit afraid to write a C++ DLL by myself because I don't really understand the C++ codes that well. However, I tried it with your suggestions today and looked into your codes and the samples I made (Dll_BLE.cpp). When I import this DLL into the Unity project, there is a DllNotFoundException when I already put it in the same folder as your BLEWinrtDll (I assume when this DLL can be used, so should mine). I would so appreciate hearing your suggestions!!

Best regards!

adabru commented 7 months ago

I'm not quite sure what the reason for the DllNotFoundException is. You can try to look at Unity's import settings for that file. You can also try to change the 32-bit or 64-bit setting in VS. And maybe try to ask ChatGPT.

Is your repository private? I can't access the link.

ShuohengZhang commented 7 months ago

@adabru sorry I didn’t notice that was private now u may have the access. And thanks again that you still concern about my case !