Serial read question

I am new to Arduino but not new to programming. I need to send a special character to the serial port and receive a variable length non-delimited string in return. The following test code does this except the return string one byte at a time. In reality, when I send a “Y”, I will get an “SM” in return. In other cases, I may get 15-20 bytes returned. I am doing this on a PC in Visual Basic using a timer. I send a character and wait a predetermined amount of time before I consider the return data complete.

//#include <SoftwareSerial.h>

char incomingByte = 0; // for incoming serial data
String strInput;

void setup() {
// Open serial communications
Serial.begin(9600);
}

void loop(){
SendCode(“Y”); // Send magic code
if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print("I received: ");
Serial.println(incomingByte, OCT);
strInput = String(incomingByte + strInput);
Serial.println(strInput, HEX);
}
delay(2000);
}

//Send text subroutine
void SendCode(String strCode) {
Serial.println(strCode);
}

The above gives me “no matching function for call to ‘HardwareSerial::println(String&, int)’” on the Serial.println(strInput, HEX); line. How do I concatenate the variable number of returned bytes to a string I can parse? I am not looking for someone to write my code for me, just a pointer or two :slight_smile:

The oct, hex etc only apply to numeric variables, not to character arrays or Strings (capital S).

Maybe serial input basics - updated can give you ideas how to read and collect serial data.

I send a character and wait a predetermined amount of time before I consider the return data complete.

That is a crappy way of doing it.

and receive a variable length non-delimited string in return.

Why? Even if the delimiter is discarded, what benefit is there of not using one?

Given that you are constructing a String - a bunch of text wrapped in a class - what does sending that instance in HEX format even mean? What is the HEX representation of "Polly wants a cracker"?

Thanks sterretje. The link to the serial input basics is a BIG help!