Skip to content

Commit

Permalink
Merge pull request #4 from chrisflesher/feature/0002-ethernet-support
Browse files Browse the repository at this point in the history
Allow Ethernet Connections (python)
  • Loading branch information
jfjlaros committed Nov 29, 2020
2 parents f5d931c + 15ea7b2 commit 740ca34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ passing the path to a serial device to the constructor.
.. code:: python
>>> from simple_rpc import Interface
>>>
>>>
>>> interface = Interface('/dev/ttyACM0')
>>> ethernet_interface = Interface('socket://192.168.1.50:10000')
Every exported method will show up as a class method of the ``interface`` class
instance. These methods can be used like any normal class methods.
Expand Down
7 changes: 7 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ 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
6 changes: 4 additions & 2 deletions simple_rpc/simple_rpc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from time import sleep
from types import MethodType

from serial import Serial
from serial import serial_for_url
from serial.serialutil import SerialException

from .extras import make_function
Expand All @@ -27,12 +27,14 @@ def __init__(self, device, baudrate=9600, wait=1, autoconnect=True):
self._device = device
self._wait = wait

self._connection = Serial(baudrate=baudrate)
self._connection = serial_for_url(device)
self._connection.baudrate = baudrate
self._version = (0, 0, 0)
self._endianness = b'<'
self._size_t = b'H'
self.methods = {}

self.close()
if autoconnect:
self.open()

Expand Down

0 comments on commit 740ca34

Please sign in to comment.