Package PyMata :: Module pymata_command_handler :: Class PyMataCommandHandler
[hide private]
[frames] | no frames]

Class PyMataCommandHandler

source code

        object --+        
                 |        
threading._Verbose --+    
                     |    
      threading.Thread --+
                         |
                        PyMataCommandHandler

This class handles all data interchanges with Firmata The receive loop runs in its own thread.

Messages to be sent to Firmata are queued through a deque to allow for priority messages to take precedence. The deque is checked within the receive loop for any outgoing messages.

There is no blocking in either communications direction.

There is blocking when accessing the data tables through the _data_lock

Instance Methods [hide private]
 
__init__(self, transport, command_deque, data_lock)
constructor for CommandHandler class
source code
 
stop(self) source code
 
is_stopped(self) source code
 
auto_discover_board(self, max_wait_time=30)
This method will allow up to max_wait_time seconds for discovery (communicating with) an Arduino board and then will determine a pin configuration table for the board.
source code
 
report_version(self, data)
This method processes the report version message, sent asynchronously by Firmata when it starts up or after refresh_report_version() is called
source code
 
set_analog_latch(self, pin, threshold_type, threshold_value)
This method "arms" a pin to allow data latching for the pin.
source code
 
set_digital_latch(self, pin, threshold_type)
This method "arms" a pin to allow data latching for the pin.
source code
 
get_analog_latch_data(self, pin)
This method reads the analog latch table for the specified pin and returns a list that contains: [latch_state, latched_data, and time_stamp].
source code
 
get_digital_latch_data(self, pin)
This method reads the digital latch table for the specified pin and returns a list that contains: [latch_state, latched_data, and time_stamp].
source code
 
report_firmware(self, data)
This method processes the report firmware message, sent asynchronously by Firmata when it starts up or after refresh_report_firmware() is called
source code
 
analog_message(self, data)
This method handles the incoming analog data message.
source code
 
digital_message(self, data)
This method handles the incoming digital message.
source code
 
encoder_data(self, data)
This method handles the incoming encoder data message and stores the data in the response table.
source code
 
sonar_data(self, data)
This method handles the incoming sonar data message and stores the data in the response table.
source code
 
get_analog_response_table(self)
This method returns the entire analog response table to the caller
source code
 
get_digital_response_table(self)
This method returns the entire digital response table to the caller
source code
 
send_sysex(self, sysex_command, sysex_data=None)
This method will send a Sysex command to Firmata with any accompanying data
source code
 
send_command(self, command)
This method is used to transmit a non-sysex command.
source code
 
system_reset(self, reset_sleep_time=2)
Send the reset command to the Arduino.
source code
 
_string_data(self, data)
This method handles the incoming string data message from Firmata.
source code
 
i2c_reply(self, data)
This method receives replies to i2c_read requests.
source code
 
capability_response(self, data)
This method handles a capability response message and stores the results to be retrieved via get_capability_query_results() in pymata.py
source code
 
pin_state_response(self, data)
This method handles a pin state response message and stores the results to be retrieved via get_pin_state_query_results() in pymata.py
source code
 
analog_mapping_response(self, data)
This method handles an analog mapping query response message and stores the results to be retrieved via get_analog_mapping_request_results() in pymata.py
source code
 
run(self)
This method starts the thread that continuously runs to receive and interpret messages coming from Firmata.
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from threading.Thread (private): _reset_internal_locks, _set_daemon, _set_ident

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  MSG_CMD_MIN = 128
  REPORT_ANALOG = 192
  REPORT_DIGITAL = 208
  SET_PIN_MODE = 244
  START_SYSEX = 240
  END_SYSEX = 247
  SYSTEM_RESET = 255
  DIGITAL_MESSAGE = 144
  ANALOG_MESSAGE = 224
  REPORT_VERSION = 249
  ENCODER_CONFIG = 32
  TONE_PLAY = 95
  SONAR_CONFIG = 96
  ENCODER_DATA = 33
  SONAR_DATA = 97
  SERVO_CONFIG = 112
  STRING_DATA = 113
  I2C_REQUEST = 118
  I2C_REPLY = 119
  I2C_CONFIG = 120
  REPORT_FIRMWARE = 121
  SAMPLING_INTERVAL = 122
  EXTENDED_ANALOG = 111
  PIN_STATE_QUERY = 109
  PIN_STATE_RESPONSE = 110
  CAPABILITY_QUERY = 107
  CAPABILITY_RESPONSE = 108
  ANALOG_MAPPING_QUERY = 105
  ANALOG_MAPPING_RESPONSE = 106
  SYSEX_NON_REALTIME = 126
  SYSEX_REALTIME = 127
  INPUT = 0
  OUTPUT = 1
  ANALOG = 2
  PWM = 3
  SERVO = 4
  I2C = 6
  ONEWIRE = 7
  STEPPER = 8
  TONE = 9
  ENCODER = 10
  SONAR = 11
  IGNORE = 127
  DIGITAL = 32
  analog_response_table = []
  digital_response_table = []
  analog_latch_table = []
  digital_latch_table = []
  LATCH_STATE = 0
  LATCHED_THRESHOLD_TYPE = 1
  ANALOG_LATCH_DATA_TARGET = 2
  ANALOG_LATCHED_DATA = 3
  ANALOG_TIME_STAMP = 4
  DIGITAL_LATCHED_DATA = 2
  DIGITAL_TIME_STAMP = 3
  LATCH_IGNORE = 0
  LATCH_ARMED = 1
  LATCH_LATCHED = 2
  DIGITAL_LATCH_LOW = 0
  DIGITAL_LATCH_HIGH = 1
  ANALOG_LATCH_GT = 2
  ANALOG_LATCH_LT = 3
  ANALOG_LATCH_GTE = 4
  ANALOG_LATCH_LTE = 5
  RESPONSE_TABLE_MODE = 0
  RESPONSE_TABLE_PIN_DATA_VALUE = 1
  MSB = 2
  LSB = 1
  command_dispatch = {}
  command_deque = None
  firmata_version = []
  firmata_firmware = []
  data_lock = None
  total_pins_discovered = 0
  number_of_analog_pins_discovered = 0
  i2c_map = {}
  active_sonar_map = {}
Properties [hide private]

Inherited from threading.Thread: daemon, ident, name

Inherited from threading.Thread (private): _block

Inherited from object: __class__

Method Details [hide private]

__init__(self, transport, command_deque, data_lock)
(Constructor)

source code 

constructor for CommandHandler class

Parameters:
  • transport - A reference to the communications port designator.
  • command_deque - A reference to a command deque.
  • data_lock - A reference to a thread lock.
Overrides: object.__init__

auto_discover_board(self, max_wait_time=30)

source code 

This method will allow up to max_wait_time seconds for discovery (communicating with) an Arduino board and then will determine a pin configuration table for the board.

Parameters:
  • max_wait_time - The maximum time to wait for discovery of the board
Returns:
True if board is successfully discovered or False upon timeout

report_version(self, data)

source code 

This method processes the report version message, sent asynchronously by Firmata when it starts up or after refresh_report_version() is called

Use the api method api_get_version to retrieve this information

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

set_analog_latch(self, pin, threshold_type, threshold_value)

source code 

This method "arms" a pin to allow data latching for the pin.

Parameters:
  • pin - Analog pin number (value following an 'A' designator, i.e. A5 = 5
  • threshold_type - ANALOG_LATCH_GT | ANALOG_LATCH_LT | ANALOG_LATCH_GTE | ANALOG_LATCH_LTE
  • threshold_value - numerical value

set_digital_latch(self, pin, threshold_type)

source code 

This method "arms" a pin to allow data latching for the pin.

Parameters:
  • pin - digital pin number
  • threshold_type - DIGITAL_LATCH_HIGH | DIGITAL_LATCH_LOW

get_analog_latch_data(self, pin)

source code 

This method reads the analog latch table for the specified pin and returns a list that contains: [latch_state, latched_data, and time_stamp]. If the latch state is latched, the entry in the table is cleared

Parameters:
  • pin - pin number
Returns:
[latch_state, latched_data, and time_stamp]

get_digital_latch_data(self, pin)

source code 

This method reads the digital latch table for the specified pin and returns a list that contains: [latch_state, latched_data, and time_stamp]. If the latch state is latched, the entry in the table is cleared

Parameters:
  • pin - pin number
Returns:
[latch_state, latched_data, and time_stamp]

report_firmware(self, data)

source code 

This method processes the report firmware message, sent asynchronously by Firmata when it starts up or after refresh_report_firmware() is called

Use the api method api_get_firmware_version to retrieve this information

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

analog_message(self, data)

source code 

This method handles the incoming analog data message. It stores the data value for the pin in the analog response table. It checks to see if the

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

digital_message(self, data)

source code 

This method handles the incoming digital message. It stores the data values in the digital response table. Data is stored for all 8 bits of a digital port

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

encoder_data(self, data)

source code 

This method handles the incoming encoder data message and stores the data in the response table.

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

sonar_data(self, data)

source code 

This method handles the incoming sonar data message and stores the data in the response table.

Parameters:
  • data - Message data from Firmata
Returns:
No return value.

get_analog_response_table(self)

source code 

This method returns the entire analog response table to the caller

Returns:
The analog response table.

get_digital_response_table(self)

source code 

This method returns the entire digital response table to the caller

Returns:
The digital response table.

send_sysex(self, sysex_command, sysex_data=None)

source code 

This method will send a Sysex command to Firmata with any accompanying data

Parameters:
  • sysex_command - sysex command
  • sysex_data - data for command @return : No return value.

send_command(self, command)

source code 

This method is used to transmit a non-sysex command.

Parameters:
  • command - Command to send to firmata includes command + data formatted by caller @return : No return value.

system_reset(self, reset_sleep_time=2)

source code 

Send the reset command to the Arduino. It resets the response tables to their initial values

Returns:
No return value

_string_data(self, data)

source code 

This method handles the incoming string data message from Firmata. The string is printed to the console

Parameters:
  • data - Message data from Firmata
Returns:
No return value.s

i2c_reply(self, data)

source code 

This method receives replies to i2c_read requests. It stores the data for each i2c device address in a dictionary called i2c_map. The data is retrieved via a call to i2c_get_read_data() in pymata.py

Parameters:
  • data - raw data returned from i2c device

capability_response(self, data)

source code 

This method handles a capability response message and stores the results to be retrieved via get_capability_query_results() in pymata.py

Parameters:
  • data - raw capability data

pin_state_response(self, data)

source code 

This method handles a pin state response message and stores the results to be retrieved via get_pin_state_query_results() in pymata.py

Parameters:
  • data - raw pin state data

analog_mapping_response(self, data)

source code 

This method handles an analog mapping query response message and stores the results to be retrieved via get_analog_mapping_request_results() in pymata.py

Parameters:
  • data - raw analog mapping data

run(self)

source code 

This method starts the thread that continuously runs to receive and interpret messages coming from Firmata. This must be the last method in this file

It also checks the deque for messages to be sent to Firmata.

Overrides: threading.Thread.run