The response is probably NOT just the two characters O and K. There are likely other characters send, too, like carriage return and line feed. You need to determine EXACTLY what is returned, and read ALL the data returned.
Hmmmm. I'm still trying with serial monitor, not into actual hardware yet.. I just wanted to know how to read and confirm that second
OK is received before sending 2nd command.. As manual said we should send 2nd command only after OK is received..
I'm trying with string here..
String Sword = "";
void setup()
{
Serial.begin(9600);
//Sword.reserve(200);
Serial.println("Power On");
}
void loop()
{
while(Serial.available())
{
char Data = (char)Serial.read();
Sword += Data;
//Serial.print(Data);
//Serial.println(Sword);
}
if(Sword != "")
{
//Serial.println(Sword);
}
if(Sword == "OK") //First Response
{
Serial.print("N1 = TEST\n");// I got OK So Printed. First command
Sword ="";
char Data = (char)Serial.read();
Sword += Data;
//How to read OK Again ? For sending next command ?
if(Sword == "OK") //Second Response
{
Serial.println("N2 = TEST\n"); //Second Response
}
}
if(Sword == "NOTOK") //Just for Debugging
{
Serial.println("Rcvd Not OK!");
Sword ="";
}
}
And Also I'm not getting where the control get lost after printing 1st command