Reading the Serial port and manipulating the string

Hi all,

Iam fairly new to the arduino, and I have hit a slight road block, I am trying to read a string from the serial port, I know the format of the string Iam meant to read i.e +Z20,Test20,xx,xx. I want to capture that string and remove the +Z20 and print out the string again?

I am trying to read a string from the serial port

The code you posted does not prove that.

I want to capture that string and remove the +Z20 and print out the string again?

Aren't you certain?

If it was a C program it would look something like this:

//--- Detect new line in serial buffer (if you read byte for byte)

const char* pTest = strstr(m_SerialBuf, "\r\n");
if (pTest != 0) //found it!
{
char reply[64];
char* pStr = &m_SerialBuf[0];

pTest[2] = 0; //ensure zero termintaion AFTER the \r\n
pStr += 5; //jump over +Zxx,

sprintf(reply, "+%s,test %d,%s", sSerialNr, nTestNr, pStr);

//--- Send reply to serial pipe!
// ...
}

I want to retrieve the string thats sitting in the buffer, and only print out what comes after "+Z20,"

A C program with member fields? I don't think so.

Post the code that you have now. We can't tell how you have collected the data.

PaulS:
The code you posted does not prove that.

He didn't post any code, sadly.

How to use this forum

Please use code tags.

Read this before posting a programming question

If it was a C program it would look something like this:

And if it was a puppy, what would it look like? This?


How about posting your actual code?

Hi again,

Iam using the arduino to run tests on device, and the device is loaded with firmware that runs its own set of tests (testing other circuitry on the device), the tests that run on the device sends back a string via the serial pipe in the format "+Z20,Test20,XX,XX" which is the result. I want to take that result and format it (i.e removing the +Z20 part) and just printing Test20,XX,XX. But Ive never done this before so Iam a little clueless where to begin :confused: (PS I am a novice when it comes to programming - sorry if I use the wrong terminology)

KeeganVeldsman:
I am trying to read a string from the serial port, I know the format of the string Iam meant to read i.e +Z20,Test20,xx,xx.

See: Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking

KeeganVeldsman:
I am trying to read a string from the serial port, I know the format of the string Iam meant to read i.e +Z20,Test20,xx,xx. I want to capture that string and remove the +Z20 and print out the string again?

Have a look at the second example in Serial Input Basics. There is also a parse example.

...R

KeeganVeldsman:
But Ive never done this before so Iam a little clueless where to begin

Indeed y reading up upon serial etc.

And if you want help, by posting your code...

the device sends back a string via the serial pipe in the format "+Z20,Test20,XX,XX"

Is there a carirage return or line feed to mark the end of that data packet?