Problem with mbientlab/MetaWear-SDK-CSharp-Plugin-NetStandard

edited June 26 in C#

Hello,
i installed "NetStandard2.0 plugins for the MetaWear C# SDK", and tried to activate the accelerometer, but nothing happens.
Also, it often crashes
Can you please advice?

Here is my code:

using MbientLab.MetaWear.Core;
using MbientLab.MetaWear.Data;
using MbientLab.MetaWear.NetStandard;
using MbientLab.MetaWear.Sensor;
using MbientLab.MetaWear.Sensor.AccelerometerMma8452q;
using MbientLab.MetaWear.Sensor.BarometerBosch;
using System;
using System.Threading.Tasks;

namespace MetaWear.NETCore
{
    class Program
    {
        static void Main(string[] args)
        {
            MainAsync(args).Wait();
        }

        private static async Task MainAsync(string[] args)
        {
            try
            {
                IMetaWearBoard metawear = Application.GetMetaWearBoard("F4:4A:2D:8E:65:3E");
                await metawear.InitializeAsync();

                //accelerometer

                var accelerometer = metawear.GetModule<IAccelerometer>();

                accelerometer.Configure(odr: 2f);
                await accelerometer.Acceleration.AddRouteAsync(source => source.Stream(data =>
                    Console.WriteLine(data.Value<Acceleration>())
                ));
                accelerometer.Acceleration.Start();
                accelerometer.Start();

                Console.Read();


            }
            catch (Exception e)
            {
                Console.WriteLine("error: " + e.Message);
            }
        }
    }
}

Comments

  • Hi again,
    I downloaded and tried to compile the three projects instead of reference it , and now i get this exception after running the code :
    "Unable to load DLL 'warble': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

    Can you please advice?
    Erez

    • Provide more details about the crash. Simply saying that your app crashes does not provide any information to work off of.
    • Use the Win10 plugin if you're building a Win10 app.
    • Your sample code is setting the odr to 2Hz.
  • Hi Eric.
    Thanks for the replay!
    I using NetStandard cause i need the Dlls in Unity, and i cant use your Win10 app.in Unity cause Unity DOES NOT support Windows.Device.Bluetooth. Do i miss something?

    Regarding crashes: Only once in ~10 attempts, i am abling to see data coming to the sensor. All other time the app simply crashes after i press "play" . Below is a screenshot. Do i miss something ? how can i provide you more Info?

    Also, i was able to connect the sensor to Unity , but again the editor crashes each time, and just every 10 times i able to get data in Unity from the sensor

    I appreciate any help cause being able to get data in Unity is critical for us.

  • Hi Eric,
    I found the problem- it is in the C project. Trace and sceenshot is below :
    As you can see - the error is " The process cannot access the file because it is being used by another process"
    This explains why the code is working sometimes and sometimes not. no
    Is this enough info for you?

    Trace:
    'example-connect.exe' (Win32): Loaded 'F:\Erez\Dropbox\Personal\Research2018\PLAYWORK\MBIENTLAB\Warble.CPP\vs2017\x64\Debug\example-connect.exe'. Symbols loaded.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'F:\Erez\Dropbox\Personal\Research2018\PLAYWORK\MBIENTLAB\Warble.CPP\vs2017\x64\Debug\warble.dll'. Symbols loaded.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\vccorlib140d.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Devices.Bluetooth.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Networking.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Networking.HostName.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\biwinrt.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Networking.Connectivity.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Networking.HostName.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Unloaded 'C:\Windows\System32\Windows.Networking.HostName.dll'
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\FirewallAPI.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\fwbase.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Devices.Enumeration.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\deviceassociation.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\propsys.dll'. Cannot find or open the PDB file.
    'example-connect.exe' (Win32): Loaded 'C:\Windows\System32\Microsoft.Bluetooth.Proxy.dll'. Cannot find or open the PDB file.
    onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1291)\Windows.Devices.Bluetooth.dll!00007FFEB81CE481: (caller: 00007FFEB81CDC0E) Exception(1) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1102)\Windows.Devices.Bluetooth.dll!00007FFEB827EFA0: (caller: 00007FFEB81D0490) ReturnHr(1) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    Msg:[onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1291)\Windows.Devices.Bluetooth.dll!00007FFEB81CE481: (caller: 00007FFEB81CDC0E) Exception(1) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    ]
    onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1750)\Windows.Devices.Bluetooth.dll!00007FFEB81D04B2: (caller: 00007FFEB81D4B42) Exception(2) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1868)\Windows.Devices.Bluetooth.dll!00007FFEB827F6E8: (caller: 00007FFEB81D4B42) ReturnHr(2) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(795)\Windows.Devices.Bluetooth.dll!00007FFEB81D4B61: (caller: 00007FFEB81D6A6A) ReturnHr(3) tid(1564) 80070020 The process cannot access the file because it is being used by another process.
    Exception thrown at 0x00007FFEEE1C4008 in example-connect.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000A4B09FDBE0.
    Exception thrown at 0x00007FFEEE1C4008 in example-connect.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
    Exception thrown at 0x00007FFEEE1C4008 in example-connect.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000A4B09FDD80.
    Exception thrown at 0x00007FFEEE1C4008 in example-connect.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
    Exception thrown at 0x00007FFEEE1C4008 (KernelBase.dll) in example-connect.exe: WinRT originate error - 0x80070020 : 'The process cannot access the file because it is being used by another process.'.
    Exception thrown at 0x00007FFEEE1C4008 in example-connect.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x000000A4B0AFD970.

  • BTW, i have Windows 10 OS, with CSR CSR8510 A10 Dongle connected.

  • edited June 28

    Which line of code is causing the exception? Your screen shot doesn't show me anything other than that the std::exception class is working as described.

    What are the steps to reproduce this exception? I have not run into this specific exception when testing on my machine. The underlying code is not doing anything fancy, just calling the Windows BLE functions.

  • Hello Eric,
    1. The lines of code are (i think) 209-210 at the win10_api.cpp. I used the example-connect test project to repreduce the error- i sent the mac as parameter and run it few times. As you can see in video , sometimes its ok , and sometimes crashes.
    2.Here is a video i recorded with reproduce the error:
    https://drive.google.com/file/d/1jevNrhSj8UqTeajeOvKYs_SZxZO0hB4-/view?usp=sharing

  • edited June 29

    Those lines of code are just exception handling code. You need to determine which async task is returning the exception, that is ultimately being thrown by previous.wait();

    Regarding your video, I am unable reproduce the error by continually running the example program in VS2017 as you do in the video. It could be something with your adapter or Windows install but it is not affecting my machine. Do you have other Windows 10 machines and/or adapters you can test with?

  • Yes.
    1.what about my trace i put?
    2.When i run it using consoleApp i get this error:

    SO i tried to open "warble.dll " with dependency walker:

    1. I am not sure what you are asking here.
    2. Which console app project are you referring to? You have been able to run the example C projects so you should already have the required DLLs installed.
  • I pushed some changes to the C library, give them a try.

  • edited July 7

    Hi Eric,
    I tried the modified C project. and i still get the error ("Unable to load DLL warble.dll..."). I will try to explain better what i did:
    1. in order to test the connection to BLE in Windows, i created "hello world" console app. you can download it here . please note that this console uses MbientLab.MetaWear.dll, warble.dll , MbientLab.MetaWear.NetStandard.dll , Warble.NetStandard.dll. The app is working on DEV computers (i.e. SDKs are installed on the computer).[ However, if I try to run it twice in a raw, it is not connecting properly to the sensor maybe it is related to the "disconnect" method? is it taking some time for the sensor to disconnect properly ?]
    2. I published the app in a self-contained folder, and run it on "clean" win 10 computer (without SDKs installed) , and get the error. you can download the publish folder it here , just double-click the "console1.exe" Note that i manually put the warble.dll at the exe folder. I assume the app is looking for some dependencies?
    3. i put all DLLs in "Plugins/Assets" folder in Unity, but the app is crashing after calling "InitializeAsync" [this is another problem]
    Thanks!

  • edited July 9

    I do not understand why the first thing you do is call DisconnectAsync since the device is not connected. Furthermore, you are never stopping the sensors, so you are leaving them continually attempting to stream data upon app termination.

    I'm not sure what's wrong with your project but I highly doubt it is the native dll; you can check this by running the example C++ projects on your other machine. Those missing dlls in your screenshot are just shims that get resolved to another dll by Windows so they don't exist anyways.

  • edited July 12

    Hello Eric,
    i found the missing DLLs ( just copied missing DLLs after using "dependency-walker" tool). However, i still have connection problems:
    1. I cant connect to MetamotionR two times in a raw: i running the code below - i fixed the disconnect method upon your comment , and now (i think) i disconnect it properly . However, the second time i running the code i get exception "error: Failed to discover gatt characteristics". (see figure below - This comes from the C library you published at 21.6) . Please let me know if this code is OK. Should i wait some time after disconnect? do i miss something ?

    1. Also, my MetamotionR cannot be discovered any more even from MetaBAse app (please see figure below - it is "disconnected", however, i can connect it with code) . For example - Yesterday all day i couldn't discover it even with nRF sniffer, and today i could discover it ( only in code) . Do i miss something ?
    2. Will you have Unity SDK ( a whole package, not just DLLs) ?
      Thanks,

    *****CODE:
    using MbientLab.MetaWear;
    using MbientLab.MetaWear.Core;
    using MbientLab.MetaWear.Data;
    using MbientLab.MetaWear.NetStandard;
    using MbientLab.MetaWear.Sensor;
    using MbientLab.MetaWear.Sensor.AccelerometerMma8452q;
    using MbientLab.MetaWear.Sensor.BarometerBosch;
    using System;
    using System.Threading.Tasks;

    namespace MetaWear.NETCore
    {
    class Program
    {
    static void Main(string[] args)
    {
    MainAsync(args).Wait();
    }

        private static async Task MainAsync(string[] args)
        {
            try
            {
    
               Console.WriteLine("Insert mac[erez - F4:4A:2D:8E:65:3E] : ");
                string mc = Console.ReadLine();
                IMetaWearBoard metawear = Application.GetMetaWearBoard(mc);
               // var deviceInfo = await metawear.ReadDeviceInformationAsync();
                  await metawear.InitializeAsync();
    
                //accelerometer
    
                var accelerometer = metawear.GetModule<IAccelerometer>();
    
                accelerometer.Configure(odr:   1
                    );
                await accelerometer.Acceleration.AddRouteAsync(source => source.Stream(data =>
                    Console.WriteLine("Accelerometer = " + data.Value<Acceleration>())
                ));
                accelerometer.Acceleration.Start();
                accelerometer.Start();
    
    
                //pressure 
    
                IBarometerBmp280 barometer = metawear.GetModule<IBarometerBmp280>();
                barometer.Configure(os: MbientLab.MetaWear.Sensor.BarometerBosch.Oversampling.Standard, coeff: IirFilerCoeff._16, standbyTime: 0.5f);
    
                await barometer.Pressure.AddRouteAsync(source => source.Stream(data => Console.WriteLine("Pressure (Pa) = "
                   + data.Value<float>())));
                barometer.Pressure.Start();
                barometer.Start();
    
                //Quaternion
                var sensorFusion = metawear.GetModule<ISensorFusionBosch>();
                sensorFusion.Configure();
                await sensorFusion.Quaternion.AddRouteAsync(source => source.Stream(data =>
                {
                    var quat = data.Value<Quaternion>();
                    Console.WriteLine("Quaternion = " + quat);
                }));
                sensorFusion.Quaternion.Start();
                sensorFusion.Start();
    
    
                Console.ReadLine();
    
                //stop 
                accelerometer.Acceleration.Stop();
                accelerometer.Stop();
                barometer.Pressure.Stop();
                barometer.Stop();
                sensorFusion.Quaternion.Stop();
                sensorFusion.Stop();
                metawear.TearDown();
                await metawear.GetModule<IDebug>().DisconnectAsync();
    
    
            }
            catch (Exception e)
            {
                Console.WriteLine("error: " + e.Message);
                Console.Read();
            }
        }
    }
    

    }

  • edited July 16
    1. Add some code that retries ``InitializeAsync`. Do you see the same error if you are directly using the C code?
    2. I've never seen that behavior before. I have encountered times where Windows will keep the connection open, but in those cases, you cannot reconnect to the board as well until you restart the BT adapter. On Windows, the best bet is to use the disconnect method from the IDebug interface, which it looks like you are already doing.
    3. No, there is no point in uploading the same files multiple times to different hosting services. Ideally, Unity should integrate NuGet support into the IDE, similar to how Visual Studio does it



    Also, please wrap your posted code with code tags so it is rendered correctly on the forums.

Sign In or Register to comment.