Xamarin.Forms-support

Hi everyone

Just this week I've received my first MetaWear-sensors and got the code working for Windows 10-devices using the C# SDK. Now I want to integrate this in a Xamarin.Forms-application.
There are already a few people looking for a Xamarin integration, so I was hoping you could help me out.

I've already added the JAR-file from the Android SDK to my solution and got it to compile. A connection can be established but the Accelerometer-module cannot be initialized due to the missing "Impl"-classes.

How can I get the MetaWear SDK's to work in Xamarin?

Thanks in advance!

Comments

  • Can't you use the C# SDK in Xamarin which will save you the hassle of doing Java interop?

    Another user has already setup Java bindings, see this GitHub repo:
    https://github.com/aalmada/MetaWear.Droid


  • Unfortunately not; the C# SDK is only for Windows 10, not for PCL or netstandard.

    I did use the repo you're referring to, and got it to compile. I've even followed the documentation for Android (https://mbientlab.com/androiddocs/latest/index.html) but the code isn't working.
    For example to make a connection with the MetaWear sensor you'll have to use:
    board.connectAsync()
    In the C# code the method is called but no connection is established. Also ".continueWith(new Continuation" is never called...
  • edited September 2017
    Unfortunately I do not have any Xamarin experience.  My suggestions are to file an issue with the MetaWear.Droid project or compile / configure the C# SDK code however you need it.  The VS2017 solution already builds a dll for .NET console so maybe you don't need to do anything else except retrieve it from NuGet.
  • UPDATE
    I've got the Android-project working (partly): its LED can be turned on and all values for "AccelerometerBmi160" can be read continuously.

    However now its iOS's turn, which again fails. I've contacted Microsoft on this topic and they told me the following:
    "
    So it looks like this library was just not set up very well for parsing by Objective Sharpie or the Xam.iOS bindings generator. Some iOS libraries work out of the box, other do not and require manual binding, which may be the case here...
    "

    How can the iOS SDK be integrated into Xamarin?
  • Have you tried the manual binding suggestion provided by MSFT?
  • edited October 2017
    See here for a port of the C# SDK to Net Standard. Works on just about everything, has a dependency on aritchie/BluetoothLE, but if you setup your projects to inherit dependencies (the new VS2017 method) you won't even know about it.


    It seems to work well (I haven't implemented serialize/deserialize yet, because time & I don't need it that much).

    I've got a few issues with streaming data back from GPIO pins on android, and I haven't tested yet on iPhone (should get to that this week though).

    I'd welcome any feedback on this.
  • @FrozenKiwi: How can the SDK be used in a .NetStandard2.0-library? The NuGet cannot be installed since it only supports "net462" and "uap10.0".

    Or should I download the entire source code and add the dll's directly?
  • Sorry - I need to update the readme to make it clear - the link in the readme points to the MBientLabs SDK (which this version was forked from), not a build of my version.

    Clone the source and reference the MetaWear.NETStandard project.  I'd suggest adding it as a submodule, as the odds are moderate there are fixes still required so being able to update it easily will come in handy for you later.

    The library is built against 1.3, NetStandard2.0 is a strict superset of 1.X so there should be no problems referencing this.

    Note, there are also a few minor adjustments to this library to ease a few things - for example the InitializeAsync method takes a callback so you can update a progress counter (or some sort of visual feedback) when loading.  Makes a big difference when your wondering if the thing has hung or not.

    Let me know how you go :-).  It should be pretty similar to using the existing .Net API, but if you want I can also upload the .Net Sample projects so you have a working copy to go from.
  • @FrozenKiwi, thanks! I've just tried it in Xamarin and got it working on an Android-device!

    You really helped me out a lot!
  • @FrozenKiwi
    One problem on the iOS-side of this: none of the characteristics have the "Write"-property enabled, which means none of the modules can be instantiated. How can I enable this?
  • Hmmm... odd, there shouldn't be a difference!

    Whats the error message you get?  I'll have to get my hands on an iOS device to do some testing.
  • It seems to be a problem in method "GetKnownCharacteristics" on the iOS-side. When searching for the 2nd characteristic in the advertisement service by its IDs, the method returns the first characteristic. Due to the lack of time, I'm just searching for both characteristics on connecting and store the result in memory.
  • Hi
    I have a c# project in Xamarin and I have problem adding the mbientlibrary as reference in the project.
    When I refer to Mbientlab.Metawear.Uwp I get this error:

    Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Windows.Foundation.UniversalApiContract, Version=4.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
    File name: 'Windows.Foundation.UniversalApiContract.dll'
       at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
       at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
       at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) HoudiniAndroid
    Could the https://github.com/aalmada/MetaWear.Droid  project help and in that case how do I integrate it in my Xamarin project. 
  • Please read the thread before posting.  Your questions have already been addressed in this thread.
  • @FrozenKiwi

    This is probably an iOS issue, but once connected to a MetaWear sensor I want it to stream its data for drawing charts. However once the screen is locked, my app will simply crash because of iOS...
    How can I keep streaming even when the screen is locked?
  • Hi Stefaan,

    Sorry for the radio silence, I've had a family emergency and have been on the road for much of the past month.

    I've made a few changes to the project in the mean time though - I've updated the .Net Core version to 2.0 and there are a few improvements to the characteristics etc (thanks for that debugging tip you sent through last month!).

    I'll try to publish a new version this week, and that may improve things.  I suspect the issue is somewhat deeper than the changes I've made, but once we are both back on the same page I'll see if there is anything I can do to help you figure out whats going on.
  • No problem at all, hope it's not a dramatical emergency.

    I'm eager to testing out the new version you'll be publishing! Let me know when the update is ready.
This discussion has been closed.