Difference between revisions of "Component: Circular Buffer (8 bit) (Storage)"

From Flowcode Help
Jump to navigationJump to search
 
(5 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
==Circular Buffer (8-bit) component==
 
==Circular Buffer (8-bit) component==
 
Circular buffer component allowing easy and efficient first in first out (FIFO) style data byte storage. Useful when used with a comms component to capture data as it comes in ready for processing when we have time. Also features macros to allow you to check for specific incoming responses such as "OK" or "ERROR".
 
Circular buffer component allowing easy and efficient first in first out (FIFO) style data byte storage. Useful when used with a comms component to capture data as it comes in ready for processing when we have time. Also features macros to allow you to check for specific incoming responses such as "OK" or "ERROR".
 +
 +
==Component Pack==
 +
 +
FREE
  
 
==Detailed description==
 
==Detailed description==
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
  
  
Line 22: Line 38:
  
 
==Examples==
 
==Examples==
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
  
  
Line 108: Line 136:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetIndexedByte'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetArray'''
 
|-
 
|-
| colspan="2" | Gets the value of a single byte at a known location in the buffer. Leaves the buffer contents and pointers untouched. 
+
| colspan="2" | Reads an array of Bytes from the circular buffer.  
 
|-
 
|-
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | address
 
|-
 
| colspan="2" |  
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WaitForValue'''
 
|-
 
| colspan="2" | Waits for an array of values to appear in the circular buffer. Returns 0 to indicate a timeout. Returns 1 to indicate the data has been found. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
 
| width="90%" | Value
 
|-
 
| colspan="2" |  
 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | NumChars
+
| width="90%" | Data
 
|-
 
|-
| colspan="2" | Number of characters to try and look for 
+
| colspan="2" | Data array to store the data into 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | RemoveContent
 
|-
 
| colspan="2" | 0=Leave the buffer contents untouched, 1=Remove values as you go 
 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Timeout
+
| width="90%" | NumBytes
 
|-
 
|-
| colspan="2" | Max amount of time to wait in milliseconds before returning 0=WaitForever 
+
| colspan="2" | Number of bytes to read from the buffer 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 159: Line 159:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetNumberBytes'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetString'''
 
|-
 
|-
| colspan="2" | Returns the number of valid data bytes currently inside the buffer. 
+
| colspan="2" | Reads a string of characters from the circular buffer.  
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | MaxLength
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
 
|-
 
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
+
| colspan="2" | Max number of bytes the string can store including the null byte 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetConsoleHandle'''
 
 
|-
 
|-
| colspan="2" | Gets the handle to the console allowing data displaying on the panel etc. 
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] -
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PeekByte'''
 
|-
 
| colspan="2" | Reads the next available byte from the circular buffer without advancing the current index, Returns 255/512 if the buffer is empty. 
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 198: Line 177:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PutByte'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PutArray'''
 
|-
 
|-
| colspan="2" | Add byte to the next free location inside the circular buffer. If the data goes into the buffer correctly then return 1. Otherwise the buffer is full and the return value will equal 0. 
+
| colspan="2" | Writes an array of bytes into the circular buffer. 
 
|-
 
|-
 
|-
 
|-
Line 206: Line 185:
 
| width="90%" | Data
 
| width="90%" | Data
 
|-
 
|-
| colspan="2" |  
+
| colspan="2" | Byte array to write into the buffer 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | NumBytes
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetByte'''
 
|-
 
| colspan="2" | Reads the next available byte from the circular buffer, Returns 255 if the buffer is empty. 
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''FlushBuffer'''
 
|-
 
| colspan="2" | Clears the contents of the buffer and re-initialises the index locations. 
 
 
|-
 
|-
 +
| colspan="2" | Number of bytes to write into the buffer 
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 242: Line 200:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetConsoleHandle'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetIndexedByte'''
 
|-
 
|-
| colspan="2" | Gets the handle to the console allowing data displaying on the panel etc. 
+
| colspan="2" | Gets the value of a single byte at a known location in the buffer. Leaves the buffer contents and pointers untouched. 
 
|-
 
|-
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] -
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendByteArray'''
 
|-
 
| colspan="2" | Sends an array of bytes to the COM port. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | Data
 
|-
 
| colspan="2" | Data byte array to send 
 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Length
+
| width="90%" | address
|-
 
| colspan="2" | Number of bytes to send 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveBinary16Bit'''
 
|-
 
| colspan="2" | Receives a binary 16-bit value split across two bytes. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | MSBfirst
 
|-
 
| colspan="2" | 0=Least significant byte first, 1=Most significant byte first 
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | Timeout
 
|-
 
| colspan="2" | Max amount of time in ms to wait between bytes 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveFloat'''
 
|-
 
| colspan="2" | Attempts to receive a floating point number as ASCII characters and convert back into a numeric value. Note this function will receive until a timeout or a none numeric char is received, the none numeric char will be lost. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | Timeout
 
|-
 
| colspan="2" | Max time in ms to wait in between bytes 
 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | IgnoreData
 
|-
 
| colspan="2" | 0=Dont ignore any data, 1=Ignore any initial none numeric data 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] -
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendFloat'''
 
|-
 
| colspan="2" | Sends out a floating point number as an ASCII String from the UART interface. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | Number
 
 
|-
 
|-
 
| colspan="2" |  
 
| colspan="2" |  
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 342: Line 218:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendHexNumber'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WaitForValue'''
 
|-
 
|-
| colspan="2" | Sends out a number as an ASCII hexadecimal String from the UART interface. 
+
| colspan="2" | Waits for an array of values to appear in the circular buffer. Returns 0 to indicate a timeout. Returns 1 to indicate the data has been found. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
+
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Number
+
| width="90%" | Value
 
|-
 
|-
 
| colspan="2" |  
 
| colspan="2" |  
Line 355: Line 231:
 
| width="90%" | NumChars
 
| width="90%" | NumChars
 
|-
 
|-
| colspan="2" | Number of characters in the string data, 0 for auto, 2 for 0x00, 4 for 0x0000 
+
| colspan="2" | Number of characters to try and look for 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | Prefix
 
|-
 
| colspan="2" | Generate hexadecimal prefix 0x e.g. 1= 0xFF, 0= FF 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFlowControl'''
 
|-
 
| colspan="2" | Allows the Flowcontrol signals to be enabled or disabled. 
 
|-
 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | State
+
| width="90%" | RemoveContent
 
|-
 
|-
| colspan="2" | A value of 0 disables flow control, 1 or above willl enable flow control. 
+
| colspan="2" | 0=Leave the buffer contents untouched, 1=Remove values as you go 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''OpenPort'''
 
|-
 
| colspan="2" | Opens the currently selected COM port, allowing data to be sent and received. 
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveHexNumber'''
 
|-
 
| colspan="2" | Attempts to receive a hex number as ASCII characters and convert back into a numeric value. Note this function will receive until a timeout or a none hexadecimal char is received, the none numeric char will be lost. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
 
| width="90%" | Timeout
 
| width="90%" | Timeout
 
|-
 
|-
| colspan="2" | Max time in ms to wait in between bytes 
+
| colspan="2" | Max amount of time to wait in milliseconds before returning 0=WaitForever 
 
|-
 
|-
| width="10%" align="center" | [[File:]] -
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | IgnoreData
 
|-
 
| colspan="2" | 0=Dont ignore any data, 1=Ignore any initial none numeric data 
 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | Prefix
 
|-
 
| colspan="2" | Look for prefix before receiving, 1=0xFF, 0=FF 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 429: Line 251:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetProp'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetNumberBytes'''
 
|-
 
|-
| colspan="2" | Allows the COM port property to be set from a parent component. 
+
| colspan="2" | Returns the number of valid data bytes currently inside the buffer. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | PropName
 
|-
 
| colspan="2" |  
 
|-
 
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
 
| width="90%" | PropVal
 
|-
 
| colspan="2" |  
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 452: Line 264:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendBinary32Bit'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetConsoleHandle'''
 
|-
 
|-
| colspan="2" | Sends out a 32-bit binary value split across four bytes. 
+
| colspan="2" | Gets the handle to the console allowing data displaying on the panel etc. 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
 
| width="90%" | Value
 
 
|-
 
|-
| colspan="2" |  
 
 
|-
 
|-
| width="10%" align="center" | [[File:]] -
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-h32-icon.png]] - HANDLE
| width="90%" | MSBfirst
 
|-
 
| colspan="2" | 0=Least significant byte first, 1=Most significant byte first 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 475: Line 277:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendBinaryFloat'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PeekByte'''
 
|-
 
|-
| colspan="2" | Sends out a 32-bit binary floating point value split across four bytes. 
+
| colspan="2" | Reads the next available byte from the circular buffer without advancing the current index, Returns 255/512 if the buffer is empty. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:]] -
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Value
 
|-
 
| colspan="2" |  
 
|-
 
| width="10%" align="center" | [[File:]] -
 
| width="90%" | MSBfirst
 
|-
 
| colspan="2" | 0=Least significant byte first, 1=Most significant byte first 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 498: Line 290:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetProp'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PutString'''
 
|-
 
|-
| colspan="2" | Allows the property filter for the COM port list to be copied to a parent component. 
+
| colspan="2" | Writes a string of characters into the circular buffer. 
 
|-
 
|-
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
 
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | PropName
+
| width="90%" | Data
 
|-
 
|-
| colspan="2" |  
+
| colspan="2" | String data array to write into the buffer 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 516: Line 308:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveByteArray'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PutByte'''
 
|-
 
|-
| colspan="2" | Attempts to receive an array of bytes using the COM port Returns the number of bytes received.  
+
| colspan="2" | Add byte to the next free location inside the circular buffer. If the data goes into the buffer correctly then return 1. Otherwise the buffer is full and the return value will equal 0. 
 
|-
 
|-
 
|-
 
|-
Line 526: Line 318:
 
| colspan="2" |  
 
| colspan="2" |  
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | MaxLength
 
|-
 
| colspan="2" | Max number of bytes to try and read 
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | Timeout
 
|-
 
| colspan="2" | Time to wait for incoming data in milliseconds 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 544: Line 326:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveString'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetByte'''
 
|-
 
|-
| colspan="2" | Attempts to receive an string using the COM port Returns the number of bytes received.  
+
| colspan="2" | Reads the next available byte from the circular buffer, Returns 255 if the buffer is empty. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Timeout
 
|-
 
| colspan="2" | Time to wait for incoming data in milliseconds 
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | MaxLength
 
|-
 
| colspan="2" | Max number of bytes to try and read 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 567: Line 339:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PWMEnable'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''FlushBuffer'''
 
|-
 
|-
| colspan="2" | Allows pulse width modulated transistor outputs to be switched on or off. Bit 0 = Enable AB Bit 1 = A / Bit 2 = B Bit 3 = C / Bit 4 = D Bit 5 = Enable CD 
+
| colspan="2" | Clears the contents of the buffer and re-initialises the index locations. 
 
|-
 
|-
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | EnableMask
 
|-
 
| colspan="2" | Range 0-63 or 0b00000 to 0b111111 
 
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 
|-
 
| colspan="2" |  
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetProp'''
 
|-
 
| colspan="2" | Allows the property filter for the COM port list to be copied to a parent component. 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
 
| width="90%" | PropName
 
|-
 
| colspan="2" |  
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 647: Line 383:
 
|-
 
|-
 
| colspan="2" | Decides if the contents of the buffer are shown in a console tab. 
 
| colspan="2" | Decides if the contents of the buffer are shown in a console tab. 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections'''
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations'''
 
|-
 
 
|}
 
|}

Latest revision as of 17:24, 9 November 2022

Author Matrix Ltd
Version 1.5
Category Storage


Circular Buffer (8-bit) component

Circular buffer component allowing easy and efficient first in first out (FIFO) style data byte storage. Useful when used with a comms component to capture data as it comes in ready for processing when we have time. Also features macros to allow you to check for specific incoming responses such as "OK" or "ERROR".

Component Pack

FREE

Detailed description

No detailed description exists yet for this component

Examples

Basic Example

Circular Buffer Example File demonstrating the storage and retrieval of data. FC6 Icon.png CircularBuffer System panel showing data in and data out of the FIFO circular buffer.

LCDData.jpg


Console window showing data in the circular buffer on the first simulation run.

CircBuff1.jpg


Console window showing data in the circular buffer on the second simulation run, note that the start location has been shifted and will eventually wrap hence the name, circular buffer.

CircBuff2.jpg


Keypad Based Door Entry System

Each key press on the keypad is fed into the Circular Buffer component. We then poll the buffer to see if the correct characters for the password have been entered. FC6 Icon.png Keypad Door Entry If the correct sequence is detected then we activate the solenoid component for 5 seconds.

KeypadCirBuff.jpg


Reliable Communications Data

This example takes bytes received from the Serial UART and uses the circular buffer to store the bytes as they come in using an interrupt. The main routine then forwards the bytes through to a PC using a USB serial connection. This example would work equally well for creating a bridge between several UARTs or translating Serial to SPI or I2C etc. FC6 Icon.png UART to USB Serial Data Bridge

AT Command Responses

This example sends out AT commands to an AT based communications module e.g. GSM or Bluetooth. The response from the module is stored in the circular buffer and we then scan the buffer for appropriate responses from the module. The outcome of the command is then printed to the LCD to let you know if the command was accepted, caused an error or simply timed out. FC6 Icon.png Reliable AT Command Response

Searching for none ASCII characters

The LookForValue and WaitForValue functions can be useful when searching for ASCII data in the circular buffer. You can also use the escape sequence \x to search for hexadecimal values in the buffer.

e.g. "ABC\xFF\x80"

Will look for the ASCII characters A,B,C followed by the byte values 255 (0xFF) and 128 (0x80).

Downloadable macro reference

Fc9-comp-macro.png LookForValue
Scans the buffer for an array of specific values. Returns 0 if the value is not found. Returns 1 if the value is found. 
Fc9-string-icon.png - STRING Value
Value to look for, can be a string or byte array, 
Fc9-u8-icon.png - BYTE NumChars
The number of characters you wish to try and match 
Fc9-u8-icon.png - BYTE RemoveContent
0=Leave data alone, 1=Remove data from buffer 
Fc9-u8-icon.png - BYTE ResetFind
0=Continue the find from the last operation, 1=Start again 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png GetArray
Reads an array of Bytes from the circular buffer.  
Fc9-u8-icon.png - BYTE Data
Data array to store the data into 
Fc9-u16-icon.png - UINT NumBytes
Number of bytes to read from the buffer 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png GetString
Reads a string of characters from the circular buffer.  
Fc9-u16-icon.png - UINT MaxLength
Max number of bytes the string can store including the null byte 
Fc9-string-icon.png - STRING Return


Fc9-comp-macro.png PutArray
Writes an array of bytes into the circular buffer. 
Fc9-u8-icon.png - BYTE Data
Byte array to write into the buffer 
Fc9-u16-icon.png - UINT NumBytes
Number of bytes to write into the buffer 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png GetIndexedByte
Gets the value of a single byte at a known location in the buffer. Leaves the buffer contents and pointers untouched. 
Fc9-u16-icon.png - UINT address
 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png WaitForValue
Waits for an array of values to appear in the circular buffer. Returns 0 to indicate a timeout. Returns 1 to indicate the data has been found. 
Fc9-string-icon.png - STRING Value
 
Fc9-u8-icon.png - BYTE NumChars
Number of characters to try and look for 
Fc9-u8-icon.png - BYTE RemoveContent
0=Leave the buffer contents untouched, 1=Remove values as you go 
Fc9-u16-icon.png - UINT Timeout
Max amount of time to wait in milliseconds before returning 0=WaitForever 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png GetNumberBytes
Returns the number of valid data bytes currently inside the buffer. 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png GetConsoleHandle
Gets the handle to the console allowing data displaying on the panel etc. 
Fc9-h32-icon.png - HANDLE Return


Fc9-comp-macro.png PeekByte
Reads the next available byte from the circular buffer without advancing the current index, Returns 255/512 if the buffer is empty. 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png PutString
Writes a string of characters into the circular buffer. 
Fc9-string-icon.png - STRING Data
String data array to write into the buffer 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png PutByte
Add byte to the next free location inside the circular buffer. If the data goes into the buffer correctly then return 1. Otherwise the buffer is full and the return value will equal 0. 
Fc9-u8-icon.png - BYTE Data
 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png GetByte
Reads the next available byte from the circular buffer, Returns 255 if the buffer is empty. 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png FlushBuffer
Clears the contents of the buffer and re-initialises the index locations. 
Fc9-void-icon.png - VOID Return



Property reference

Fc9-prop-icon.png Properties
Fc9-type-21-icon.png Buffer Size
Sets the number of byte elements inside the circular buffer. 
Fc9-type-16-icon.png Storage Type
When buffer is full this property decides what to do. Store first x values - Will retain the information inside the buffer, new data will be discarded. Store last x values - Will discard the oldest location in the buffer and overwrite with new data. 
Fc9-type-16-icon.png Memory Type
 
Fc9-type-16-icon.png Return Type
Specifies the way the receive function indicates a timeout. 8 Bit mode - Timeout is represented by the value 255. 16 Bit mode - Timeout is represented by the value 512 allowing the value 255 to represent valid data 
Fc9-type-7-icon.png Console
Decides if the contents of the buffer are shown in a console tab.