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

Problem with SerialPort


  • Please log in to reply
2 replies to this topic

#1 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 08 January 2014 - 11:12 AM

Hi. Im having problems with my serial comunication in Netduino 2. I have the Netduino firmware 4.2.2 in the Netduino 2 and trying to develop in VS2012 with the 4.3 SDK. I cant flash the 4.3 beta firmaware in Netduino 2 becouse it gets freezed.

 

The code is the next one:

public static void Main()        {            SerialPort com = new SerialPort(SecretLabs.NETMF.Hardware.Netduino.SerialPorts.COM1, 115200, Parity.None, 8, StopBits.One);            string msg="Hi";            byte[] message;            while (true)             {                Thread.Sleep(2000);                message = Encoding.UTF8.GetBytes(msg);                com.Write(message, 0, message.Length);            }

And the error it gives:

 

An unhandled Exception of type "System.ArgumentException" ocurred in Microsoft.SPOT.Hardware.SerialPort

 

 

I know that is a versin or assembly compatibility problema, but how can I fix it????

 



#2 Schildi

Schildi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 11 January 2014 - 11:35 AM

Hi,

 

I used your code and I got the same issue. My first rough guess would be to please you to open the door before trying to walk through it, that reduces headache ;)

So please try :

com.open();

before your while loop:

SerialPort com = new SerialPort(SecretLabs.NETMF.Hardware.Netduino.SerialPorts.COM1, 115200, Parity.None, 8, StopBits.One);            string msg="Hi";            byte[] message;            com.Open();            while (true)            {                Thread.Sleep(2000);                message = Encoding.UTF8.GetBytes(msg);                com.Write(message, 0, message.Length);            }

at least that helped my application still beeing alive and not throwing an exception.

Remark: I did not test if something is coming on the com port.

 

regards Marco



#3 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 12 January 2014 - 09:51 AM

Hi Schildi!!!

 

Oh my god!! how I could not realize about it!!!!!! I was trying to use the com port without openning it!!!!! Tipical dumb mistake that gets you crazy until somebody opens your eyes!!! Thank you so much!!!






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.