Dear Robin, the latest code is shown below.
/*
LDRD Connected Node
*/
#include <Arduino.h> // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
Uart Serial2 (&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
const long numChars = 2000;
char receivedChars[numChars];
boolean newData = false;
int i = 0;
int k = 0;
void SERCOM1_Handler()
{
Serial2.IrqHandler();
}
void setup() {
// initialize serial communication at 115200 bits per second: Serial1 is pin 0 and 1;
Serial1.begin(9600);
Serial2.begin(9600);
Serial1.println("<Arduino is ready>");
// Assign pins 10 & 11 SERCOM functionality
pinPeripheral(10, PIO_SERCOM);
pinPeripheral(11, PIO_SERCOM);
}
void loop() {
for (i;i<1;i++)
{
Serial2.println("+++");
delay(5000);
while (Serial2.available() > 0) {
Serial2.read();
}
}
for (k;k<1;k++)
{
Serial2.println("rdlfind 2 -30 -1");
}
recvWithStartEndMarkers();
showNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static long 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;
}
}
The actual data I have is:
<iakjdfoiahfuiwheri2ghw9vbguisbdv9082478y5943vbuidwsbug>
<1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
0000000000
9999999999
8888888888
7777777777
6666666666
5555555555
4444444444
3333333333
2222222222
1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
0000000000
9999999999
8888888888
7777777777
6666666666
5555555555
4444444444
3333333333
2222222222
1111111111
>
<11111111111111111111
22222222222222222222
33333333333333333333
44444444444444444444
55555555555555555555
66666666666666666666
77777777777777777777
88888888888888888888
99999999999999999999
00000000000000000000
99999999999999999999
88888888888888888888
77777777777777777777
66666666666666666666
55555555555555555555
444444444444444444444
33333333333333333333
22222222222222222222
11111111111111111111
>
While the processed data from Arduino is:
<Arduino is ready>
This just in ... iakjdfoiahfuiwheri2ghw9vbguisbdv9082478y5943vbuidwsbug
This just in ... 1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
0000000000
9999999999
8888888888
7777777777
6666666666
5555555555
4444444444
3333333333
2222222222
1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
0000000000
9999999999
8888888888
7777777777
6666666666
5555555555
4444444444
3333333333
2222222222
1111111111
This just in ... 11111111111111111111
22222222222222222222
33333333333333332
11111111111111111111
So I have 3 data in the memory, and you can see that the first two data seems to be captured correctly, but a large bunch of data at the end of the 3rd data is missing and also corrupted. Which seems to be a similar problem with my previous post that a section of the data was missing and corrupted.
In my code, I gave a "const long numChars = 5000;" which theoretically should be able to handle the amount of data I have now, but it doesn't seem.
Could you please help me with this?
thank you very much