Building a .exe for a metawear C sensor

Hello,

Our lab is working on a project using the gyroscopic sensor on the metawear c device.  We have downloaded the sample UWP application, which we have adapted to give us the gyroscope information.  However, we are hoping to make a more lightweight application that can run in the background and feed gyroscope information to another application.  Has anyone had any luck making a console application in visual studio for this sensor?

I had hoped it would be as simple as using NuGet to install the MetaWear.Win32 package, but when I attempt to do this I get the following error:

Could not install package 'MetaWear.Win32 0.5.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Any information would be greatly appreciated, thanks!

Comments

  • edited August 2016
    The MetaWear.Win32 package is for Win32 projects.  It sounds like you are still trying to make a .net or uwp project.

    If you're going to make a Win32 project, you'll have to use the bluetooth functions from the Bluetoothleapis.h header file.
  • To clarify I am not trying to make a uwp... I am trying to make a c# console application but I am not sure if that falls under the umbrella of a .net application.

    In any case I have tried both the win32 package and the winRT package and get the same error both times...
  • A C# console a[[lication is a .net application however you can call into Win32 dlls  I guess there could be an issue with how the nuspec file is setup.  What you can do is download the NuGet package directly and manually add the DLLs to your project.
  • It's possible that I am doing it incorrectly... but after I extract the .dll from the nuget package and add a reference to it, I get an error that tells me that a reference to the .dll could not be added.

    Is it possible that the .dll will only work with a certain .net framework?  Not ruling out the possibility that I have made an incorrect step somewhere along the way.
  • Sorry, what I mean is that the DLLs need to be discoverable by the executable, either residing in the system folder or distributed with the exe.  You then use pinvoke/dllimport to call into it.
  • That is interesting, Uldrendan ..

    Can you please tell us how do you do ble pairs and isConnect on the bluetooth in windows?

    I really like to setup something similar. But almost  impossible in Windows 10 API 

  • Eric, thanks for the tip.  We are experimenting now.  Will report back when we make some progress.
  • It would be interesting to hear any progress. It seems not that many people trying to use the bluetoothleapis with these sensors. 

    My progress so far is:
    1. I have been able to connect to the sensor with the Windows BLE API. 
    2. Compiled and linked and run with the lib/dll from the MetaWear.Win32 project version 0.7.0.

    So now I am struggling with connecting these but only this example gives a hint how to implement the read_gatt_char and write_gatt_char. But in that example read_gatt_char is empty but in the document it says that the response need to be passed on to mbl_mw_metawearboard_char_read. Is there alternative ways to setup this then? I have tested that project and it works good but it is based on 0.3.0 so it looks a bit different. 
  • I have only found Bluetooth LE tutorials for Universal Windows apps written in C#, which is what the UWP Starter project is based on.  The only resource for using BLE in a Win32 app is sample code from the MSDN forums linked by another community member.
  • So far so good with our application. I found an external nuget package that let me get the UWP bluetooth functions (nuget package is called UwpDesktop) into our C# console application, and I have used Eric method to read in the .dll once I have unzipped the nuget package. @victor let me know if you are still having trouble connecting and I can show you how I did this using the UwpDesktop package.

    @simway the only thing I can suggest is looking at the c# wrapper functions. The starter I used was this sample here. In there, MetaWearBoard.cs has the function Initialize(Fn_IntPtr_Int initDelegate) that got the sensor working for me. 

    Currently my issue is that the sensor will stop sending gyroscope data to my application when I run it through Unity. But that may be a question for another topic.

  • I actually have it running now using the Windows Bluetooth LE API. When I finally found out how to setup the notification the board (works most times) initializes correctly. Been able to control the led and read data for ambient light, accelerometer and magnetometer. It is still a simple console win32 program but will do tests also in Unity as a dll. 

    I am currently trying to use Sensor Fusion to get orientation calculated but it looks like the module internally is not setup, I guess I have to do some debugging to see what is going on.
  • Let me know if you get it working as a Unity .dll, would be very interested in seeing it.
  • Of course, I now realized that I have the CPRO Wear and not Motion so there is no Sensor Fusion chip. I have to calculate some things myself for testing and order correct product later. But that means I am done and will do some tests with Unity. I will post updates.
  • Now it is working in Unity also. It fails to start up sometimes and also seems to crash after a while but it not because of Unity I think, I need to check the dll and make sure I take care of the initialization, mem leaks and waiting for write and read operations to complete. I have been able to get both Magnetometer and Accelerometer data. So apart from stablizing the code I assume I need to make in software what the Sensor Fusion does in hardware to have the sensors correct orientation as the output. 
  • edited March 2017
    simway, are you posted your solution on asset store ? is it available somewhere ?








  • can someone help please with writing a console app (not UWP) in c# or cpp?
    how did you implement the Bluetooth connection not using the UWP libraries? 
    can someone post a sample please? all i need is a console app that get the sensor fusion data.


  • I used the UWPDesktop Nugrt 
    i didn't get the Nuget part. what Nuget should i use? how do you unzip a nuget? and what dll's should i link to?
    "What you can do is download the NuGet package directly and manually add the DLLs to your project"
  • why there is no example for using your board with a console app? 
  • https://www.nuget.org/packages/MetaWear.Win32/

    You can unzip a nuget package with any zip application, dlls are in the package.

    All official Bluetooth LE example code and documentation that we've found is for the Universal Windows Platform.  Plus, Win10 runs on desktop, mobile, and even the Raspberry Pi so any code examples should be able to run on all of those devices, which is the purpose of a UWP app.  Unless you are doing something like building a game in C# using the Unity engine, you should just build a UWP app.
  • we are trying to avoid any GUI, we need to call the app (which streams data from the sensor fusion) from another app, hence, it has to be a CLI based.

    so far, we built a c# app and added the UDPDesktop Nuget in order to use the libraries for connecting BTLE.

    we are trying to use winRT dll but cannot integrate it into the project. when we try to add a reference we are getting the following error:
    a reference "MetaWear.WinRT.dll" can't be added, Please make sure that the file is accessible and that it is a valid assembly or COM component. 
     
    we tried to reside the dll next to the .exe, but we need some guidance for how to use the dllimport. what functions should we import? all the functions that we use? Do you have a list of the dllimport that we can use?

    also, can you please advice wether we need the Win32 or the WinRT dll?

    thanks

  • You aren't building a UWP app so you need to use the Win32 DLL, which I linked in my previous post.  C# wrappers are included in the WinRT nuget package or you can retrieve them from the GitHub page.
This discussion has been closed.