Skip to content

Commit 240909e

Browse files
authored
Merge pull request #4359 from dhalbert/usb_cdc-connect-doc-note
Add caveat for usb_cdc.Serial.connected; fix another doc bug
2 parents 88542e1 + 24ac815 commit 240909e

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

shared-bindings/countio/Counter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
//|
2323
//| For example::
2424
//|
25+
//| import board
2526
//| import countio
26-
//| import time
27-
//| from board import *
2827
//|
2928
//| pin_counter = countio.Counter(board.D1)
3029
//| #reset the count after 100 counts

shared-bindings/usb_cdc/Serial.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@
4040
//|
4141
//| def __init__(self) -> None:
4242
//| """You cannot create an instance of `usb_cdc.Serial`.
43-
//|
44-
//| Serial objects are pre-constructed for each CDC device in the USB
45-
//| descriptor and added to the ``usb_cdc.ports`` tuple."""
43+
//| The available instances are in the ``usb_cdc.serials`` tuple."""
4644
//| ...
4745
//|
48-
4946
//| def read(self, size: int = 1) -> bytes:
5047
//| """Read at most ``size`` bytes. If ``size`` exceeds the internal buffer size
5148
//| only the bytes in the buffer will be read. If `timeout` is > 0 or ``None``,
@@ -64,6 +61,29 @@
6461
//| :rtype: bytes"""
6562
//| ...
6663
//|
64+
//| def readline(self, size: int = -1) -> Optional[bytes]:
65+
//| r"""Read a line ending in a newline character ("\\n"), including the newline.
66+
//| Return everything readable if no newline is found and ``timeout`` is 0.
67+
//| Return ``None`` in case of error.
68+
//|
69+
//| This is a binary stream: the newline character "\\n" cannot be changed.
70+
//| If the host computer transmits "\\r" it will also be included as part of the line.
71+
//|
72+
//| :param int size: maximum number of characters to read. ``-1`` means as many as possible.
73+
//| :return: the line read
74+
//| :rtype: bytes or None"""
75+
//| ...
76+
//|
77+
//| def readlines(self) -> List[Optional[bytes]]:
78+
//| """Read multiple lines as a list, using `readline()`.
79+
//|
80+
//| .. warning:: If ``timeout`` is ``None``,
81+
//| `readlines()` will never return, because there is no way to indicate end of stream.
82+
//|
83+
//| :return: a list of the line read
84+
//| :rtype: list"""
85+
//| ...
86+
//|
6787
//| def write(self, buf: ReadableBuffer) -> int:
6888
//| """Write as many bytes as possible from the buffer of bytes.
6989
//|
@@ -124,7 +144,12 @@ STATIC mp_uint_t usb_cdc_serial_ioctl_stream(mp_obj_t self_in, mp_uint_t request
124144
}
125145

126146
//| connected: bool
127-
//| """True if this Serial is connected to a host. (read-only)"""
147+
//| """True if this Serial is connected to a host. (read-only)
148+
//|
149+
//| .. note:: The host is considered to be connected if it is asserting DTR (Data Terminal Ready).
150+
//| Most terminal programs and ``pyserial`` assert DTR when opening a serial connection.
151+
//| However, the C# ``SerialPort`` API does not. You must set ``SerialPort.DtrEnable``.
152+
//| """
128153
//|
129154
STATIC mp_obj_t usb_cdc_serial_get_connected(mp_obj_t self_in) {
130155
usb_cdc_serial_obj_t *self = MP_OBJ_TO_PTR(self_in);

0 commit comments

Comments
 (0)