Go Down

Topic: readBytesUntil What am I missing? (Read 9037 times) previous topic - next topic

westek

Jul 12, 2012, 09:54 pm Last Edit: Jul 12, 2012, 09:58 pm by westek Reason: 1
Greetings,
I am using the Arduino IDE 1.0 on a Mac running OSX 10.7.4

The hardware I'm programming is a Arduino Uno Rev 3.

I'm trying to read an unknown length string of ASCII characters terminated with a line feed from the UART on the Arduino from an external source. Lets just say from the Serial monitor in the Arduino IDE. I assumed readBytesUntil would be the simplest way but I keep getting the error: no matching function for call to 'HardwareSerial::readBytesUntil(int&, String&)'

I have done my due diligence trying to understand the error, but I'm just not getting it. So here is my simple code.

Code: [Select]
// Library Code To Include.
#include <OneWire.h>
#include <LiquidCrystal.h>

// Compiler/Library Initialization.

// Tell Library What Pins The LCD Is Connected To.
LiquidCrystal lcd(12,11,5,4,3,2); // RS,Enable,D4,D5,D6,D7

//Initialization/Setup Code Begins Here

void setup() {
  Serial.begin(9600);   // Start The Serial UART at 9600 Baud. Test Code Comment Out.
  lcd.begin(16,2);      // Tell Library How Many Columns And Rows The LCD Has.
}

void loop() {
  String serialdata = "0";
  int lf = 10;
 
 
  Serial.readBytesUntil(lf, serialdata);
 
  lcd.setCursor(0,0);
  lcd.print(serialdata);
 
}


Can anyone point me in the right direction or am I not understanding the usage of readBytesUntil. There is no example usage on the Arduino website. Thank you in advance for any help or direction.

abrookfield

http://arduino.cc/en/Serial/ReadBytesUntil
www.reeftopper.com

westek


http://arduino.cc/en/Serial/ReadBytesUntil


Thanks but that was the first place I checked... There is no example there. No explanation of the error I'm getting on that page. Please don't take this the wrong way, but that really wasn't helpful.

WizenedEE

Quote
buffer: the buffer to store the bytes in (char[] or byte[])


The function expects either a char[] or a byte[]. String is neither of those.

abrookfield

#4
Jul 12, 2012, 10:21 pm Last Edit: Jul 12, 2012, 10:23 pm by abrookfield Reason: 1
String serialdata = "0";
char serialdata[80];

// Serial.readBytesUntil() returns the number of characters read into the buffer. A 0 means no valid data was found
nchars=Serial.readBytesUntil(lf, serialdata, 80);
www.reeftopper.com

westek


Quote
buffer: the buffer to store the bytes in (char[] or byte[])


The function expects either a char[] or a byte[]. String is neither of those.


Yes, good point. I fixed that by declaring the variable serialdata as char instead of string but I still get the same error.

no matching function for call to 'HardwareSerial::readBytesUntil(int&, char&)'

????

abrookfield

#6
Jul 12, 2012, 10:30 pm Last Edit: Jul 12, 2012, 10:36 pm by abrookfield Reason: 1
Serial.readBytesUntil(character, buffer, length)

nchars=Serial.readBytesUntil(lf, serialdata, 80);
nchars=Serial.readBytesUntil(lf, serialdata, 80);
www.reeftopper.com

westek


String serialdata = "0";
char serialdata[80];

// Serial.readBytesUntil() returns the number of characters read into the buffer. A 0 means no valid data was found
nchars=Serial.readBytesUntil(lf, serialdata, 80);



OK, this fixed it. I was assuming the last parameter was optional. I guess I thought that since the wording that described the the termination of the function used the word  "OR" that if I was only looking for the termination character or the default timeout period I wouldn't need it.  Does that make sense? Thank You very much for setting me straight. I'm posting the corrected code so that others reading the thread can see the fixed result. Again Thank everyone for their help.

Code: [Select]
// Library Code To Include.
#include <OneWire.h>
#include <LiquidCrystal.h>

// Compiler/Library Initialization.

// Tell Library What Pins The LCD Is Connected To.
LiquidCrystal lcd(12,11,5,4,3,2); // RS,Enable,D4,D5,D6,D7

//Initialization/Setup Code Begins Here

void setup() {
  Serial.begin(9600);   // Start The Serial UART at 9600 Baud. Test Code Comment Out.
  lcd.begin(16,2);      // Tell Library How Many Columns And Rows The LCD Has.
}

void loop() {
  char serialdata[80];
  int lf = 10;
 
 
  Serial.readBytesUntil(lf, serialdata, 80);
 
  lcd.setCursor(0,0);
  lcd.print(serialdata);
 
}/code]

Go Up