First chance exception on serialport open
#1
Posted 30 April 2012 - 06:43 PM
#2
Posted 30 April 2012 - 09:01 PM
Can you share your code really quick (the few lines that create the SerialPort object and open the SerialPort)?I have an RS232 shield form Cutedigi. When I try to open my serial port, I get the following message:
"a first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.Serialport.dll"
I can give more details if needed. Is this a common error caused by a simple mistake?
Chris
#3
Posted 30 April 2012 - 09:59 PM
#4
Posted 25 May 2012 - 01:37 PM
Here's the code I'm using:
try { sp = new SerialPort(Serial.COM1, 38400, Parity.None, 0, StopBits.One); sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived); sp.Open(); byte[] message = Encoding.UTF8.GetBytes("R\r"); Debug.Print(message.ToString()); sp.Write(message, 0, message.Length); } catch (Exception e) { Debug.Print(e.StackTrace); }
StackTrace is telling me I'm getting an ArgumentException in System.IO.Ports.SerialPort::InternalOpen
#5
Posted 25 May 2012 - 01:39 PM
I just realized I had 0 for data bits, I doubt that will work very well now will it...........
#6
Posted 05 March 2013 - 10:41 AM
Hi, people Im Luis from argentina,
First I apologize for me english, in my country speek spanish.
I have the same problem that bryant. Can you help me ?. thanks
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 Microsoft.SPOT.IO;
using
System.IO.Ports;// el libro esta mal antes usaba SPOT ahora usa este, pero igual hay que agregar el ...SPOT.HARDWARE.SerialPort.
?
?
namespace
puerto_serie_netduino
{
public class Program
{
public static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
static SerialPort serial1;
public static void Main()
{
try
{
SerialPort serial1 = new SerialPort("com2", 9600, Parity.None, 8, StopBits.One);
serial1.Open();
serial1.DataReceived +=
new SerialDataReceivedEventHandler(serial1_DataReceived);
}
catch (Exception ex)
{
string msg = ex.Message;
}
Thread.Sleep(Timeout.Infinite);
}
static void serial1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] buffer = new byte[3];
if (serial1.BytesToRead > 0)
{
led.Write(
true);
}
}
}
}
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users