Problem with mbientlab/MetaWear-SDK-CSharp-Plugin-NetStandard
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);
}
}
}
}
This discussion has been closed.
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
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.
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
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:
I pushed some changes to the C library, give them a try.
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!
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.
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 ?
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();
}
}
IDebug
interface, which it looks like you are already doing.Also, please wrap your posted code with code tags so it is rendered correctly on the forums.
Hello Eric,
1. I responding now because it took us some time to perform comprehensive tests on the components. We retried InitializeAsync and ended up with performing three levels of testing, in each we try to perform sequences of "connect, "disconnect" , and loop of "connect"-disconnect":
1. level 1 - "example-connect" in Warble (with latest commits) with success.
2. level 2 - "Example.Connect" (the WRAPPER) with success.
3. level 3 - testing MetaWear.NetStandard using "InitializeAsync" and "disconnectAsync" (even without strating the sensors) . Here we found some issues : in short, we cannot achieve two success "InitializeAsync" and "disconnectAsync" connections is a raw. Sometimes even the first InitializeAsync throw the exception "Failed to discover gatt characteristics" . So, i tried to do something different : this time i first call InitializeAsync , and on the second time i tried to connect to the C++ Gatt connect, but it still throws the exception.
My conclusion is that something in the C++ prevent the second connect in a raw, when the first connect is always InitializeAsync (cause the warble and the wrapper are working fine)
I attach the tester i used. Below is the code. You can see that i first call to InitializeAsync and then to the Gatt and always get exception.
Also - maybe this bug is related to the other bug we have and described [here] on parallel post ?
(https://mbientlab.com/community/discussion/2601/unity-works-perfectly-with-metawear-sensor-on-first-run-hangs-on-2nd-run#latest "here")?
Running this code in a loop is my goal, so i can be sure it is working.
Thanks
Erez
Here is the code:
I pushed out some fixes to the NetStandard plugin; the new version (v1.0.5) works with your attached solution on my machine.
Read this
https://help.github.com/articles/creating-and-highlighting-code-blocks/
Hi Eric,
1. I pulled all commits for the three projects (warble, Wrapper and .Net), and** now i get "Catastrophic failure" message **when connecting. I attached the simulator i wrote to reproduce the error. Below is screenshot followed bt Log
2. Is there a way to subscribe to your commits?
Here is the logfile:
11:49:09:031 LoadBoardAttributesAsync
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
11:49:10:406 exception:Catastrophic failure
Catastrophic failure
(HRESULT = -2147418113)
Exception thrown: 'MbientLab.Warble.WarbleException' in MbientLab.MetaWear.dll
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
11:49:10:967 LoadBoardAttributesAsync
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
subscribe Exception thrown: 'MbientLab.Warble.WarbleException' in System.Private.CoreLib.dll
11:49:11:985 exception:Catastrophic failure
Hi Eric,
This error was due to firmware update to 1.4.1. somehow i had to update five times until until it was connected.
Anyway , now the sensor is not advertising at all! i cannot connect from Android nor Metabase....
How can i "wake" the sensor ? i tried to move it and restarting several times, but nothing works..
Same error here. Catastrophic failure. I'm on 1.4.1.
An update - now i cannot connect again to Metawear anymore even from MetaBase...
Hrm, I don't have any issues with your updated VS solution nor the sample C programs. My test board is also running firmware v1.4.1.
There weren't many code changes in the latest release, just commits ee4230b. and 8f3b726. Maybe your adapter does not work with uncached service discovery (first commit)? Since you are working with the source code, which line is causing the exception?
You can follow the project on GitHub.
@abcd
Try unpairing your sensor under Bluetooth settings in windows 10 and try connecting again. That did the trick for me.
Hi jimjam,
I never pairing with windows 10 , i am using the Scan method of the Warble.
This works for me now outside of Metawear but inside Unity is still freezing
MetaWear NetStandard
This plugin implements the IBluetoothLeGatt and ILibraryIO interfaces for .NET Standard2.0 compatible applications.
Developers buidling Windows 10 specific applications should use the Windows 10 plugin instead.
Install
Use the Package Manager console to install the MetaWear.CSharp.NetStandard package in addition to the MetaWear.CSharp package:
PM> Install-Package MetaWear.CSharp
PM> Install-Package MetaWear.CSharp.NetStandard
Or, manually add the entries to the *.csproj file:
Linux users will also need to compile the Warble library on their target machine and ensure that the shared library is discoverable by the dotnet application.
Usage
Call Application.GetMetaWearBoard with the MAC address of the device you are communicating with. You can use the SDK features, as outlined in the SDK developers' guide, with the returned IMetaWearBoard object.
using MbientLab.MetaWear.NetStandard;
using System;
using System.Threading.Tasks;
namespace MetaWear.NETCore {
class Program {
static void Main(string[] args) {
MainAsync(args).Wait();
}
}
Try this one. Hope it helps. Courtesy of github.