Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UARTService.readinto with "memoryview" slice and "bytearrary" causes ValueError: length argument not allowed for this type #128

Open
dh-metre opened this issue Jul 30, 2021 · 2 comments

Comments

@dh-metre
Copy link

dh-metre commented Jul 30, 2021

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 "<stdin>", line 1, in <module>
  File "dev.py", line 308, in <module>
  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.

@dh-metre dh-metre changed the title UARTService.readinto with memory view slice and bytearrary cases ValueError: length argument not allowed for this type UARTService.readinto with "memoryview" slice and "bytearrary" causes ValueError: length argument not allowed for this type Jul 30, 2021
@dh-metre
Copy link
Author

dh-metre commented Jul 30, 2021

Changing line 77 in nordic.py to return self._rx.readinto(buf) appears to be one way resolve the issue. I tested this.

@jepler
Copy link
Member

jepler commented Sep 20, 2021

@dh-metre please consider submitting a pull request to fix this problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants