panoptes.pocs.sensors package

Submodules

panoptes.pocs.sensors.arduino_io module

class panoptes.pocs.sensors.arduino_io.ArduinoIO(board, serial_data, db)[source]

Bases: object

Supports reading from and writing to Arduinos.

The readings (python dictionaries) are recorded in a PanDB collection in the following form:

```
{
‘name’: self.board, ‘timestamp’: t, ‘data’: reading

}

```

connect()[source]

Connect to the port.

disconnect()[source]

Disconnect from the port.

Will re-open automatically if reading or writing occurs.

get_reading()[source]

Reads and returns a single reading.

handle_command(msg)[source]

Handle one relay command.

TODO(jamessynge): Add support for ‘set_relay’, where we look up the relay name in self._last_reading to confirm that it exists on this device.

handle_commands()[source]

Read and process commands for up to 1 second.

Returns when there are no more commands available from the command subscriber, or when a second has passed. The interval is 1 second because we expect at least 2 seconds between reports, and also expect that it probably doesn’t take more than 1 second for each report to be read. We could make this configurable, or could dynamically adjust, such as by polling for input.

handle_reading(reading)[source]

Saves a reading as the last_reading and writes to output_queue.

read_and_record()[source]

Try to get the next reading and, if successful, record it.

Write the reading to the appropriate PanDB collections and to the appropriate message topic.

If there is an interruption in success in reading from the device, we announce (log) the start and end of that situation.

reconnect()[source]

Disconnect from and connect to the serial port.

This supports handling a SerialException, such as when the USB bus is reset.

run()[source]

Main loop for recording data and reading commands.

This only ends if an Exception is unhandled or if a ‘shutdown’ command is received. The most likely exception is from SerialData.get_and_parse_reading() in the event that the device disconnects from USB.

stop_running
write(text)[source]

Writes text (a string) to the port.

Returns: the number of bytes written.

panoptes.pocs.sensors.arduino_io.auto_detect_arduino_devices(ports=None)[source]

Returns a list of tuples of (board_name, port).

panoptes.pocs.sensors.arduino_io.detect_board_on_port(port)[source]

Determine which type of board is attached to the specified port.

Returns: Name of the board (e.g. ‘camera_board’) if we can read a
line of JSON from the port, parse it and find a ‘name’ attribute in the top-level object. Else returns None.
panoptes.pocs.sensors.arduino_io.get_arduino_ports()[source]

Find ports (device paths or URLs) that appear to be Arduinos.

Returns://host:port arduino_simulator://?board=camera).
Return type:a list of strings; device paths (e.g. /dev/ttyACM1) or URLs (e.g. rfc2217
panoptes.pocs.sensors.arduino_io.open_serial_device(port, serial_config=None, **kwargs)[source]

Creates an rs232.SerialData for port, assumed to be an Arduino.

Default parameters are provided when creating the SerialData instance, but may be overridden by serial_config or kwargs.

Parameters:
  • serial_config – dictionary (or None) with serial settings from config file, suitable for passing to SerialData or to a PySerial instance.
  • **kwargs – Any other parameters to be passed to SerialData. These have higher priority than the serial_config parameter.

Module contents