Serial Communication - How to read large bytes of data

Dear Robin2,

thank you very much for the help. I read the link you send and modified the code as per ''A more complete system"

However, I'm not able to get as much as bytes as you suggested.

In serial emulator, I obtain the following, which is exactly what I typed


<8967846137451273549146189246354782354723547234
83741238468923658923658235
173490174823654823562
18471046123845689235623
81234618046123905461203
18234761023468120354632
907349237420374>

But arduino gave me the following output:
This just in ... aaaaa
This just in ... abcdefg
This just in ... 8967846137451273549146189246354782354723547234
83741238468923658923658235
173490174823654823562
18471046123845689235623
81234618046123905461203
1823476102

Could you please let me know what's wrong here>?

thanks a lot

#include <Arduino.h>   
#include "wiring_private.h" // pinPeripheral() function

Uart Serial2 (&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);

const byte numChars = 4000;
char receivedChars[numChars];

boolean newData = false;
int j = 0;

void SERCOM1_Handler()
{
	Serial2.IrqHandler();
}

void setup() {
	Serial1.begin(9600);
	Serial2.begin(9600); 
	// Assign pins 10 & 11 SERCOM functionality
	pinPeripheral(10, PIO_SERCOM);
	pinPeripheral(11, PIO_SERCOM);
}

void loop() {
  
	for (j;j<1;j++)
	{
                //request data to host device
		Serial2.println("rdlfind 2 -10 -1");
	}		
    recvWithStartEndMarkers();
    showNewData();
	
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
 // if (Serial2.available() > 0) {
    while (Serial2.available() > 0 && newData == false) {
        rc = Serial2.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial1.print("This just in ... ");
        Serial1.println(receivedChars);
        newData = false;
    }
}