Array fundamentals and buffers ?
Hello all,
I have the following questions concerning arrays.
1) I want to write (9) bytes into an array as they enter my serial port, I am using FullDuplexSerial.
2) I·assume that I need to declare an array with "0-8" elements.
3) I remember someone saying something about adding "1" element for a terminator, is this correct ? Therefore to recieve "8" bytes I need to declare
an array to hold "9" bytes. Need clarification on how to read and write to an array using a terminator and what that terminator should be.
4) When I write my code for the array should I set the pointer to location "0"·before the write or·does it auto default to that location ?
5) When I write the bytes to the array, reset the pointer and write to it again will it overwrite the existing values already in the array as long as I am sending "9" bytes every time.
6) Is there a simple code fragment that will reset all the elements in an array to "0" or clear an array ?
Is the buffer in FullDuplexSerial a "LIFO" buffer ?
Thanks,
JMLStamp2p
·
I have the following questions concerning arrays.
1) I want to write (9) bytes into an array as they enter my serial port, I am using FullDuplexSerial.
2) I·assume that I need to declare an array with "0-8" elements.
3) I remember someone saying something about adding "1" element for a terminator, is this correct ? Therefore to recieve "8" bytes I need to declare
an array to hold "9" bytes. Need clarification on how to read and write to an array using a terminator and what that terminator should be.
4) When I write my code for the array should I set the pointer to location "0"·before the write or·does it auto default to that location ?
5) When I write the bytes to the array, reset the pointer and write to it again will it overwrite the existing values already in the array as long as I am sending "9" bytes every time.
6) Is there a simple code fragment that will reset all the elements in an array to "0" or clear an array ?
Is the buffer in FullDuplexSerial a "LIFO" buffer ?
Thanks,
JMLStamp2p
·
Comments
2) Yes. All arrays start at element zero. To have 9 elements, you will use subscripts from 0 to 8, but you declare the array with size 9.
3) Whether you need a terminating value depends on how you're going to use the array.
4) Nothing happens automatically. Your program has to do everything unless you use some existing routine that does things a particular way.
5) Yes
6) Yes. Use BYTEFILL. If your array is called MyArray, you can use: BYTEFILL(@MyArray,0,9). Look it up in the Propeller manual.
The buffer in FullDuplexSerial is a First-In-First-Out (FIFO) buffer. A LIFO buffer is Last-In-First-Out.
Here's a Spin fragment to receive 9 bytes from FullDuplexSerial object "serial" and put them into MyArray which is declared as a 9 byte array. "i" is any variable.
JMLStamp2p