3.4. Parallel (or asynchronous) Sender

class pyrobotics.parallel_senders.ParallelSender(command, timeout=300000, attempts=1)

Sends a command and waits for the answer in parallel to other thread’s execution, allowing other thread’s to poll if the response have been received.

Parameters:
  • command (Command) – Command to be sent, must be an instance of class Command.
  • timeout (int) – (Default 300000) How much time (in miliseconds) to wait for response before trying again or aborting.
  • attempts (int) – (Default 1) How many attempts to send the command if no response is received after timeout. If attempts is 0, it will keep trying indefinitely until StopSending is called. (Use carefully)

Note

Notice the command is sent when the object is created.

response

A property for retrieving the response object generated by the command.

This property should be used when sending is False.

sending

A property that indicates whether the object is still waiting for a response.

3.4.1. Example

from pyrobotics import BB
from pyrobotics.parallel_senders import ParallelSender as PS
from otherModule import fastCommand, slowCommand

function_map = {
                'fast_command': fastCommand,
                'slow_command': slowCommand

def initialize():
  global function_map
  BB.Initialize(2000, function_map)
  BB.Start()
  BB.SetReady()

def main():
  initialize()

  p = PS(Command('command_name', 'command_params'), 3000)

  while p.sending:
    #do something
    print 'sending message...'

  if not p.response:
    print 'Sending failed, probably timed out.'
    return

  if p.response.result:
    print 'command was successful!'
  else:
    print 'command execution was UNsuccessful!'}

  BB.Wait()

if __name__ == '__main__':
  main()

Table Of Contents

Previous topic

3.3. Shared Variables

This Page