From 3e287bbc6ec1cb2a3a5dec720d84ae378259b88d Mon Sep 17 00:00:00 2001 From: Quan Lin <36973354+jacklinquan@users.noreply.github.com> Date: Thu, 29 Nov 2018 13:45:33 +1100 Subject: [PATCH] Method flush added. In FTDI driver, flush method is added to be better compatible with Serial from pyserial. --- usbserial4a/ftdiserial4a.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/usbserial4a/ftdiserial4a.py b/usbserial4a/ftdiserial4a.py index 328f4b2..2329494 100644 --- a/usbserial4a/ftdiserial4a.py +++ b/usbserial4a/ftdiserial4a.py @@ -4,6 +4,7 @@ Classes: FtdiSerial(serial.serialutil.SerialBase) ''' +import time from serial.serialutil import SerialBase, SerialException from usb4a import usb @@ -163,7 +164,7 @@ class FtdiSerial(SerialBase): def read(self, data_length=1): '''Read data from the serial port. - This function should be used in another thread, as it blocks. + This method should be used in another thread, as it blocks. Parameters: data_length (int): the length of read buffer(better <= 1024). @@ -230,6 +231,14 @@ class FtdiSerial(SerialBase): wrote += i return wrote + def flush(self, flush_time=0.2): + '''Simply wait some time to allow all data to be written. + + Parameters: + flush_time (float): time in seconds to wait. + ''' + time.sleep(flush_time) + def purgeHwBuffers(self, purgeReadBuffers, purgeWriteBuffers): '''Set serial port parameters.