Skip to content

Commit

Permalink
documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhitmire committed Nov 18, 2017
1 parent 885d250 commit 0691a5e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,6 @@
'Miscellaneous'),
]

autoclass_content = 'both'


4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ Indices and tables
API
===
.. automodule:: pyrealtime.decode_layer
:members:
:members:
.. automodule:: pyrealtime.serial_layer
:members:
30 changes: 29 additions & 1 deletion pyrealtime/serial_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@


def find_serial_port(name):
"""Utility function to scan available serial ports by name. The returned object is intended to be passed to the
:meth:`~pyrealtime.serial_layer.SerialWriteLayer.from_port` constructor of
:class:`~pyrealtime.serial_layer.SerialReadLayer` or :class:`~pyrealtime.serial_layer.SerialWriteLayer`.
:param name: The name of the serial port to scan for. It will return the first available port containing name.
:return: A closed serial port object
"""
try:
import serial
import serial.tools.list_ports
Expand All @@ -23,14 +30,25 @@ def find_serial_port(name):


class SerialWriteLayer(TransformMixin, EncoderMixin, ThreadLayer):
def __init__(self, port_in, baud_rate, device_name,*args, **kwargs):
"""Sends data to a serial port
"""
def __init__(self, port_in, baud_rate, device_name, *args, **kwargs):
"""
:param port_in: Source of data to send
:param baud_rate: Baud rate or serial port (e.g. 9600, 115200, etc). See pyserial documentation for more details
:param device_name: Full or partial name of the device (e.g. 'COM2' or 'Arduino'). The port will be obtained using :func:`~pyrealtime.serial_layer.find_serial_port`.
"""
self.ser = None
self.baud_rate = baud_rate
self.device_name = device_name
super().__init__(port_in, *args, **kwargs)

@classmethod
def from_port(cls, port_in, serial, *args, **kwargs):
"""Creates a layer from an existing serial object
:param serial: Serial port object, either created using pyserial or from :func:`~pyrealtime.serial_layer.find_serial_port`.
"""
layer = cls(port_in=port_in, baud_rate=None, device_name=None, *args, **kwargs)
layer.ser = serial
return layer
Expand All @@ -51,14 +69,24 @@ def transform(self, data):


class SerialReadLayer(ProducerMixin, DecoderMixin, ThreadLayer):
"""Reads data from a serial port
"""
def __init__(self, baud_rate, device_name, *args, **kwargs):
"""
:param baud_rate: Baud rate or serial port (e.g. 9600, 115200, etc). See pyserial documentation for more details
:param device_name: Full or partial name of the device (e.g. 'COM2' or 'Arduino'). The port will be obtained using :func:`~pyrealtime.serial_layer.find_serial_port`.
"""
self.ser = None
self.baud_rate = baud_rate
self.device_name = device_name
super().__init__(*args, **kwargs)

@classmethod
def from_port(cls, serial, *args, **kwargs):
"""Creates a layer from an existing serial object
:param serial: Serial port object, either created using pyserial or from :func:`~pyrealtime.serial_layer.find_serial_port`.
"""
layer = cls(baud_rate=None, device_name=None, *args, **kwargs)
layer.ser = serial
return layer
Expand Down

0 comments on commit 0691a5e

Please sign in to comment.