University project error message

Hi guys! my university project is an electronic stethoscope, using a FEZ cerbuino bee and a mic inserted into the end of a normal stethoscope. The objective is to obtain a value for BPM in visual studio. When running the program shown below, I seem to randomly get this error message;

“An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll”

Could someone give my guidance as to why this happens?

using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Hardware;
using GHI.OSHW.Hardware;



namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            AnalogInput lightSensor = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A1);

            double lightSensorReading = 0;
            while (true)
            {
                lightSensorReading = lightSensor.Read();
                Debug.Print(lightSensorReading.ToString());
                Thread.Sleep(25);
            }
        }
                
            
            void programStarted()
            {
                Debug.Print("Program Started");
            }
        }

    }


output from debug;

0.049328449328449327
0.061538461538461542
0.056166056166056168
0.047619047619047616
A first chance exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll
0.057631257631257635
An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll

The program '[22] Micro Framework application: Managed' has exited with code 0 (0x0).

Try using ReadRaw and see if you still get that exception.

@ ks09aao - dunno if it will make a difference but remove any references to GHI.Premium.Hardware;

1 Like

@ Justin - Good catch!

removing the reference did the trick! many thanks, I’ve spent an awfully long time trying to solve that!

Sweet :slight_smile:

Could we know the reason af such a solution?

GHI.Premium.Hardware is not on OSHW board.

I would have expected that the code simply didn’t launch instead of working with exception occuring…