panoptes.utils.serial_handlers package¶
Submodules¶
panoptes.utils.serial_handlers.protocol_arduinosimulator module¶
Provides a simple simulator for telemetry_board.ino or camera_board.ino.
We use the pragma “no cover” in several places that happen to never be reached or that would only be reached if the code was called directly, i.e. not in the way it is intended to be used.
-
class
panoptes.utils.serial_handlers.protocol_arduinosimulator.ArduinoSimulator(message, relay_queue, json_queue, chunk_size, stop)[source]¶ Bases:
objectSimulates the serial behavior of the PANOPTES Arduino sketches.
The RS-232 connection is simulated with an input and output queue of bytes. This class provides a run function which can be called from a Thread to execute. Every two seconds while running it will generate another json output line, and then send that to the json_queue in small chunks at a rate similar to 9600 baud, the rate used by our Arduino sketches.
-
__init__(message, relay_queue, json_queue, chunk_size, stop)[source]¶ Parameters: - message – The message to be sent (millis and report_num will be added).
- relay_queue – The queue.Queue instance from which relay command bytes are read and acted upon. Elements are of type bytes.
- json_queue – The queue.Queue instance to which json messages (serialized to bytes) are written at ~9600 baud. Elements are of type bytes (i.e. each element is a sequence of bytes of length up to chunk_size).
- chunk_size – The number of bytes to write to json_queue at a time.
- stop – a threading.Event which is checked to see if run should stop executing.
-
generate_next_message(now)[source]¶ Append the next message to the pending bytearray and scheduled the next message.
-
generate_next_message_bytes(now)[source]¶ Generate the next message (report) from the simulated Arduino.
-
-
class
panoptes.utils.serial_handlers.protocol_arduinosimulator.FakeArduinoSerialHandler(*args, **kwargs)[source]¶ Bases:
panoptes.utils.serial_handlers.NoOpSerial-
flush()[source]¶ Write the buffered data to the output device.
We interpret that here as waiting until the simulator has taken all of the entries from the queue.
-
in_waiting¶ The number of input bytes available to read immediately.
-
is_config_ok¶ Does the caller ask for the correct serial device config?
-
out_waiting¶ The number of bytes in the output buffer.
-
read(size=1)[source]¶ Read size bytes.
If a timeout is set it may return fewer characters than requested. With no timeout it will block until the requested number of bytes is read.
Parameters: size – Number of bytes to read. Returns: Bytes read from the port, of type ‘bytes’.
-
readline()[source]¶ Read and return one line from the simulator.
This override exists just to support logging of the line.
-
-
panoptes.utils.serial_handlers.protocol_arduinosimulator.Serial¶ alias of
panoptes.utils.serial_handlers.protocol_arduinosimulator.FakeArduinoSerialHandler
panoptes.utils.serial_handlers.protocol_buffers module¶
-
class
panoptes.utils.serial_handlers.protocol_buffers.BuffersSerial(*args, **kwargs)[source]¶ Bases:
panoptes.utils.serial_handlers.NoOpSerial-
in_waiting¶ The number of input bytes available to read immediately.
-
read(size=1)[source]¶ Read size bytes.
If a timeout is set it may return fewer characters than requested. With no timeout it will block until the requested number of bytes is read.
Parameters: size – Number of bytes to read. Returns: Bytes read from the port, of type ‘bytes’. Raises: SerialTimeoutException– In case a write timeout is configured for the port and the time is exceeded.
-
-
panoptes.utils.serial_handlers.protocol_buffers.GetWBufferValue()[source]¶ Returns an immutable bytes object with the value of the w buffer.
-
panoptes.utils.serial_handlers.protocol_buffers.Serial¶ alias of
panoptes.utils.serial_handlers.protocol_buffers.BuffersSerial
panoptes.utils.serial_handlers.protocol_hooked module¶
-
panoptes.utils.serial_handlers.protocol_hooked.ExampleSerialClassForUrl(url)[source]¶ Implementation of serial_class_for_url called by serial.serial_for_url.
Returns the url, possibly modified, and a factory function to be called to create an instance of a SerialBase sub-class (or at least behaves like it). You can return a class as that factory function, as calling a class creates an instance of that class.
serial.serial_for_url will call that factory function with None as the port parameter (the first), and after creating the instance will assign the url to the port property of the instance.
Returns: A tuple (url, factory).
-
panoptes.utils.serial_handlers.protocol_hooked.serial_class_for_url(url)¶ Implementation of serial_class_for_url called by serial.serial_for_url.
Returns the url, possibly modified, and a factory function to be called to create an instance of a SerialBase sub-class (or at least behaves like it). You can return a class as that factory function, as calling a class creates an instance of that class.
serial.serial_for_url will call that factory function with None as the port parameter (the first), and after creating the instance will assign the url to the port property of the instance.
Returns: A tuple (url, factory).
panoptes.utils.serial_handlers.protocol_no_op module¶
Module contents¶
The protocol_*.py files in this package are based on PySerial’s file test/handlers/protocol_test.py, modified for different behaviors. The call serial.serial_for_url(“XYZ://”) looks for a class Serial in a file named protocol_XYZ.py in this package (i.e. directory).
-
class
panoptes.utils.serial_handlers.NoOpSerial(*args, **kwargs)[source]¶ Bases:
serial.serialutil.SerialBaseNo-op implementation of PySerial’s SerialBase.
Provides no-op implementation of various methods that SerialBase expects to have implemented by the sub-class. Can be used as is for a /dev/null type of behavior.
-
in_waiting¶ The number of input bytes available to read immediately.
-
read(size=1)[source]¶ Read size bytes.
If a timeout is set it may return fewer characters than requested. With no timeout it will block until the requested number of bytes is read.
Parameters: size – Number of bytes to read. Returns: Bytes read from the port, of type ‘bytes’. Raises: SerialTimeoutException– In case a write timeout is configured for the port and the time is exceeded.
-