Is this a code good for reading this serial output

Hello,
I am trying to use an RS232 converter with my Mega2560 to read data that is being outputted by a weight scale device. The scale uses RFID tags and outputs 4 lines two of which contain the tag number and an assigned ID, the first two lines arent important.
Ive been trying to implement this using the sample code which reads serial data byte by byte until a newline is detected.
The sample code i modified is a much more efficient way of reading Serial data instead of using that awful Serial.readString function.
Ive been able to capture the RS232 output from the the weight scale using a USB to RS232 converter.
the data looks like this:

FR"EIDVID"
?

969 000000680825
FR"EIDVID"
?

969 000000680825
FR"EIDVID"
?

969 000000680825
FR"EIDVID"
?

969 000000680825

The data always starts with the FR"EIDVID" indicator and then a question mark in line 2.
Line 3 can sometimes be blank depending if the RFID tag has an alias assigned, if its blank its blank and if it contains a value it contains a value, it really makes no difference if its blank.
Its line 4 i want to capture, it will always be a numeric value.

So ive written some code with some very helpful advice i got in an earlier post.
The problem is that i dont have immediate access to the hardware and i would like to try and tie down the programming side as much as possible. I will test and if it fails I will try and figure out and rectify the issue.

The code should read data until a newline is received and then the string is terminated.

Then it performs the check, line 1 is checked to see if its FR"EIDVID", a variable lineChecker is set to 1.
line 2 is check to see if its equal to a ?, if so line checker is 2
line 3 is checked to see if it contains a hypen as the Alias is usually something like 33-33 or 1-102.
line 4 is checked to see if its all numbers.

At present this code works if i simulate it from the Arduino terminal but i was looking for some advice on successfully detecting the last two lines reliably.

void recvWithEndMarker() {
 
  static byte ndx = 0;

    char endMarker = '\n'; //read until newline
    char rc;
    while (Serial2.available() > 0 && newData == false) {
    rc = Serial2.read();
    if (rc != endMarker) {
    receivedChars[ndx] = rc;
     ndx++;
     if (ndx >= numChars) {
         ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
    }
  }
}
void showNewData() {
  if (newData == true) {
 
    if (strcmp(receivedChars, "FR\"EIDVID\"")  == 0) { //check for line 1
      lineChecker = 1;
    }
    else if (strcmp(receivedChars, "?")  == 0) { //check for line 2
      lineChecker = 2;
   
    }
    else if (line3Checker() != false) { //check if line 3 contains a hyphen
      lineChecker = 3;
      earTag = receivedChars;
    }  
    else if (check_string() == true) {
           if (eidLookup == true) {
              eidTag = receivedChars;
        detectedCow = true;
        duplicateChecker();
      }
    }
    else {
      lineChecker = 0;
    }
    lineChecker = 0;
     lastTag=earTag;
    newData = false;
  }
}
boolean line3Checker()
{
  char * pch;
  pch = strchr(receivedChars, '-');
  while (pch != NULL)
  {
    return true;
  }
  return false;
}


boolean check_string() {
  int counter = 0;
  char* testChars = receivedChars;
  int string_len = strlen(testChars);
  for (int i = 0; i < strlen(testChars); i++) { //add a 0 in blank space
    if (testChars[i] == ' ')
    {
      testChars[i] = '0';
    }
  }
  for (int i = 0; i < strlen(testChars); i++) {
    if (isdigit(testChars[i])) {
      counter++;
    }
  }

  if ((counter == strlen(testChars) && (strlen(testChars) != 0)))
  {
    lineChecker = 4;
    eidLookup = true;
    int len = strlen(receivedChars); 
    return true; 
  }
  else {
    eidLookup = false;
    return false;
  }
}

cfcorp:
At present this code works if i simulate it from the Arduino terminal but i was looking for some advice on successfully detecting the last two lines reliably

That seems to say that it works and that it does not work.

I don't understand what you want help with. What is it actually doing now and what do you want it to do that is different?

...R

     earTag = receivedChars;

You did not include the definition of either of these variables. That stuff at the top of the code which looks useless isn't useless. Please show it next time you post code.

But, based on the way you are using these variables, they look like char pointers. This line makes earTag point to the same location as receivedChars. If you later change the chars in receivedChars then you have lost the ear tag value you wanted.

Use strcpy() or the safer strncpy() functions to copy a string. Look them up. They are part of the standard C library, which sits under all the Arduino stuff.

Hello guys,
Thanks for the replies.
Apologies if this seems confusing Robin2, I am able to use the Arduino IDE and TerraTerm to send a line at a time which does work for me using my laptop.
I was looking for some advice or heads up in case there was something else i should look out for when interfacing with the weigh scale
The main issue is that the scale is about an hour away and I just wanted to see if anyone could point out stuff to be aware of in case it doesn't work and i am trying to debug on site.
Its fine for me to type in FR"EIDVID" and ? for the arduino to ignore it and also when i type in a sample number for the RFID tag such as 969 2132132132. That picks up fine and even if i did something like 44-22 it'll also get detected.

The main reason for my question was about my approach and whether you guys think it makes sense.
I actually have a post here as i had some hardware problems interfacing the weigh scale to the arduino RS232 conveter so i wanted to check if anyone could spot major issues in my code.
I was using a crossover cable which didnt work between the scale and arduino even when i use the SerialPassthrough sample code. Although my USB to RS232 cable connected to my Arduino worked using my laptop. I was thinking it may be a DTE to DTC issue. To try and debug HW issues ive bought an RS232 Male and female breakout board where i can hopefully debug.

Hello MorganS, thanks also for your reply.
Sorry i forgot to add in the definitions for receivedChars which is an array of size 32 and earTag is a String.
So instead of just making the variable equal to receivedChars i will try and use the strncpy() function.

cfcorp:
The main issue is that the scale is about an hour away and I just wanted to see if anyone could point out stuff to be aware of in case it doesn't work and i am trying to debug on site.

I'm not good at that stuff unless I am fully immersed in a project. My general approach is to try to imagine what might happen and how I would recognise it. That can also help when things happen that I had not anticipated.

I certainly would not expect my own code to work first time in the situation you describe.

...R

Please post a link to the scale, I may have an application for such a device in my own project. Thanx.

cfcorp:
Sorry i forgot to add in the definitions for receivedChars which is an array of size 32 and earTag is a String.

Then it will do what you want. However it is good practise to avoid big-S String entirely. So make that change when you have free time to play.

You do have a basic problem with the code as shown. It remembers what line it is up to but never uses that information. You should check that lineChecker equals 2 before testing to see if the current line is a valid 3rd line. If it isn't, then set lineChecker back to zero to wait for the next beginning.