Saving serial information into an array

I am working on an RFID reader program and I am receiving this tag information at the serial monitor

+ 0.start look for tag:
--------------
command return: 32121E3002A0AA085150251190A538
--------------

How do I save it into an array ? This is the code I wrote but I got many errors in the information saved at the tag array.

 while(mySerial.available())
  {    
      Serial.print(mySerial.read(),HEX);
      delay(2);

     for (int i=0; i<=29; i++)
         {tag[i]=mySerial.read();
           Serial.print(tag[i],HEX);
           delay(2); }
  }

This is what is the tag array display.

command return: 32121E3002FFFFFFA0FFFFFFAA0FFFFFF851502511FFFFFF90FFFFFFA538FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Please advise

t i=0; i<=29; i++)
         {tag[i]=mySerial.read();
           Serial.print(tag[i],HEX);
           delay(2); }
  }

You already have the info saved in some array called tag. What more do you need? What is the problem?

while(mySerial.available())
  {    
      Serial.print(mySerial.read(),HEX);
      delay(2);

     for (int i=0; i<=29; i++)
         {tag[i]=mySerial.read();

Check to see if you’ve got at least one character to read, then read all 30 of them.
No.

AWOL:

while(mySerial.available())

{   
      Serial.print(mySerial.read(),HEX);
      delay(2);

for (int i=0; i<=29; i++)
        {tag[i]=mySerial.read();



Check to see if you've got at least one character to read, then read all 30 of them.
No.

How do I do this in the code ?

See if there's a character to read, then read it.

See Robin2's serial handling basics thread.

I am not sure how to modify the Serial Input Basics Tutorial from Robin2,

this is what I have so far. Please advise

const byte numChars=30;
char receivedChars[numChars];
boolean newData=false;
static byte ndx=0;
char rc;


 while(mySerial.available() >0 && newData ==false)
  {    
      

      rc=mySerial.read();
      receivedChars[ndx]=rc;
      Serial.print(receivedChars[ndx]);
      ndx++;
      if(ndx>=numChars)
         {ndx=numChars-1;
         }



This is what is saved at the receivedChars



-------------
+ 0.start look for tag:
--------------
command return: 20

Your code doesn't compile because it is incomplete, so I can't test it.

Don't copy the code from that thread. It probably won't work if you just copy it exactly. Instead, spend a few hours reading carefully through that thread until you understand the code in it. Then it will be trivial to do what you want.

If you really do what you should here then we shouldn't hear from you for a day or so. At least a few hours. If you come back from that thread in just a half an hour it makes it look like you're not trying very hard and that makes the help dry up.

AWOL: Your code doesn't compile because it is incomplete, so I can't test it.

The code compile but it does not display the correct information.

No, the code you posted will not compile because it is not complete. You are missing loop and setup functions at the very least. Your while loop isn't in a function.

you should, sometimes must, allow for the fact that your system might 'come alive' right in the middle of a data block transmission. so it's best to not process a block unless and until you have the right number of elements and the last or first datum received is provably the end or start of the block. if the data block does NOT have a specific start or end marker/character you can usually use time to determine the blocks. ASCII characters SOH .. EOT exist for good reason. I admit they don't get much use nowadays.

Delta_G: No, the code you posted will not compile because it is not complete. You are missing loop and setup functions at the very least. Your while loop isn't in a function.

I did not post that part of the code because it's very long. I thought this is trivial.

I only posted the part where I need to save the serial data into the array.

Delta_G: Don't copy the code from that thread. It probably won't work if you just copy it exactly. Instead, spend a few hours reading carefully through that thread until you understand the code in it. Then it will be trivial to do what you want.

If you really do what you should here then we shouldn't hear from you for a day or so. At least a few hours. If you come back from that thread in just a half an hour it makes it look like you're not trying very hard and that makes the help dry up.

The example you referred too is simple and it's different than the my problem. In the Robin example there is start and end characters.

Yes, it is different. That's why you can't expect to copy it. The code you actually need will differ slightly. But if you'll spend more time reading there you'll find all the pieces for the answer you seek. It WILL require thought and study on your part.

If you want to get there without spending the time to read and study and think then get your wallet out and head over to the "Gigs and Collaborations" section and someone will write the code for you for the right price.

So you only posted part of the code. Now that severely limits those trying to help. They've either got to figure out what going on without any possibility to test or they have to write those sections and add to what you've given and what if they write something different from what you have?

Delta_G: So you only posted part of the code. Now that severely limits those trying to help. They've either got to figure out what going on without any possibility to test or they have to write those sections and add to what you've given and what if they write something different from what you have?

If you have any any technical advices to solve the issue, you are most welcome to share. Otherwise, spare your lectures for yourself. Thanks.

I'm trying to help you. I'm telling you what I need you to do so I can help you. And you call it a lecture? What lecture? I'm just tells ng you how to get help. If you don't want any help then spare us the time wasting and don't post anymore so we can move on to people who really want to fix their codes.

Bye!

In the snippet you posted you are saving the data in an array called receivedChars. So you've already saved the data you want to save. Since you're so sure that the rest of the code has nothing to do with it I guess we can mark this one solved. You've already got what you claim you want.