The problem with this was that somehow, when I read out the serial buffer, this command was sent/read out repeatedly.

I then modified the code like this:
Code: [Select]
Serial.println("INQUIRY 1");
delay(500);
Serial.flush();


This works better, but not in every case. And even more, I don't know why it works. If I for example remove the delay, I have the same problems again. Also, I was once told that delay should not be used...

Also, I don't know why it works with Serial.flush(). Doesn't this command delete the serial buffer? Shouldn't I then not be able to read what I have printed before?

Any help with this is appreciated...

By the way, I read out the serial buffer like this:[code] while(Serial.available() > 0){ message_part = Serial.read(); message[message_part_count] = message_part; message_part_count++; if (message_part == char(10)){ // only send out message if it's complete (with line feed) Serial.print(message); delay(500); Serial.flush(); reset_message(); } // end if } // end while [/code]">

The problem with this was that somehow, when I read out the serial buffer, this command was sent/read out repeatedly.

I then modified the code like this:
Code: [Select]
Serial.println("INQUIRY 1");
delay(500);
Serial.flush();


This works better, but not in every case. And even more, I don't know why it works. If I for example remove the delay, I have the same problems again. Also, I was once told that delay should not be used...

Also, I don't know why it works with Serial.flush(). Doesn't this command delete the serial buffer? Shouldn't I then not be able to read what I have printed before?

Any help with this is appreciated...

By the way, I read out the serial buffer like this:[code] while(Serial.available() > 0){ message_part = Serial.read(); message[message_part_count] = message_part; message_part_count++; if (message_part == char(10)){ // only send out message if it's complete (with line feed) Serial.print(message); delay(500); Serial.flush(); reset_message(); } // end if } // end while [/code]">

The problem with this was that somehow, when I read out the serial buffer, this command was sent/read out repeatedly.

I then modified the code like this:
Code: [Select]
Serial.println("INQUIRY 1");
delay(500);
Serial.flush();


This works better, but not in every case. And even more, I don't know why it works. If I for example remove the delay, I have the same problems again. Also, I was once told that delay should not be used...

Also, I don't know why it works with Serial.flush(). Doesn't this command delete the serial buffer? Shouldn't I then not be able to read what I have printed before?

Any help with this is appreciated...

By the way, I read out the serial buffer like this:[code] while(Serial.available() > 0){ message_part = Serial.read(); message[message_part_count] = message_part; message_part_count++; if (message_part == char(10)){ // only send out message if it's complete (with line feed) Serial.print(message); delay(500); Serial.flush(); reset_message(); } // end if } // end while [/code]">
hi there

I'm working with a bluegiga wt32 bluetooth adapter at the moment. I never worked with a serial interface so naturally, I do have some questions. generally, it works quite well, but there seem to be some problems with the serial buffer (or so I guess).

Initially I sent the serial commands just like this:
Code: [Select]
Serial.println("INQUIRY 1");


The problem with this was that somehow, when I read out the serial buffer, this command was sent/read out repeatedly.

I then modified the code like this:
Code: [Select]
Serial.println("INQUIRY 1");
delay(500);
Serial.flush();


This works better, but not in every case. And even more, I don't know why it works. If I for example remove the delay, I have the same problems again. Also, I was once told that delay should not be used...

Also, I don't know why it works with Serial.flush(). Doesn't this command delete the serial buffer? Shouldn't I then not be able to read what I have printed before?

Any help with this is appreciated...

By the way, I read out the serial buffer like this:[code] while(Serial.available() > 0){ message_part = Serial.read(); message[message_part_count] = message_part; message_part_count++; if (message_part == char(10)){ // only send out message if it's complete (with line feed) Serial.print(message); delay(500); Serial.flush(); reset_message(); } // end if } // end while [/code]


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir