mbientlab / MetaWear-SDK-CSharp

MetaMotion / MetaWear .NET Standard 2.0 SDK for Windows/Linux

Home Page:https://mbientlab.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logging not working

StefaanAvonds opened this issue · comments

In my Xamarin.Forms UWP application I'm trying to get the logging-module to work, however exceptions are always thrown by the SDK. By looking at the code, I saw something odd:

In class "MbientLab.MetaWear.Impl.Logging" there is an internal method, called "CreateLoggersAsync'. In here a TimedTask is executed which - for what I'm able to see - can never return a correct value.

var id = await createLoggerTask.Execute("Did not receive logger id within {0}ms", bridge.TimeForResponse, () => bridge.sendCommand(command));

A command is send to the MetaWear-sensor, but never is a result initialized for the TimedTask. This will automatically result in a TimeOut, or an infinite wait because no result is ever set. I got around this by adding following code (although I have no idea that this is the correct approach):

var id = await createLoggerTask.Execute("Did not receive logger id within {0}ms", bridge.TimeForResponse, () =>
                        {
                            bridge.sendCommand(command);
                            createLoggerTask.SetResult(i);
                        });

When the logs ought to be downloaded the same problem occurs. In the same class in method "DownloadAsyncInner" another TimedTask is executed without ever initializing a result to it:


            var entriesResponse = await queryEntriesTask.Execute("Current log usage not received within {0}ms", bridge.TimeForResponse,
                () => bridge.sendCommand(new byte[] { (byte)LOGGING, Util.setRead(LENGTH) })
            );

So again this always thrown an exception, or wait until the result is set which never will.

Am I missing something, or is it not possible to log using current SDK version (1.0.15)?

If it weren't possible to log, then MetaBase wouldn't be working, nor would the unit tests pass. See if you can log data with the aforementioned app on your Win10 machine.

Were you ever able to log data with the C# SDK? If so, what was the last working version for you? Can you log data if you are building a .NET Core app or a non-xamarin UWP app?

Add some logging to the IBluetoothLeGatt.WriteCharacteristicAsync implementation to confirm that the values are successfully being written to the remote device.

I was able to log using one of the previous versions (v0.3.0 if I'm correct).

The implementation of WriteCharacteristicAsync does receive a response containing correct values, so no problems there.
Just for fun, I tried TearDown right after connecting with the sensor. With this, logging (and downloading) suddenly works.

Is it a good idea to always call TearDown after connecting?

No, see the documentation:
https://mbientlab.com/csdocs/0/metawearboard.html#tear-down

What you described sounds like you never cleaned up the board after you were done logging.