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
Answered
Hardware →
Netduino Plus 2 (and Netduino Plus 1) →
SerialPort Receive Data CorruptionStarted by Hawkez, 20 Jul 2015 Netduino Plus 2, Netduino 3 WiFi and 2 more... |
|
|||
Answered
Hardware →
Netduino 3 →
SerialPort BytesToRead only ever returns 256Started by Riaan Mastenbroek, 25 May 2015 SerialPort |
|
|||
Hardware →
Netduino Plus 2 (and Netduino Plus 1) →
To comunicate netduino 2+ with module bluetooth jy mcu(app android)Started by Archimede, 17 Nov 2014 android, serialport, bluetooth and 5 more... |
|
|||
Hardware →
Netduino Plus 2 (and Netduino Plus 1) →
SerialPort.DataReceivedStarted by MLA44, 06 Nov 2014 SerialPort, documentation |
|
|||
Hardware →
Netduino 2 (and Netduino 1) →
Bytes sent over SerialPort not the same when received on Netduino over BluetoothStarted by Tinymacrocosm, 25 Oct 2014 Bluetooth, JY-MCU, Netduino2 and 1 more... |
|
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users