Cerberus - Would this be bad, Failed allocations?

This was a modified app that I had running on my Cerberus, but it stopped running/etc so I tried a different board and now its running again (Argon R1). I did reflash the Cerberus firmware, but to no avail. The app is a couple of different approaches to get the Grove Dust Sensor working with Gadgeteer via the Grove Expansion board (future CodeShare project). I’m wondering why I’d be getting Failed allocations, when I didn’t before. Right now I only have 1 Cerberus, an oversight I was planning on correcting on my next order as I wanted to pickup a couple more as its a killer mainboard, I just hope I didn’t kill it.

Create TS.

Loading start at 806e0e8, end 809661c

Assembly: mscorlib (4.2.0.0)Assembly: Microsoft.SPOT.Native (4.2.0.0)Assembly: Microsoft.SPOT.Hardware (4.2.0.0)
Assembly: Microsoft.SPOT.Graphics (4.2.0.0)Assembly: Microsoft.SPOT.TinyCore (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0)Assembly: Microsoft.SPOT.IO (4.2.0.0)
Assembly: System.IO (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)Assembly: Microsoft.SPOT.Net (4.2.0.0)
Assembly: System (4.2.0.0)Loading Deployment Assemblies.

Attaching deployed file.

Assembly: GHI.OSHW.Hardware (4.2.2.0)Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0)Attaching deployed file.

Assembly: GTM.GHIElectronics.SDCard (1.0.0.0)Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCerberus (1.0.5.0)Attaching deployed file.

Assembly: GTM.Seeed.GroveExpansion (1.0.0.0)Attaching deployed file.

Assembly: GTM.GHIElectronics.UsbClientDP (1.0.0.0)Attaching deployed file.

Assembly: CerberusDustSensor (1.0.0.0)Resolving.

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.OneWire.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI OSHW NETMF v4.2 SDK\Assemblies\le\GHI.OSHW.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\SDCard\NETMF 4.2\le\GTM.GHIElectronics.SDCard.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Mainboards\FEZCerberus\NETMF 4.2\le\GHIElectronics.Gadgeteer.FEZCerberus.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Seeed\Seeed .NET Gadgeteer SDK\Modules\GroveExpansion\NETMF 4.2\le\GTM.Seeed.GroveExpansion.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\UsbClientDP\NETMF 4.2\le\GTM.GHIElectronics.UsbClientDP.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Users\Blake\Documents\Visual Studio 2010\Projects\CerberusDustSensor\CerberusDustSensor\bin\Debug\le\CerberusDustSensor.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZCerberus version 1.1
Program Started
The thread ‘’ (0x3) has exited with code 0 (0x0).
Failed allocation for 514 blocks, 6168 bytes

Failed allocation for 17 blocks, 204 bytes

Failed allocation for 13 blocks, 156 bytes

Failed allocation for 39 blocks, 468 bytes

Failed allocation for 7 blocks, 84 bytes

Failed allocation for 10 blocks, 120 bytes


using System;
using System.IO;
using Gadgeteer.Interfaces;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT;
using GT = Gadgeteer;
using Gadgeteer.Modules.Seeed;
using Gadgeteer.Modules.LoveElectronics;

namespace CerberusDustSensor
{
    public partial class Program
    {
        private static string _dataFilePath = @ "SD\DustSensor.TXT";
        private bool _storage = false;
        private string[] storagedevice;

        //method 1
        private GT.Timer _sensorTimer;
        private GT.Interfaces.InterruptInput _dustSensor;
        private bool _pulseLow = false;
        public const Int64 ticks_per_millisecond = System.TimeSpan.TicksPerMillisecond;
        private Int64 _startTime = 0;

        //method 2
        private GT.Timer _sensorTimer2;
        private GT.Interfaces.DigitalInput _dustSensor2;
        

        private Int64 _lowTime = 0;
        private Int64 _sampleTime = 0;

        
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
            sdCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(sdCard_SDCardUnmounted);

            if (sdCard.IsCardMounted)
            {
                storagedevice = Mainboard.GetStorageDeviceVolumeNames();
                _storage = Mainboard.MountStorageDevice(storagedevice[0]);
            }

            /*
            //method 1
            _dustSensor = groveExpansion.SetupInterruptInput(GT.Socket.Pin.Three, GT.Interfaces.GlitchFilterMode.Off, GT.Interfaces.ResistorMode.Disabled, GT.Interfaces.InterruptMode.RisingAndFallingEdge);
            _dustSensor.Interrupt += new InterruptInput.InterruptEventHandler(_dustSensor_Interrupt);

            _sensorTimer = new GT.Timer(60000);
            _sensorTimer.Tick += new GT.Timer.TickEventHandler(_sensorTimer_Tick);
            _sensorTimer.Start();
             */
            

            //method 2
            _dustSensor2 = groveExpansion.SetupDigitalInput(GT.Socket.Pin.Three, GlitchFilterMode.Off, ResistorMode.Disabled);
            _sensorTimer2 = new GT.Timer(1);
            _sensorTimer2.Tick += new GT.Timer.TickEventHandler(_sensorTimer2_Tick);
            _sensorTimer2.Start();


        }

        void sdCard_SDCardUnmounted(SDCard sender)
        {
            storagedevice = Mainboard.GetStorageDeviceVolumeNames();
            foreach (string s in storagedevice)
            {
                Debug.Print(s);
            }
            _storage = false;
        }

        void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
        {
            storagedevice = Mainboard.GetStorageDeviceVolumeNames();
            _storage = Mainboard.MountStorageDevice(storagedevice[0]);
        }

        void _dustSensor_Interrupt(InterruptInput sender, bool value)
        {
            if (value)
            {
                _lowTime = _lowTime + (GetCurrentTimeInTicks() - _startTime);
                _pulseLow = false;
            }
            else
            {
                _startTime = GetCurrentTimeInTicks();
                _pulseLow = true;
            }
        }


        public static long GetCurrentTimeInTicks()
        {
            return Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks;
        }


        void _sensorTimer_Tick(GT.Timer timer)
        {
            Mainboard.SetDebugLED(true);

            if (_pulseLow)
            {
                Int64 now = GetCurrentTimeInTicks();
                _lowTime = _lowTime + (now - _startTime);
                _startTime = now;
            }

            double ratio = (_lowTime / (double) ticks_per_millisecond)/600.0;

            _lowTime = 0;

            double concentration = CalculateConcentration(ratio);

            StoreResult(concentration);

            Mainboard.SetDebugLED(false);
        }

        private void StoreResult(double concentration)
        {
            if (_storage)
            {
                try
                {
                    StreamWriter sw = new StreamWriter(File.Open(_dataFilePath, FileMode.Append, FileAccess.Write));
                    sw.WriteLine(concentration.ToString());
                    sw.Flush();
                    sw.Close();
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                }
            }
        }

        private static double CalculateConcentration(double ratio)
        {
            double concentration = 1.1*(ratio*ratio*ratio) - 3.8*(ratio*ratio) + 520.0*ratio + 0.62;

            Debug.Print(concentration.ToString());
            return concentration;
        }

        void _sensorTimer2_Tick(GT.Timer timer)
        {
            if (!_dustSensor2.Read())
                _lowTime++;

            if (_sampleTime++ > 60000)
            {
                _sensorTimer2.Stop();

                double ratio = (_lowTime*100.0)/_sampleTime;
                double concentration = CalculateConcentration(ratio);

                StoreResult(concentration);

                _lowTime = 0;
                _sampleTime = 0;
                _sensorTimer2.Start();
            }
        }
    }
}

looks like you are running out of memory…
you may want to check your references and remove all that is not used by the Cerberus…

Cheers.

I love using Resharper (the one tool everyone should have) for cleaning up all that unneeded stuff, so I run about as skinny as I can get on References etc, but what I did was comment out the unused code, etc and I’m back to running again. That is weird as I wouldn’t have thought that unused code would have burned that much memory, but your suggestion made me do the work to comment out code and skinny it down further and now its back to running. I was scared I killed my beloved Cerberus.

Working app, just commented out some ‘small’ stuff really.


using System;
using System.IO;
using Gadgeteer.Interfaces;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT;
using GT = Gadgeteer;
using Gadgeteer.Modules.Seeed;

namespace CerberusDustSensor
{
    public partial class Program
    {
        private static string _dataFilePath = @ "SD\DustSensor.TXT";
        private bool _storage = false;
        private string[] storagedevice;

        //method 1
        //private GT.Timer _sensorTimer;
        //private GT.Interfaces.InterruptInput _dustSensor;
        //private bool _pulseLow = false;
        //public const Int64 ticks_per_millisecond = System.TimeSpan.TicksPerMillisecond;
        //private Int64 _startTime = 0;

        //method 2
        private GT.Timer _sensorTimer2;
        private GT.Interfaces.DigitalInput _dustSensor2;
        

        private Int64 _lowTime = 0;
        private Int64 _sampleTime = 0;

        
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
            sdCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(sdCard_SDCardUnmounted);

            if (sdCard.IsCardMounted)
            {
                storagedevice = Mainboard.GetStorageDeviceVolumeNames();
                _storage = Mainboard.MountStorageDevice(storagedevice[0]);
            }

            /*
            //method 1
            _dustSensor = groveExpansion.SetupInterruptInput(GT.Socket.Pin.Three, GT.Interfaces.GlitchFilterMode.Off, GT.Interfaces.ResistorMode.Disabled, GT.Interfaces.InterruptMode.RisingAndFallingEdge);
            _dustSensor.Interrupt += new InterruptInput.InterruptEventHandler(_dustSensor_Interrupt);

            _sensorTimer = new GT.Timer(60000);
            _sensorTimer.Tick += new GT.Timer.TickEventHandler(_sensorTimer_Tick);
            _sensorTimer.Start();
             */
            

            //method 2
            _dustSensor2 = groveExpansion.SetupDigitalInput(GT.Socket.Pin.Three, GlitchFilterMode.Off, ResistorMode.Disabled);
            _sensorTimer2 = new GT.Timer(1);
            _sensorTimer2.Tick += new GT.Timer.TickEventHandler(_sensorTimer2_Tick);
            _sensorTimer2.Start();


        }

        void sdCard_SDCardUnmounted(SDCard sender)
        {
            storagedevice = Mainboard.GetStorageDeviceVolumeNames();
            foreach (string s in storagedevice)
            {
                Debug.Print(s);
            }
            _storage = false;
        }

        void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
        {
            storagedevice = Mainboard.GetStorageDeviceVolumeNames();
            _storage = Mainboard.MountStorageDevice(storagedevice[0]);
        }

        /*
        void _dustSensor_Interrupt(InterruptInput sender, bool value)
        {
            if (value)
            {
                _lowTime = _lowTime + (GetCurrentTimeInTicks() - _startTime);
                _pulseLow = false;
            }
            else
            {
                _startTime = GetCurrentTimeInTicks();
                _pulseLow = true;
            }
        }


        public static long GetCurrentTimeInTicks()
        {
            return Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks;
        }


        void _sensorTimer_Tick(GT.Timer timer)
        {
            Mainboard.SetDebugLED(true);

            if (_pulseLow)
            {
                Int64 now = GetCurrentTimeInTicks();
                _lowTime = _lowTime + (now - _startTime);
                _startTime = now;
            }

            double ratio = (_lowTime / (double) ticks_per_millisecond)/600.0;

            _lowTime = 0;

            double concentration = CalculateConcentration(ratio);

            StoreResult(concentration);

            Mainboard.SetDebugLED(false);
        }
        */

        private void StoreResult(double concentration)
        {
            if (_storage)
            {
                try
                {
                    StreamWriter sw = new StreamWriter(File.Open(_dataFilePath, FileMode.Append, FileAccess.Write));
                    sw.WriteLine(concentration.ToString());
                    sw.Flush();
                    sw.Close();
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                }
            }
        }

        private static double CalculateConcentration(double ratio)
        {
            double concentration = 1.1*(ratio*ratio*ratio) - 3.8*(ratio*ratio) + 520.0*ratio + 0.62;

            Debug.Print(concentration.ToString());
            return concentration;
        }

        void _sensorTimer2_Tick(GT.Timer timer)
        {
            if (!_dustSensor2.Read())
                _lowTime++;

            if (_sampleTime++ > 60000)
            {
                _sensorTimer2.Stop();

                double ratio = (_lowTime*100.0)/_sampleTime;
                double concentration = CalculateConcentration(ratio);

                StoreResult(concentration);

                _lowTime = 0;
                _sampleTime = 0;
                _sensorTimer2.Start();
            }
        }
    }
}