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

Serial can't use ReadLine();

serial c#

  • Please log in to reply
6 replies to this topic

#1 Wayneio

Wayneio

    Member

  • Members
  • PipPip
  • 24 posts

Posted 25 April 2013 - 09:14 PM

Hi,

 

I'm starting to have a bit more luck with the netduino and VS2012, but have hit an annoying point in my code.

 

I am using serial.ReadLine(); to read data sent back from the netduino to the pc, but I now need the netduino to also read the information, however I get the error "System.IO.Ports.SerialPort' does not contain a definition for 'ReadLine' and no extension method 'ReadLine' accepting a first argument of type 'System.IO.Ports.SerialPort' could be found (are you missing a using directive or an assembly reference?)"

 

Now I can't understand why, as the code on the netduino for serial communication is virtually identical to that of the code on the pc-side applicaiton, and that works fine.

 

This is a seciton of the code that has the error in it

 

 

	 static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)	    {		    // create a single byte array		    byte[] bytes = new byte[1];		    // as long as there is data waiting to be read		    while (serial.BytesToRead > 0)		    {			   theLED.Write(true);			   Thread.Sleep(500);			    // read a single byte			   serial.Read(bytes, 0, bytes.Length);               // the bit that doesn't work...			   theText = serial.ReadLine();			   // send the same byte back			   serial.Write(bytes, 0, bytes.Length);			    theLED.Write(false);		    } 

 

 

 



#2 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 26 April 2013 - 12:35 AM

well, ok you won't like this explanation, but... SerialPort does not have a method called ReadLine()!  Remember that NETMF is a subset of the 'full' subset you get on the desktop.  There's loads of things that are not there; you have code up that functionality from the basic things that are there.



#3 GrZeCh

GrZeCh

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationPoland

Posted 26 April 2013 - 06:51 AM

Maybe this will help you:

 

http://forums.netdui...rt-code-review/



#4 Wayneio

Wayneio

    Member

  • Members
  • PipPip
  • 24 posts

Posted 26 April 2013 - 08:17 PM

Thanks for the replys, I have got the applciation working without ReadLine functionality now (after fianlly giving up with MF 4.3 and VS2012, resorting to another computer with VS2012).



#5 Wayneio

Wayneio

    Member

  • Members
  • PipPip
  • 24 posts

Posted 26 April 2013 - 09:10 PM

Just another related question, i have read the command, and then the amount of times that the command should be executed. When i run this code and step through it with visual studio, the LED flashes as I would expect, but if I run it with no breakpoints, the LED stays on constantly.

 

I guess this is something to do with the speed that it all happens without breakpoints. Can anyone shed any light?

 

 

//flash by set amount					    int cnt = 0;					    while (cnt < CMDNo)					    {						    theExLED.Write(true);						    Thread.Sleep(5000);						    theExLED.Write(false);						    cnt++;					    } 

 

 

 

Thanks



#6 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 26 April 2013 - 10:50 PM

yes, the while loop immediately turns the led on after it has turned it off.  If you want it to take 5 sec per cycle (as you have coded it), break the 5 sec into two delays of 2.5 sec, and put one after when you turn on, and one after when you turn off.  e.g.

//flash by set amountint cnt = 0;while (cnt < CMDNo){	theExLED.Write(true);	Thread.Sleep(2500);	theExLED.Write(false);	Thread.Sleep(2500);	cnt++;}


#7 Wayneio

Wayneio

    Member

  • Members
  • PipPip
  • 24 posts

Posted 27 April 2013 - 08:11 AM

yes, the while loop immediately turns the led on after it has turned it off.  If you want it to take 5 sec per cycle (as you have coded it), break the 5 sec into two delays of 2.5 sec, and put one after when you turn on, and one after when you turn off.  e.g.

//flash by set amountint cnt = 0;while (cnt < CMDNo){	theExLED.Write(true);	Thread.Sleep(2500);	theExLED.Write(false);	Thread.Sleep(2500);	cnt++;}

Oh god. Now i feel daft. I'll make the excuse that it was late at night when i was trying this. Thanks :)






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.