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

im trying the follow code but i have problems it apears "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.SerialP

serialport

  • Please log in to reply
4 replies to this topic

#1 edgar3232

edgar3232

    New Member

  • Members
  • Pip
  • 2 posts

Posted 17 February 2013 - 10:44 PM

using System; using System.Text; using System.IO.Ports; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace NetduinoPlusXbeeEcho { public class Program { private static bool pin13Value; private static OutputPort pin13 = new OutputPort(Pins.GPIO_PIN_D13, false); public static void Main() { byte[] buffer = new byte[32]; SerialPort port = new SerialPort("COM1", 19200); port.ReadTimeout = 0; port.Open(); while(true) { int count = port.Read(buffer, 0, buffer.Length); if(count > 0) { char[] chars = Encoding.UTF8.GetChars(buffer); if (chars[0] == 'h') pin13Value = true; if (chars[0] == 'l') pin13Value = false; pin13.Write(pin13Value); port.Write(buffer, 0, count); } } } } }



#2 dustmouse

dustmouse

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationEdgewater, CO

Posted 17 February 2013 - 11:52 PM

Could it have something to do with this line?

 

private static OutputPort pin13 = new OutputPort(Pins.GPIO_PIN_D13, false);

 

 

Maybe it's grumpy because you're setting an instance of something to a static variable.


Check out my Netduino projects on GitHub.


#3 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 18 February 2013 - 01:08 PM

are you running this on a Netduino Plus or a Netduino Plus 2?



#4 dustmouse

dustmouse

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationEdgewater, CO

Posted 27 February 2013 - 08:09 PM

Could it have something to do with this line?

 

private static OutputPort pin13 = new OutputPort(Pins.GPIO_PIN_D13, false);

 

 

Maybe it's grumpy because you're setting an instance of something to a static variable.

 

I don't know what I was thinking when I wrote this.  

 

Are there any more details in the exception?  Like in the inner exception?  I'm not sure what IDE you're using, but if you're using Visual Studio, have you tried going to Debug -> Exceptions and checking the 'Thrown' checkbox for Common Language Runtime Exceptions?  It should show you exactly where in your code the exception is being thrown. 


Check out my Netduino projects on GitHub.


#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 04:46 AM

Hi edgar3232, Also...what line of code is throwing the exception? Chris





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.