I changes the SOP and EOP as per my requirement and the code that i used is this
#define SOP '\r\n'
#define EOP '\r\n'
#include <avr/wdt.h>
int count=0;
int i;
bool started = false;
bool ended = false;
char inData[200];
byte index;
void setup()
{
Serial.begin(9600);
// Other stuff...
}
void readprocess()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 199)
{
inData[index] = inChar;
Serial.print(inData[index]);
index++;
}
}
}
Serial.println('\n');
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
void loop()
{
Serial.write("===");
delay(100);
readprocess();
delay(2000);
Serial.write("LLL");
delay(100);
readprocess();
delay(2000);
Serial.write("\r\nAT+INQ\r\n");
delay(1000);
readprocess();
delay(30000);
readprocess();
delay(2000);
wdt_enable(WDTO_15MS);
wdt_reset();
}
I get this output
[color=red]===[/color]
OK
[color=red]LLL[/color]
OK
[color=red]AT+INQ[/color]
OK
+INQ:D4C1:FC:3A:56:7C,”C1-01”
00:1C:A4:14:7D:AA,”Sony Erics
if it can print from the buffer all the data detected as a result of the AT+INQ command, I can't understand why it is not able to print beyond the "ERICS" part
Before trying out the above program, i tried the following..
I removed the code that removes data from the buffer.
inData[index] = '\0';
and then,I tried printing the inData array elements after detecting the EOP char in this way,
if(started && ended)
{
// The end of packet marker arrived. Process the packet
for(i=0;i<200;i++)
{
if(inData[i]>0;)
Serial.print(inData[i]);
}
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
But for this code I dont get any output for my AT+INQ command (Maybe my modification to the code is wrong)