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); } } } } }
im trying the follow code but i have problems it apears "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.SerialP
#1
Posted 17 February 2013 - 10:44 PM
#3
Posted 18 February 2013 - 01:08 PM
are you running this on a Netduino Plus or a Netduino Plus 2?
#4
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
Posted 28 February 2013 - 04:46 AM
Also tagged with one or more of these keywords: serialport
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users