adafruit / adafruit/Adafruit_CircuitPython_BLE
UARTService.readinto with "memoryview" slice and "bytearrary" causes ValueError: length argument not allowed for this type
- Dominant language
- Python
- Stars
- 138
- Forks
- 58
- PR merge metrics
- No merged PRs in 30d
Description
`byte_count = device.readinto(memoryview(in_buf)[start_ptr:])`
causes: `ValueError: length argument not allowed for this type`
also tried with "bytearray" and got same error.
```
Traceback (most recent call last):
File "", line 1, in
File "dev.py", line 308, in
File "lib/metre/gAsynco.py", line 121, in run
File "lib/metre/gAsynco.py", line 522, in run_until_complete
File "lib/metre/gAsynco.py", line 506, in run_until_complete
File "lib/metre/gAsynco.py", line 196, in _wrapped_coro
File "lib/metre/gAsynco.py", line 394, in _wrapper
File "dev.py", line 234, in serial_task
File "adafruit_ble/services/nordic.py", line 77, in readinto
ValueError: length argument not allowed for this type
```
I poked around and see this in nordic.py:
```
def readinto(self, buf, nbytes=None):
"""
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
that many bytes. Otherwise, read at most ``len(buf)`` bytes.
:return: number of bytes read and stored into ``buf``
:rtype: int or None (on a non-blocking error)
"""
return self._rx.readinto(buf, nbytes)
```
Looking futher in _blio.CharacteristicBuffer at suggestion from @dhalbert it looks like the `ValueError: length argument not allowed for this type is thrown` because two parameters are passed in `return self._rx.readinto(buf, nbytes)` above.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in adafruit_ble/services/nordic.py at UARTService.readinto, then inspect _blio.CharacteristicBuffer to confirm how its readinto arguments are handled. Reproduce the ValueError with a memoryview slice and bytearray, and consider the issue resolved when both buffer types work and the readinto return value remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100