Pages: [1]   Go Down
Author Topic: readBytesUntil What am I missing?  (Read 7782 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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.
« Last Edit: July 12, 2012, 02:58:44 pm by westek » Logged

Atlanta
Offline Offline
Full Member
***
Karma: 4
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta
Offline Offline
Full Member
***
Karma: 4
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
« Last Edit: July 12, 2012, 03:23:43 pm by abrookfield » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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&)'

????
Logged

Atlanta
Offline Offline
Full Member
***
Karma: 4
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.readBytesUntil(character, buffer, length)

nchars=Serial.readBytesUntil(lf, serialdata, 80);
nchars=Serial.readBytesUntil(lf, serialdata, 80);
« Last Edit: July 12, 2012, 03:36:56 pm by abrookfield » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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]
Logged

Pages: [1]   Go Up
Jump to: