ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
task_share.Queue Class Reference

This class implements 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 by allocating memory for the contents and setting up the components in an empty configuration. 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)
 Returns True if there are any items in the queue and False if the queue is empty. More...
 
def empty (self)
 Returns True if there are no items in the queue and False if there are any items therein. More...
 
def full (self)
 This method returns True if the queue is already full and there is no room for more data without overwriting existing data. More...
 
def num_in (self)
 This method returns the number of items which are currently in the queue. More...
 
def __repr__ (self)
 This method puts diagnostic information about the queue into a string.
 

Static Public Attributes

int ser_num = 0
 A counter used to give serial numbers to queues for diagnostic use.
 

Detailed Description

This class implements a queue which is used to transfer data from one task to another.

If parameter 'thread_protect' is True, the transfer will be protected from corruption in the case that one thread might interrupt another due to threading or due to one thread being run as an interrupt service routine.

Constructor & Destructor Documentation

◆ __init__()

def task_share.Queue.__init__ (   self,
  type_code,
  size,
  thread_protect = True,
  overwrite = False,
  name = None 
)

Initialize a queue by allocating memory for the contents and setting up the components in an empty configuration.

The data type code is given as for the Python 'array' type, which can be any of

  • b (signed char), B (unsigned char)
  • h (signed short), H (unsigned short)
  • i (signed int), I (unsigned int)
  • l (signed long), L (unsigned long)
  • q (signed long long), Q (unsigned long long)
  • f (float), or 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

◆ any()

def task_share.Queue.any (   self)

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)

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)

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 any items.

Parameters
in_ISRSet this to True if calling from within an ISR

◆ num_in()

def task_share.Queue.num_in (   self)

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.

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: