From c0f45b73f2bcb01da5e3cb1c139306d2d6315d86 Mon Sep 17 00:00:00 2001 From: Quan Lin <36973354+jacklinquan@users.noreply.github.com> Date: Wed, 16 Jan 2019 15:51:11 +1100 Subject: [PATCH] Version 0.1.6 The read method is improved. --- setup.py | 2 +- usbserial4a/__init__.py | 2 +- usbserial4a/cdcacmserial4a.py | 12 +++++++----- usbserial4a/ftdiserial4a.py | 10 ++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 783798d..713c1ed 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="usbserial4a", - version="0.1.5", + version="0.1.6", description="Python package for Kivy Android USB serial port.", long_description="https://github.com/jacklinquan/usbserial4a", long_description_content_type="text/markdown", diff --git a/usbserial4a/__init__.py b/usbserial4a/__init__.py index 14860cc..dad940b 100644 --- a/usbserial4a/__init__.py +++ b/usbserial4a/__init__.py @@ -9,4 +9,4 @@ Requires: kivy, pyjnius, pyserial, usb4a ''' # Project version -__version__ = '0.1.5' +__version__ = '0.1.6' diff --git a/usbserial4a/cdcacmserial4a.py b/usbserial4a/cdcacmserial4a.py index 98e7a67..e90d0fb 100644 --- a/usbserial4a/cdcacmserial4a.py +++ b/usbserial4a/cdcacmserial4a.py @@ -37,7 +37,7 @@ class CdcAcmSerial(SerialBase): DEFAULT_READ_BUFFER_SIZE = 1024 DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024 - USB_READ_TIMEOUT_MILLIS = 1 + USB_READ_TIMEOUT_MILLIS = 50 USB_WRITE_TIMEOUT_MILLIS = 5000 def __init__(self, *args, **kwargs): @@ -176,10 +176,12 @@ class CdcAcmSerial(SerialBase): read = bytearray() timeout = Timeout(self.timeout) - # Keep reading until there is enough data or timeout. - while self.in_waiting < size: - if timeout.expired(): - break + # If there is enough data in the buffer, do not bother to read. + if len(self._read_buffer) < size: + # Keep reading until there is enough data or timeout. + while self.in_waiting < size: + if timeout.expired(): + break # Get data from read buffer. read = self._read_buffer[:size] diff --git a/usbserial4a/ftdiserial4a.py b/usbserial4a/ftdiserial4a.py index d66b510..362a883 100644 --- a/usbserial4a/ftdiserial4a.py +++ b/usbserial4a/ftdiserial4a.py @@ -185,10 +185,12 @@ class FtdiSerial(SerialBase): read = bytearray() timeout = Timeout(self.timeout) - # Keep reading until there is enough data or timeout. - while self.in_waiting < size: - if timeout.expired(): - break + # If there is enough data in the buffer, do not bother to read. + if len(self._read_buffer) < size: + # Keep reading until there is enough data or timeout. + while self.in_waiting < size: + if timeout.expired(): + break # Get data from read buffer. read = self._read_buffer[:size]