| 152 | } |
| 153 | |
| 154 | void closePortNative(void *portHandle) |
| 155 | { |
| 156 | // Force the port to enter non-blocking mode to ensure that any current reads return |
| 157 | COMMTIMEOUTS timeouts; |
| 158 | memset(&timeouts, 0, sizeof(COMMTIMEOUTS)); |
| 159 | timeouts.WriteTotalTimeoutMultiplier = 0; |
| 160 | timeouts.ReadIntervalTimeout = MAXDWORD; |
| 161 | timeouts.ReadTotalTimeoutMultiplier = 0; |
| 162 | timeouts.ReadTotalTimeoutConstant = 0; |
| 163 | timeouts.WriteTotalTimeoutConstant = 0; |
| 164 | SetCommTimeouts(portHandle, &timeouts); |
| 165 | |
| 166 | // Purge any outstanding port operations |
| 167 | PurgeComm(portHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR); |
| 168 | if (CancelIoEx) |
| 169 | CancelIoEx(portHandle, NULL); |
| 170 | SetCommMask(portHandle, 0); |
| 171 | |
| 172 | // Close the port |
| 173 | if (!CloseHandle(portHandle)) |
| 174 | printf("Error Line = %d, Code = %d\n", __LINE__ - 1, GetLastError()); |
| 175 | } |
| 176 | |
| 177 | int waitForEvent(void *portHandle) |
| 178 | { |