Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Error "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll"


  • Please log in to reply
5 replies to this topic

#1 RafaelDPerez

RafaelDPerez

    New Member

  • Members
  • Pip
  • 3 posts

Posted 01 December 2012 - 09:03 PM

Hello guys! I would really appreciate your help with a problem that I'm having with a project on Netduino Plus. My partner and I are making a project where we are going to use a humidity and temperature sensor, and a RFID. The model of our humidity and temperature sensor is DHT22 (https://www.sparkfun.../products/10167), and the model of the RFID RTL-09875 (https://www.sparkfun.com/products/9875). The thing is that when we tried each thing seperately, it worked perfectly, but when we added both classes and codes into a single project the error "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll" came out. I think this is related to the cpu pin that the Netduino is using. I don't know very well because I'm new to this. I attached the code we have so far, please help us! Rafael D. Perez

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 December 2012 - 05:50 AM

Hi RafaelDPerez, Can you post a code snippet which demonstrates the issue in a simple sample? We want to make sure we can help guide you here, but there are a lot of things that can be going wrong in a large project. By simplifying it to a small number of lines of code, we can help diagnose things and all learn together. Welcome to the Netduino community, Chris

#3 RafaelDPerez

RafaelDPerez

    New Member

  • Members
  • Pip
  • 3 posts

Posted 02 December 2012 - 02:39 PM

Hi Chris!

Thanks a lot for the reply!

I'm going to paste here the code of the program. But I would like you to download the project zip and open it in visual studio because I think the problem is in one of the classes of either the RFID or the Temeprature Sensor. The class of the RFID is called Class1, and the one of the sensor is called DhtSensor. When I build the solution, the line that gets marked is the one that says:

portOut = new TristatePort(pin1, true, false, resistorMode);

Let me know if you need any more info, and sorry if I'm not being clear, I'm completely new to this.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using IDx2Reader;
using CW.NETMF;
using CW.NETMF.Sensors;

namespace ProyectoTest
{
    public class Program
    {
        private static idReader _idReader;

        private static void StartRFID()
        {
            _idReader = new idReader(SerialPorts.COM1, Pins.GPIO_PIN_D4);
            _idReader.RfidEvent += new idReader.RfidEventDelegate(_idReader_RfidEvent);
            _idReader.Start();
        }

        static void _idReader_RfidEvent(object sender, idReader.RfidEventArgs e)
        {
            Debug.Print("Card scanned: " + e.RFID + ", time: " + e.ReadTime);
        }



        public static void Main()
        {
            // Write your code here

            StartRFID();
            var dhtSensor = new Dht22Sensor(Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, PullUpResistor.External);
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);


            while (true)
            {
                Thread.Sleep(2000);

                if (dhtSensor.Read())
                {
Debug.Print("dht sensor read() ok, rh = " + dhtSensor.Humidity.ToString("f1") + "%, temp = " + dhtSensor.Temperature.ToString("f1") + "°c");
                }
                else
                {
                    Debug.Print("dht sensor read() failed");
                }

                if (dhtSensor.Temperature >= 25)
                {
                    led.Write(true);
                }
                else
                    led.Write(false);
            }
        }

    }
    
}

Attached Files


Edited by Chris Walker, 02 December 2012 - 05:34 PM.
added [code][/code] tags


#4 RafaelDPerez

RafaelDPerez

    New Member

  • Members
  • Pip
  • 3 posts

Posted 02 December 2012 - 02:47 PM

Other thing, the line I put in my last reply is in the DhtSensor class!! Sorry and thanks again! Rafael D. Perez

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 December 2012 - 05:35 PM

Hi Rafael, Just to confirm...does the code snippet above fail for you? On which line of code are you getting the error? I don't see any TristatePorts in your code--so I'm wondering if we're working out a number of different issues? Let's start with the code snippet (thank you for posting that): what issue are you specifically experiencing with the above code? [Also...the above code is relying on a bunch of code in your project which isn't posted. Is it possible to simplify your code further--to perhaps a total of maybe 10 lines of code? We're happy to help walk through just about any scenario...but the longer the code is the harder it is and the _much_ longer it will take to assist you.] Chris

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 02 December 2012 - 06:07 PM

Yep, you've guessed it right - the problem is that pins D0 and D1 are also used by COM1 (RX, TX), so after you create the instance of SerialPort() they are reserved and cannot be used again (without disposing), hence the exception in TristatPort() constructor. You'd need to connect the DHT sensor to different pins, for example D2 and D3.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.