Skip to content

Commit e23b5a2

Browse files
committed
UARTService -> UARTServer; update and correct examples
1 parent 89d68b8 commit e23b5a2

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ Usage Example
3030

3131
.. code-block:: python
3232
33-
from adafruit_ble.uart import UARTService
33+
from adafruit_ble.uart import UARTServer
3434
35-
uart_service = UARTService()
36-
uart_service.start_advertising()
35+
uart_server = UARTServer()
36+
uart_server.start_advertising()
3737
38-
uart_service.write('abc')
38+
# Wait for a connection.
39+
while not uart_server.connected:
40+
pass
41+
42+
uart_server.write('abc')
3943
4044
4145
Contributing

adafruit_ble/uart.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from bleio import UUID, Characteristic, Service, Peripheral, CharacteristicBuffer
3232

3333

34-
class UARTService:
34+
class UARTServer:
3535
"""
3636
Provide UART-like functionality via the Nordic NUS service.
3737
@@ -42,8 +42,15 @@ class UARTService:
4242
4343
Example::
4444
45-
from adafruit_ble.uart import UARTService()
46-
uart = UARTService() # Starts advertising immediately.
45+
from adafruit_ble.uart import UARTServer
46+
uart = UARTServer()
47+
uart.start_advertising()
48+
49+
# Wait for a connection.
50+
while not uart.connected:
51+
pass
52+
53+
uart.write('abc')
4754
"""
4855

4956
NUS_SERVICE_UUID = UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
@@ -76,7 +83,7 @@ def stop_advertising(self):
7683

7784
@property
7885
def connected(self):
79-
"""True if someone connected to the service."""
86+
"""True if someone connected to the server."""
8087
return self._periph.connected
8188

8289
def read(self, nbytes=None):

examples/ble_uart_echo_test.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from adafruit_ble.uart import UARTService
1+
from adafruit_ble.uart import UARTServer
22

3-
# Starts advertising automatically. That may change in later versions.
4-
uart = UARTService()
3+
uart = UARTServer()
4+
uart.start_advertising()
55

6-
while True:
7-
# Returns one if nothing was read.
8-
one_byte = uart.read()
6+
# Wait for a connection
7+
while not uart.connected:
8+
pass
9+
10+
while uart.connected:
11+
# Returns b'' if nothing was read.
12+
one_byte = uart.read(1)
913
if one_byte:
1014
uart.write(bytes([one_byte]))

0 commit comments

Comments
 (0)