How do I zero out or clear a byte buffer?
Don M
Posts: 1,653
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
DataBuffer[36]
Thanks.
Don
Comments
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.
@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.
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.