diff --git a/src/serial.h b/src/serial.h index 34e7560..7359415 100644 --- a/src/serial.h +++ b/src/serial.h @@ -92,7 +92,6 @@ int serial_read (serial_t *device, void* data, unsigned int size); int serial_write (serial_t *device, const void* data, unsigned int size); int serial_flush (serial_t *device, int queue); -int serial_drain (serial_t *device); int serial_send_break (serial_t *device); diff --git a/src/serial_posix.c b/src/serial_posix.c index 2064c22..cdaa882 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -541,6 +541,14 @@ serial_write (serial_t *device, const void *data, unsigned int size) nbytes += n; } + // Wait until all data has been transmitted. + while (tcdrain (device->fd) != 0) { + if (errno != EINTR ) { + TRACE ("tcdrain"); + return -1; + } + } + return nbytes; } @@ -574,23 +582,6 @@ serial_flush (serial_t *device, int queue) } -int -serial_drain (serial_t *device) -{ - if (device == NULL) - return -1; // EINVAL (Invalid argument) - - while (tcdrain (device->fd) != 0) { - if (errno != EINTR ) { - TRACE ("tcdrain"); - return -1; - } - } - - return 0; -} - - int serial_send_break (serial_t *device) { diff --git a/src/serial_win32.c b/src/serial_win32.c index 8a9c619..299b130 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -399,21 +399,6 @@ serial_flush (serial_t *device, int queue) } -int -serial_drain (serial_t *device) -{ - if (device == NULL) - return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect) - - if (!FlushFileBuffers (device->hFile)) { - TRACE ("FlushFileBuffers"); - return -1; - } - - return 0; -} - - int serial_send_break (serial_t *device) { diff --git a/src/suunto_d9.c b/src/suunto_d9.c index b8cc021..8decadb 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -242,9 +242,6 @@ suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsi return EXITCODE (n); } - // Wait until all data has been transmitted. - serial_drain (device->port); - // Receive the echo. unsigned char echo[128] = {0}; assert (sizeof (echo) >= csize); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 378ec7f..6cd9124 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -209,9 +209,6 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], return EXITCODE (n); } - // Wait until all data has been transmitted. - serial_drain (device->port); - // If the interface sends an echo back (which is the case for many clone // interfaces), this echo should be removed from the input queue before // attempting to read the real reply from the dive computer. Otherwise, diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index 06cbd6b..32347dd 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -181,9 +181,6 @@ suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[], return EXITCODE (n); } - // Wait until all data has been transmitted. - serial_drain (device->port); - serial_sleep (0x9); // Clear RTS to receive the reply.