And, another odd issue:
Okay, when attempting to connect two device:
InitializeAsync() seems to cause the following error:
Managed Debugging Assistant 'CallbackOnCollectedDelegate'
A callback was made on a garbage collected delegate of type 'Warble.NetStandard!MbientLab.Warble.Bindings+FnVoid_IntPtr_WarbleGattP_CharP::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
This happens when I have a first device running and streaming data, and then try to connect to a second device.
This error type breaks the system, even when inside a TRY container.
Also, it only happens "sometimes".
I'm thinking it might have to do with the await?
async public Task<bool> Connect()
{
if (string.IsNullOrEmpty(deviceMac))
{
// no mac address to process? What are we supposed to do with this?
Console.WriteLine("No mac address assigned...");
return false;
}
try
{
connecting = true;
if (device == null)
{
device = MbientLab.MetaWear.NetStandard.Application.GetMetaWearBoard(deviceMac);
device.TimeForResponse = 10000;
Console.WriteLine("connecting to " + deviceMac);
Console.WriteLine("connecting..." + device.IsConnected);
}
if (device.IsConnected)
{
Console.WriteLine("Already Connected!");
led = device.GetModule<ILed>();
//lateralAccelerometer = device.GetModule<IAccelerometer>();
if (rotationalAccelerometer == null)
rotationalAccelerometer = device.GetModule<ISensorFusionBosch>();
connecting = false;
return true;
}
Console.WriteLine("InitializeAsync Starting!");
await device.InitializeAsync(); // crash happens here, possibly due to the await?
Console.WriteLine("connected!");
Console.WriteLine("Model: " + device.ModelString);
led = device.GetModule<ILed>();
if (rotationalAccelerometer == null)
rotationalAccelerometer = device.GetModule<ISensorFusionBosch>();
connecting = false;
return true;
}
catch (Exception e)
{
Console.WriteLine("Crash Error!");
Console.WriteLine(e + "\n");
connecting = false;
return false;
}
}
Comments
Does this .net core tutorial work for you?
https://mbientlab.com/tutorials/WCS.html#stream-multiple-accelerometers
What environment are you running your code in?
Your code snippet involves a lot of other class variables. Isolate your code into a self contained static method that can reproduce this issue.
I passed the whole class in the other thread, and while I can rebuild the whole thing as a series of static classes, that's a whole new rebuild. If that's the only way it'll work, that's fine, but I was kind of hoping to figure out the why, as opposed to rebuilding a whole new design method?
Huh. Okay, rewrote the code for this:
Same error set, at the same InitializeAsync() point.
InitializeAsync Starting!
Managed Debugging Assistant 'CallbackOnCollectedDelegate'
A callback was made on a garbage collected delegate of type 'Warble.NetStandard!MbientLab.Warble.Bindings+FnVoid_IntPtr_WarbleGattP_CharP::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
I don't care about non-MetaWear code. Use the provided function definition and answer questions 1 and 2 from my previous post.
Another question for you: