I have a need to receive a specific confirmation packet after commanding my transmitting Xbee to stop sending normal packets.
My buffer still has normal packets in it when this happens, so next time I call readPacket(), I don't want to see them. So right before I call my stop command, I try to purge the incoming buffer like this:
void burnSerial(void) {
while (xbee.readPacket(20)) {
xbee.getResponse().getRx16Response(rx16);
} //read all available responses
// only do this when not in a constant stream of responses or it may hang.
while (Serial.available()) { Serial.read(); }
//burn whatever may be in serial buffer
}
But this doesn't work. The next time I call xbee.readPacket()
, I see tons of normal packets before I finally see my confirmation packet. Why don't these functions do anything for me at all?