unity-game-enginemicrosoft-band

Is it possible to use MS Band with Unity standalone Windows build?


I'm trying to figure out the quickest way to get data from the MS Band 2 into a Unity standalone Windows build with VR support. I'm able to build and run the SDK sample apps on my Win10 laptop, and they work.

I've tried various things, ranging from importing the Microsoft.Band.DLL into Unity as a managed plugin, to trying to wrap the Band DLL in a native plugin. However, I have not found a way to make this work. I'm starting to suspect that I simply will not be able to get the Band DLL to work with a standalone Windows build, for a number of reasons.

When I try to use the Band DLL as a managed plugin, Unity doesn't support C# 4 which is required by the Band DLL. When I try to create a native DLL, I can't figure out how to create a project in VS2015 that will work with the Band SDK, and I can't change the sample projects to output a DLL instead of an app. When I try a new project that can output a DLL, and try to install the Microsoft.Band NuGet package, it tells me that my project targets 'native,Version=v0.0' even though the SDK version is 10.*.

Ideally, there would be a way to include required DLLs with the Band DLL in Unity, and I could access it as a managed plugin. But I'd even be happy with wrapping a C++ file in extern "C" and making a separate function to return each piece of data from the Band.

I simply am not familiar enough with the Universal Windows concept to know if there is a way to make it work with a Unity standalone Windows build, or if it is intentionally prevented from working that way. Since they both run on the same machine, it seems like this should be possible.

My fallback plan is to write a Universal Windows app that reads the device data, and have that connect to the Unity standalone Windows app to give access to it. Whether that's through a local file, network connection, or remote server is another problem altogether.


Solution

  • The best way of doing this is to use C++ to make a wrapper around the MS Band but that is not an option in this case because Microsoft does not have a C++ API for MS Band and their website is full of requests from programmers asking for C++ support since late 2015, which they ignored. You still have 4 other options that may or may not work.

    1. Try Unity C# 5.0 and 6.0 Integration https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration/src This will let you use C# >4 with Unity. How to Set it up is on the page.

    2. Use Local Interprocess Communication. Make a console plugin with C# and build the project as C# with Visual Studio instead of Unity. Compile it to exe instead of DLL and call it MSBandLIC.exe. Write all your code that communicates with the MS Band in this program.

      Start the MSBandLIC.exe program from your Unity program.

      You can then use Anonymous Pipes to communicate with the MSBandLIC.exe from Unity. The code is long but easy to write. Here is a link from Microsoft on how or do this. https://msdn.microsoft.com/en-us/library/bb546102.aspx

    3. TCP Console Plugin

      Make a console plugin with C# and build the project as C# with Visual Studio instead of Unity. Compile it to exe instead of DLL and call it MSBandTCP.exe.

      Start the MSBandTCP.exe program from your Unity program.Write all your code communicates with the MS Band in this program then create a TCP server listening to port 5550.

      On Unity side, use TCP to connect to your local machine with port 5550 and there you can communicate and receive information from MS Band.

    4. Reverse-Engineer the API and make your simple API with the functions you need to access from the MS Band. It looks like MS Band communicates with computer/mobile phones through Bluetooth. Bluefruit LE Sniffer and Wireshark should help you accomplish this.

      How do this:

      Choose a functions that you need from the MS Band API. Write a C# App without Unity that sends a message to the MS Band in while loop everything 2 seconds. Use Bluefruit LE Sniffer and Wireshark to see what message is going from Windows to the MS Band. MS Band should respond, if it does but what it sent is encrypted, use JustDecompile to de-compile the DLL part of the API and figure out how the API de-compiles bytes it receives from the MS Band. You can then reconstruct your own API from what information you gathered.