Issue reconnecting to data stream on device...
Okay, we've hammered past most issues.
We've built a network server to server data to the Unity app. Works great, but we have an issues with the stream not working a second time.
async public void StartRotationalAccelerometer(Action<string, EulerAngles> _return)
{
Console.WriteLine("StartRotationalAccelerometer");
if (device == null)
return;
Console.WriteLine("Set StartRotationalAccelerometer");
if (rotationalAccelerometer == null)
rotationalAccelerometer = device.GetModule<ISensorFusionBosch>();
_EulerAnglesReturn = _return;
Console.WriteLine("Start StartRotationalAccelerometer");
rotationalAccelerometer.Configure();
rotationalAccelerometer.EulerAngles.Start();
rotationalAccelerometer.Start();
Console.WriteLine("Stream StartRotationalAccelerometer");
//await rotationalAccelerometer.EulerAngles.AddRouteAsync(null);
await rotationalAccelerometer.EulerAngles.AddRouteAsync(ReturnStream2);
}
Then it goes to:
public void ReturnStream2(MbientLab.MetaWear.Builder.IRouteComponent _data)
{
Console.WriteLine("Stream2 StartRotationalAccelerometer");
_data.Stream(ReturnStream3);
}
public void ReturnStream3(IData _data)
{
Console.WriteLine("Stream3 StartRotationalAccelerometer");
EulerAngles sample = _data.Value<EulerAngles>();
if (_EulerAnglesReturn != null)
_EulerAnglesReturn.Invoke(deviceMac, sample);
}
When I close the device:
async public void StopRotationalAccelerometer()
{
if (device == null)
return;
if (rotationalAccelerometer == null)
rotationalAccelerometer = device.GetModule<ISensorFusionBosch>();
_EulerAnglesReturn = null;
// break linkup...
await rotationalAccelerometer.EulerAngles.AddRouteAsync(source => source.Stream(null));
// Put accelerometer back into standby mode
rotationalAccelerometer.Stop();
// Stop accelerationi data
rotationalAccelerometer.EulerAngles.Stop();
// break linkup...
await rotationalAccelerometer.EulerAngles.AddRouteAsync(source => source.Stream(null));
}
Sadly, the code works fine the first time, but after that, it never gets a stream again.
Anything I'm missing?
Comments
Why are you continually adding routes instead of removing them?
What behaves differently in your code between the first run and subsequent runs?
Same as in the other thread, isolate your code into a self contained static function that reproduces the behavior.
Simple. I never found a way to remove routes. Even the samples I found have addition of null routes. I can't even find a usable method for route removal.
Can I ask why you want it static, as opposed as in a storage class? Generally, I have the whole kit as follows:
namespace mbientlab_BridgeServer
{
public class MbientLabDevice
{
public IMetaWearBoard device;
public ILed led;
public ISensorFusionBosch rotationalAccelerometer;
}
Generally, the whole kit is stored in a variable for each device, so they can work independently.
I will see if I can narrow the effect, as well.
addRoute
does not remove routes, the documentation clearly states what it does.https://github.com/mbientlab/MetaWear-SDK-CSharp/blob/1.2.0/MetaWear/IDataProducer.cs#L12
https://mbientlab.com/csdocs/1/metawearboard.html#tear-down
https://github.com/mbientlab/MetaWear-SDK-CSharp/blob/1.2.0/MetaWear/IRoute.cs
For now, I don't care about your non-MetaWear code. I just want a simple, self contained function that only uses MetaWear code to reproduce this issue.
Also, please answer my 2nd question from my previous post