Shop OBEX P1 Docs P2 Docs Learn Events
How do I zero out or clear a byte buffer? — Parallax Forums

How do I zero out or clear a byte buffer?

Don MDon M Posts: 1,653
edited 2012-04-28 18:04 in Propeller 1
I have a buffer declared that is 36 bytes. When I have a device connected to my setup it reads the data into the buffer. When I disconnect this device the buffer still contains the data. What I am looking to do is zero out or clear the buffer when the device is disconnected.

DataBuffer[36]

Thanks.
Don

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-28 17:03
    bytefill(@DataBuffer, 0, 36)
  • Mike GMike G Posts: 2,702
    edited 2012-04-28 17:04
    Zero terminate the buffer
    DataBuffer[0] := 0

    Fill the buffer with zeros as posted above

    Set buffer count to zero.

    Why do you need to clear the buffer?

    Post your code.
  • Don MDon M Posts: 1,653
    edited 2012-04-28 17:44
    @Duane- Thanks. That is what I was looking for. Couldn't remember the code but knew I'd seen it somewhere here before.

    @Mike- I'm building a device that will test the communications of a manufactured product (used on an assembly line) and report some information about that product (serial number etc.). When the product is then unplugged from the tester I want the data to be cleared so when the next product that is plugged in and tested, but doesn't happen to work, won't incorrectly report the data left in the buffer from the previous test.
  • Mike GMike G Posts: 2,702
    edited 2012-04-28 18:04
    You can zero out the buffer. That will work.

    A better approach, IMHO, is to zero terminate the buffer or keep track of the buffer tail when the product is plugged in. This way each new reading regardless of length is always correct. Plus no figuring out when the product is unplugged. The logic is all contained in the serial number write.
Sign In or Register to comment.