Table Of Contents

Previous topic

client_states

Next topic

server_states

This Page

rs232

SerialManager

class blitz.communications.rs232.SerialManager[source]

Manages serial (eventually RS232, SPI or I2C) communications with expansion boards. It has both a monitoring loop and an “outbox” which it uses for sending information.

classmethod Instance()[source]

Returns a reference to a single SerialManager instance

Returns SerialManager:
 The SerialManager singleton instance
get_available_ports()[source]

Generates a list of available serial ports, mapping their ID to the COM* or /dev/tty* reference. Adapted from http://stackoverflow.com/a/14224477/233608

Returns:Nothing
handle_board_command(signal_args)[source]

Listens for board commands and distributes them to the correct board.

Parameters:signal_args – the arguments received from the blinker signal. In the form [‘BOARD ID’, ‘ARGS’, ...]
static open_serial_connection(port_name, baud_rate=57600, read_timeout=3)[source]

Creates a serial port connection, opens it and returns it. Note if you are using USB serial and an Arduino you may need to put a resistor between 5V or 3.3V and the RESET pin to prevent auto reset. This should only be required during development using a PC. Check the interwebs for the correct resistance value (this is a known issue)

Parameters:
  • port_name – the name of the port to open (for instance COM3)
  • baud_rate – the baud rate of the serial connection (default 57600)
  • read_timeout – the timeout to use for reading from ports (default 3 seconds)
Returns:

An open serial port object

receive_serial_data(board_id)[source]

Requests a transmission from the specified board and saves the returned data to the database

Parameters:board_id – the ID of the board in hex form, (e.g. “08” for board with ID 8)
Returns:Nothing
reset_expansion_board(board_id)[source]

Resets the (Arduino Based) expansion board on the given port by toggling the DTR line. Only works for Arduino based expansion boards

Parameters:board_id – the serial port to send the reset command to
send_command_with_ack(command, board_id)[source]

Sends the given command over the serial port and checks for an ACK response. Returns None if the ACK was received, and the received message otherwise

Parameters:
  • command – the string command to send over the serial port, from the SerialCommands constant
  • board_id – the ID of the board in hex form, (e.g. “08” for board with ID 8)
Raises ExpansionBoardNotFound:
 

when a message is sent to an expansion board which doesn’t exist

Returns:

the board response if an error was received, or None if ACK was received

send_id_request(port)[source]

Requests an ID from the serial port name and returns it. If no ID is found, return None

Parameters:port – the serial port handle to read/write from
Returns:A two digit hex board ID, or None if no ID was found
start(tcp)[source]

Starts listening on the serial ports and polling for updates every SerialUpdatePeriod seconds

Parameters:tcp – the TCP connection to use for communications
Returns:Nothing
stop(signal_args)[source]

Stops logging data and sends a STOP request to all boards

Parameters:signal_args – the arguments provided by the blinker signal (unused)
Returns:Nothing