MEGA 2560 R3 clone. I'm a retired longtime programmer and new Arduino and C++ user. Project is to read two different UART streams, save the data in a char array, and once I have a full set of values, parse it to display on a LCD char display. Both data streams contain no delimeters or starting and ending chars - they stream data continuously, repeating data over and over.
The simplest of the two streams contains just two variable values, and the other contains 25 entries. An example of the simpler stream: "0DT=IIA=0DT=IIA=". In this example, the value of "T" is "II" and "A" is "0D". I don't care about pairing up values so I have a matched set, I'm happy to take what I see.
This code doesn't contain any of the parsing or LCD functions, I'm still trying to get the data captured. I had this working with Strings, but wound up with data corruption - so I'm redoing it with char arrays.
I can't seem to be able to figure out to recognize when the char array contains a apecific substring - that would lead me to start or stop gathering data. I've tried three different ways to ID that the result contains "A=", but am having trouble.
I am attaching a screenshot of the serial monitor after a brief run. I tried to cut/paste the data, but it does contain un-printable chars and wouldn't paste. To make the test output easier to read, I output both the raw data as it comes in, and the assembled string - one on top of the other, in 80 byte chunks.
Thanks in advance for your help. Steve.
char TMc[250];
char AA[3] = "=A";
void setup()
{
Serial.begin(9600); // speed to talk to the computer
Serial2.begin(2400); // speed to read the TM
}
void loop() {
static int n = 0;
bool Got1 = false;
if (Serial2.available() > 0)
{
char a = Serial2.read();
Serial.print(a);
TMc[n] = a;
TMc[n + 1] = '\0';
// Try 1
if (n > 5
& TMc[n - 3] == "="
& TMc[n - 2] == "A"
)
{ Serial.println("*SS*");
Got1 = true;
} //EndIf
// Try 2
if (strstr(TMc, AA) > 0)
{
Serial.println("*AA*"); //EndIf
}
//Try 3
if (strstr(TMc, "=A") > 0)
{
Serial.println("*BB*"); //EndIf
}
//Chop test data into 80 char chunks to make it more readable on the Monitor.
//Output both the raw stream characters one at a time and the built char array one above the other.
//Raw data is displayed with a leading ":" and char data with a "|"
if (n > 80 or Got1)
{ Serial.println();
Serial.print(": ");
for (int i = 0; i <= n; i++)
{
Serial.print(TMc[i]);
}
Serial.print( " Got1= ");
Serial.print(Got1);
Serial.println();
Serial.print("| ");
n = 1;
TMc[0] = "]";;
TMc[1] = '\0';
Got1 = false;
} // end n>
n++;
} // end Available
} // end loop
