Skip to content

Commit

Permalink
Updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Jan 16, 2021
1 parent 61a4f7a commit d940d48
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 58 deletions.
1 change: 1 addition & 0 deletions docs/api/simple_rpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ SimpleRPC

.. automodule:: simple_rpc.simple_rpc
:members:
:inherited-members:
89 changes: 38 additions & 51 deletions docs/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ Library
=======

The API library provides several interfaces, discussed below. All interfaces
share the methods described in Section `Generic methods`_.
share the methods described in Section `Methods`_.


Serial interface
----------------
Generic interface
-----------------

A ``SerialInterface`` class instance is made by passing the path to a device to
the constructor.
The ``Interface`` class can be used when the type of device is not known
beforehand, A class instance is made by passing either the path to a device or
a URI to the constructor.

.. code:: python
>>> from simple_rpc import SerialInterface
>>> from simple_rpc import Interface
>>> interface = Interface('/dev/ttyACM0')
The constructor takes the following parameters.
Expand All @@ -37,67 +38,53 @@ The constructor takes the following parameters.
- yes
- Automatically connect.

Please see the list of handlers_ for a full description of the supported
interface types.

Socket interface
----------------
Serial interface
^^^^^^^^^^^^^^^^

A ``SocketInterface`` class instance is made by passing a URI to the
constructor.
When a path to a serial device is given, the ``Interface`` constructor returns
a ``SerialInterface`` class instance.

.. code:: python
>>> from simple_rpc import SocketInterface
>>> interface = Interface('socket://192.168.1.50:10000')
The constructor takes the following parameters.
>>> from simple_rpc import Interface
>>> interface = Interface('/dev/ttyACM0')
>>> interface.__class__
<class 'simple_rpc.simple_rpc.SerialInterface'>
.. list-table:: Constructor parameters.
:header-rows: 1

* - name
- optional
- description
* - ``device``
- no
- Device name.
* - ``baudrate``
- yes
- Baud rate.
* - ``autoconnect``
- yes
- Automatically connect.
Alternatively, the ``SerialInterface`` class can be used directly.

.. code:: python
Generic interface
-----------------
>>> from simple_rpc import SerialInterface
>>> interface = SerialInterface('/dev/ttyACM0')
The ``Interface`` class can be used when the type of device is not known
beforehand,
Socket interface
^^^^^^^^^^^^^^^^

When a path to a serial device is given, it returns a ``SerialInterface`` class
instance.
When a socket URI is given, the ``Interface`` constructor returns a
``SocketInterface`` class instance.

.. code:: python
>>> from simple_rpc import Interface
>>> interface = Interface('/dev/ttyACM0')
>>> interface = Interface('socket://192.168.1.50:10000')
>>> interface.__class__
<class 'simple_rpc.simple_rpc.SerialInterface'>
<class 'simple_rpc.simple_rpc.SocketInterface'>
When a URI is given, it returns a ``SocketInterface`` class instance.
.. code:: python
Alternatively, the ``SocketInterface`` class can be used directly.

>>> interface = Interface('socket://192.168.1.50:10000')
>>> interface.__class__
<class 'simple_rpc.simple_rpc.SocketInterface'>
.. code:: python
>>> from simple_rpc import SocketInterface
>>> interface = SocketInterface('socket://192.168.1.50:10000')
Generic methods
---------------
Methods
^^^^^^^

The ``SerialInterface`` and the ``SocketInterface`` provide the following
standard methods.
The ``Interface`` class provides the following methods.

.. list-table:: Class methods.
:header-rows: 1
Expand All @@ -118,7 +105,7 @@ The ``open()`` function is used to connect to a device, this is needed when

.. code:: python
>>> interface = SerialInterface('/dev/ttyACM0', autoconnect=False)
>>> interface = Interface('/dev/ttyACM0', autoconnect=False)
>>> # Do something.
>>> interface.open()
Expand All @@ -134,7 +121,7 @@ Additionally, the ``with`` statement is supported for easy opening and closing.

.. code:: python
>>> with SerialInterface('/dev/ttyACM0') as interface:
>>> with Interface('/dev/ttyACM0') as interface:
>>> interface.ping(10)
The class instance has a public member variable named ``methods`` which
Expand Down Expand Up @@ -178,8 +165,7 @@ Basic usage
-----------

In the example_ given in the device library documentation, the ``inc`` method
is exported, which is now present as a class method of the ``SerialInterface``
class instance.
is exported, which is now present as a class method of the class instance.

.. code:: python
Expand Down Expand Up @@ -243,3 +229,4 @@ other Object. A similar Object is returned.
.. _example: https://simplerpc.readthedocs.io/en/latest/usage_device.html#example
.. _handlers: https://pyserial.readthedocs.io/en/latest/url_handlers.html
25 changes: 18 additions & 7 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ Any of these methods can be called by using the ``call`` subcommand.
$ simple_rpc call inc 1
2

The ``-d`` option is to select a device. For serial devices, a path can be
used.

::

$ simple_rpc list -d /dev/ttyUSB0

For ethernet or WiFi devices, a URI can be used.

::

$ simple_rpc call -d socket://192.168.1.50:10000 inc 1
2

Please see the list of handlers_ for a full description of the supported
interface types.


Complex objects
---------------
Expand All @@ -64,10 +81,4 @@ makes use of the demo_ sketch in the device examples.

.. _example: https://simplerpc.readthedocs.io/en/latest/usage.html#example
.. _demo: https://github.com/jfjlaros/simpleRPC/blob/master/examples/demo/demo.ino

Ethernet connections
---------------

To connect to ethernet or WiFi devices:

$ simple_rpc list -d socket://192.168.1.50:10000
.. _handlers: https://pyserial.readthedocs.io/en/latest/url_handlers.html

0 comments on commit d940d48

Please sign in to comment.