From 01ae584dcd3b62b278a0d85fea9f8024ac83d851 Mon Sep 17 00:00:00 2001 From: Quan Lin <36973354+jacklinquan@users.noreply.github.com> Date: Thu, 29 Nov 2018 16:50:39 +1100 Subject: [PATCH] Bug in read fixed. --- usbserial4a/ftdiserial4a.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/usbserial4a/ftdiserial4a.py b/usbserial4a/ftdiserial4a.py index 2329494..f09edfb 100644 --- a/usbserial4a/ftdiserial4a.py +++ b/usbserial4a/ftdiserial4a.py @@ -161,14 +161,11 @@ class FtdiSerial(SerialBase): if result != 0: raise SerialException("Reset failed: result={}".format(result)) - def read(self, data_length=1): + def read(self): '''Read data from the serial port. This method should be used in another thread, as it blocks. - Parameters: - data_length (int): the length of read buffer(better <= 1024). - Returns: dest (bytearray): data read from the serial port. ''' @@ -177,14 +174,14 @@ class FtdiSerial(SerialBase): if not self._read_endpoint: raise SerialException("Read endpoint does not exist!") - buf = bytearray(data_length) + buf = bytearray(1024) timeout = int( self._timeout * 1000 if self._timeout \ else self.USB_READ_TIMEOUT_MILLIS) totalBytesRead = self._connection.bulkTransfer( self._read_endpoint, buf, - data_length, + 1024, timeout) if totalBytesRead < self.MODEM_STATUS_HEADER_LENGTH: raise SerialException(