diff options
Diffstat (limited to 'sercp.c')
-rw-r--r-- | sercp.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -202,6 +202,7 @@ void TestArgs (int argc, char *argv[]) } +//***************************************************************************** void FlushSerialPort() { if (serial_fd) { @@ -213,6 +214,20 @@ if (serial_fd) { } } +//***************************************************************************** + +void CloseSerialPort() { + if (serial_fd) { + #ifdef _WIN32 + PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR); + CloseHandle(serial_fd); + #else + tcflush(serial_fd, TCIOFLUSH); + close (serial_fd); + #endif + } +} + //***************************************************************************** // @@ -440,6 +455,9 @@ void sercpRecv(void) { } } else { printf("Fileinfo corrupted. End...\n"); + FlushSerialPort(); + CloseSerialPort(); + exit(EXIT_FAILURE); break; } break; @@ -739,17 +757,6 @@ int OpenUart() { #endif } -void CloseSerialPort() { - if (serial_fd) { -#ifdef _WIN32 - PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR); - CloseHandle(serial_fd); -#else - tcflush(serial_fd, TCIOFLUSH); - close (serial_fd); -#endif - } -} |