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

First chance exception on serialport open


  • Please log in to reply
5 replies to this topic

#1 Bryan T

Bryan T

    Member

  • Members
  • PipPip
  • 25 posts

Posted 30 April 2012 - 06:43 PM

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?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 April 2012 - 09:01 PM

Hi Bryan,

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?

Can you share your code really quick (the few lines that create the SerialPort object and open the SerialPort)?

Chris

#3 Bryan T

Bryan T

    Member

  • Members
  • PipPip
  • 25 posts

Posted 30 April 2012 - 09:59 PM

Chris, thanks for the reply. I actually got it working, but I'm still not sure what was wrong in the first place. I don't have time today, but tomorrow I'll try to recreate the original error and share the code, just so I understand what was happening. Thanks.

#4 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 25 May 2012 - 01:37 PM

I just ran into this today, working on talking with this pH Stamp.
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 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 25 May 2012 - 01:39 PM

Well, nevermind.
I just realized I had 0 for data bits, I doubt that will work very well now will it...........Posted Image

#6 segu239

segu239

    New Member

  • Members
  • Pip
  • 1 posts

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

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.