diff options
author | Pavel Vymetálek <pavel@vym.cz> | 2020-04-06 16:55:13 +0200 |
---|---|---|
committer | Pavel Vymetálek <pavel@vym.cz> | 2020-04-06 16:55:13 +0200 |
commit | 4fb0f336df691b6fb55c38c1128b63d94fc4e1d3 (patch) | |
tree | 6fe29dff4e211dc8df923f91d0210c00677d6815 | |
parent | 3159ad30681e16943b42f43ba6fc57fcb2d8e713 (diff) | |
download | sercp-pc-4fb0f336df691b6fb55c38c1128b63d94fc4e1d3.tar.gz |
Fix aborting while received fileinfo is corruptedv0.3.3
-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 - } -} |