1

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?

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Aug 25, 2016 at 20:06

1 Answer 1

1

It means there's a lot of latency between your issuing a command and getting a confirmation of the command's effect. When you send the command, it's best that you wait and read packets until you find the confirmation and then you return from the function or do whatever else you want to do. There is no need for a separate burnSerial() function, nor should you blindly discard data. So basically, the sequence of operations should be:

  • Send the command
  • Read packets until you find the 'confirmation' identification marker
  • Return or exit

This assumes that your transmitter only sends confirmation after it has halted the stream.

answered Aug 26, 2016 at 7:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.