ME405 Library  Version 0.38
Python library in support of ME405 class
task_share.Queue Class Reference

A queue which is used to transfer data from one task to another. More...

Inheritance diagram for task_share.Queue:
Collaboration diagram for task_share.Queue:

Public Member Functions

def __init__ (self, type_code, size, thread_protect=False, 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.
 

Detailed Description

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:

import task_share
# This queue holds unsigned short (16-bit) integers
my_queue = task_share.Queue ('H', 100, name="My Queue")
# Somewhere in one task, put data into the queue
my_queue.put (some_data)
# In another task, read data from the queue
something = my_queue.get ()
A queue which is used to transfer data from one task to another.
Definition: task_share.py:90

Constructor & Destructor Documentation

◆ __init__()

def task_share.Queue.__init__ (   self,
  type_code,
  size,
  thread_protect = False,
  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)
Parameters
type_codeThe type of data items which the queue can hold
sizeThe maximum number of items which the queue can hold
thread_protectTrue if mutual exclusion protection is used
overwriteIf True, oldest data will be overwritten with new data if the queue becomes full
nameA short name for the queue, default QueueN where N is a serial number for the queue

Member Function Documentation

◆ __repr__()

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.

◆ any()

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.

Returns
True if items are in the queue, False if not

◆ empty()

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.

Returns
True if queue is empty, False if it's not empty

◆ full()

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.

Returns
True if the queue is full

◆ get()

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:

def some_task ():
# Setup
while True:
if my_queue.any ():
something = my_queue.get ()
do_something_with (something)
# More loop stuff
yield 0
Parameters
in_ISRSet this to True if calling from within an ISR

◆ num_in()

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.

Returns
The number of items in the queue

◆ put()

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:

def some_task ():
# Setup
while True:
if not my_queue.full ():
my_queue.put (create_something_to_put ())
yield 0
Parameters
itemThe item to be placed into the queue
in_ISRSet this to True if calling from within an ISR

The documentation for this class was generated from the following file: