HI,
#UKHeliBob : Thanks for the advice. Actually I knew it. MY fault. I apologize.
#AWOL: Correct. A big, big TYPO. Sorry, I should have discovered that - before I send the code. I was a bit frustrated, working on the code since early morning.
Here is the code (total):
String Istr;
byte _comma_count = 0;
String msg_fields[20] = "";
int Antal; /* danish for NUMBER */
String Command[] = {"WR","RD","HELP"};
void setup()
{
Serial.begin(9600);
}
void loop()
{
String Str = "WR";
Istr = readline();
if (Istr != "")
{
Istr.toUpperCase();
Antal = getCSVfields(Istr);
//
// this is a test , trying to make it easier to find and manipulate string(s).
//
for (int n = 0; n <= 2; n++)
{
if (Command[n] == Str)
{
Serial.println('Command found ');
}
else
{
Serial.println('Command not found');
}
}
/*
if (Antal != 0 )
{
Serial.print("antal = ");
Serial.println(Antal);
Serial.print("comm[0] = ");
Serial.println(msg_fields[0]);
}
String Comm = msg_fields[0];
Serial.print("NY comm = ");
Serial.print(msg_fields[0]);
Serial.print(" '");
Serial.print(Comm);
Serial.print("' '");
Serial.print(Comm[0]);
Serial.println("' ");
*/
//
// Tried if (msg_fields[0] = "RD") { } ... does not work
//
// this works:
if ((0x52 == msg_fields[0][0]) && (0x44 == msg_fields[0][1]))
{
RDCommand();
}
else if ((0x57 == msg_fields[0][0]) && (0x52 == msg_fields[0][1]))
{
WRCommand();
}
Antal = 0;
Istr = "";
}
}
String readline()
{
if (Serial.available() == 0) return ("");
Istr = "";
Istr = Serial.readStringUntil('\n'); /* \r == CR \n = LF */
return (Istr);
}
int getCSVfields( String input_buffer)
{
byte _sentencePos = 0;
_comma_count = 0;
for (int n = 0; n <= 20; ++n)
{
msg_fields[n] = "";
}
while (1)
{
if (input_buffer[_sentencePos] == NULL) break;
if (input_buffer[_sentencePos] == 44) /* , */
{
_comma_count++;
msg_fields[_comma_count] = "";
_sentencePos++;
}
else
{
msg_fields[_comma_count] += input_buffer[_sentencePos];
_sentencePos++;
}
}
return _comma_count + 1;
}
void RDCommand()
{
Serial.println("test RD 1 ");
Serial.print("test COMM 2 ");
Serial.println(msg_fields[1]);
return;
}
void WRCommand()
{
Serial.println("test WR 1 ");
Serial.print("test COMM 2 ");
Serial.println(msg_fields[1]);
return;
}
Why do I have to use Integers as chars in
else if ((0x57 == msg_fields[0][0]) && (0x52 == msg_fields[0][1])) --- this ?