Plot Something - ME 405 Term Project
|
A queue which is used to transfer data from one task to another. More...
Public Member Functions | |
def | __init__ (self, type_code, size, thread_protect=True, overwrite=False, name=None) |
Initialize a queue object to carry and buffer data between tasks. More... | |
def | put (self, item, in_ISR=False) |
Put an item into the queue. More... | |
def | get (self, in_ISR=False) |
Read an item from the queue. More... | |
def | any (self) |
Check if there are any items in the queue. More... | |
def | empty (self) |
Check if the queue is empty. More... | |
def | full (self) |
Check if the queue is full. More... | |
def | num_in (self) |
Check how many items are in the queue. More... | |
def | clear (self) |
Remove all contents from the queue. | |
def | __repr__ (self) |
This method puts diagnostic information about the queue into a string. More... | |
Static Public Attributes | |
int | ser_num = 0 |
A counter used to give serial numbers to queues for diagnostic use. | |
A queue which is used to transfer data from one task to another.
If parameter 'thread_protect' is True
when a queue is created, transfers of data will be protected from corruption in the case that one task might interrupt another due to use in a pre-emptive multithreading environment or due to one task being run as an interrupt service routine.
An example of the creation and use of a queue is as follows:
def task_share.Queue.__init__ | ( | self, | |
type_code, | |||
size, | |||
thread_protect = True , |
|||
overwrite = False , |
|||
name = None |
|||
) |
Initialize a queue object to carry and buffer data between tasks.
This method sets up a queue by allocating memory for the contents and setting up the components in an empty configuration.
Each queue can only carry data of one particular type which must be chosen from the following list. The data type is specified by a one-letter type code which is given as for the Python array.array
type, which can be any of the following:
b (signed char) | B (unsigned char) | 8 bit integers |
h (signed short) | H (unsigned short) | 16 bit integers |
i (signed int) | I (unsigned int) | 32 bit integers (probably) |
l (signed long) | L (unsigned long) | 32 bit integers |
q (signed long long) | Q (unsigned long long) | 64 bit integers |
f (float) | d (double-precision float) |
type_code | The type of data items which the queue can hold |
size | The maximum number of items which the queue can hold |
thread_protect | True if mutual exclusion protection is used |
overwrite | If True , oldest data will be overwritten with new data if the queue becomes full |
name | A short name for the queue, default QueueN where N is a serial number for the queue |
Reimplemented from task_share.BaseShare.
def task_share.Queue.__repr__ | ( | self | ) |
This method puts diagnostic information about the queue into a string.
It shows the queue's name and type as well as the maximum number of items and queue size.
def task_share.Queue.any | ( | self | ) |
Check if there are any items in the queue.
Returns True
if there are any items in the queue and False
if the queue is empty.
True
if items are in the queue, False
if not def task_share.Queue.empty | ( | self | ) |
Check if the queue is empty.
Returns True
if there are no items in the queue and False
if there are any items therein.
True
if queue is empty, False
if it's not empty def task_share.Queue.full | ( | self | ) |
Check if the queue is full.
This method returns True
if the queue is already full and there is no room for more data without overwriting existing data.
True
if the queue is full def task_share.Queue.get | ( | self, | |
in_ISR = False |
|||
) |
Read an item from the queue.
If there isn't anything in there, wait (blocking the calling process) until something becomes available. If non-blocking reads are needed, one should call any()
to check for items before attempting to read from the queue. This is usually done in a low priority task:
in_ISR | Set this to True if calling from within an ISR |
def task_share.Queue.num_in | ( | self | ) |
Check how many items are in the queue.
This method returns the number of items which are currently in the queue.
def task_share.Queue.put | ( | self, | |
item, | |||
in_ISR = False |
|||
) |
Put an item into the queue.
If there isn't room for the item, wait (blocking the calling process) until room becomes available, unless the overwrite
constructor parameter was set to True
to allow old data to be clobbered. If non-blocking behavior without overwriting is needed, one should call full()
to ensure that the queue is not full before putting data into it:
item | The item to be placed into the queue |
in_ISR | Set this to True if calling from within an ISR |