Difference between revisions of "Component: Circular Buffer (8 bit) (Storage)"
Line 16: | Line 16: | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
Line 24: | Line 26: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
Revision as of 13:31, 17 November 2021
Author | Matrix Ltd |
Version | 1.5 |
Category | Storage |
Contents
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".
Detailed description
No detailed description exists yet for this component
Examples
Basic Example
Circular Buffer Example File demonstrating the storage and retrieval of data.
CircularBuffer
System panel showing data in and data out of the FIFO circular buffer.
Console window showing data in the circular buffer on the first simulation run.
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.
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.
Keypad Door Entry
If the correct sequence is detected then we activate the solenoid component for 5 seconds.
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.
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.
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
![]() |
GetIndexedByte |
Gets the value of a single byte at a known location in the buffer. Leaves the buffer contents and pointers untouched. | |
![]() |
address |
![]() |
Return |
![]() |
GetNumberBytes |
Returns the number of valid data bytes currently inside the buffer. | |
![]() |
Return |
![]() |
GetConsoleHandle |
Gets the handle to the console allowing data displaying on the panel etc. | |
[[File:]] - | Return |
![]() |
PeekByte |
Reads the next available byte from the circular buffer without advancing the current index, Returns 255/512 if the buffer is empty. | |
![]() |
Return |
![]() |
GetByte |
Reads the next available byte from the circular buffer, Returns 255 if the buffer is empty. | |
![]() |
Return |
![]() |
FlushBuffer |
Clears the contents of the buffer and re-initialises the index locations. | |
![]() |
Return |