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

  • public static void (IMetaWearBoard metawear) {
    }
    
  • 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:

        async static public Task<MbientLabDevice> Connect(MbientLabDevice _device )
        {
            if (string.IsNullOrEmpty(_device.deviceMac))
            {
                // no mac address to process?  What are we supposed to do with this?
                Console.WriteLine("No mac address assigned...");
                return _device;
            }
    
            try
            {
                _device.connecting = true;
                if (_device.device == null)
                {
                    _device.device = MbientLab.MetaWear.NetStandard.Application.GetMetaWearBoard(_device.deviceMac);
                    _device.device.TimeForResponse = 10000;
                    Console.WriteLine("connecting to " + _device.deviceMac);
                    Console.WriteLine("connecting..." + _device.device.IsConnected);
                }
    
                if (_device.device.IsConnected)
                {
                    Console.WriteLine("Already Connected!");
                    _device.led = _device.device.GetModule<ILed>();
    
                    //lateralAccelerometer = device.GetModule<IAccelerometer>();
                    if (_device.rotationalAccelerometer == null)
                        _device.rotationalAccelerometer = _device.device.GetModule<ISensorFusionBosch>();
    
                    _device.connecting = false;
                    return _device;
                }
    
                Console.WriteLine("InitializeAsync Starting!");
                await _device.device.InitializeAsync();
                Console.WriteLine("connected!");
                Console.WriteLine("Model: " + _device.device.ModelString);
    
                _device.led = _device.device.GetModule<ILed>();
                if (_device.rotationalAccelerometer == null)
                    _device.rotationalAccelerometer = _device.device.GetModule<ISensorFusionBosch>();
    
                _device.connecting = false;
                return _device;
            }
            catch (Exception e)
            {
                Console.WriteLine("Crash Error!");
                Console.WriteLine(e + "\n");
                _device.connecting = false;
                return _device;
            }
        }
    

    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:

    • Are you attempting to connect to the same board multiple times simultaneously?
Sign In or Register to comment.