| 131 | } |
| 132 | |
| 133 | void* openPortNative(const char *portName) |
| 134 | { |
| 135 | // Try to open the serial port with read/write access |
| 136 | void *portHandle = CreateFileA(portName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED, NULL); |
| 137 | if (portHandle != INVALID_HANDLE_VALUE) |
| 138 | { |
| 139 | // Configure the port parameters and timeouts |
| 140 | if (!configPort(portHandle)) |
| 141 | { |
| 142 | // Close the port if there was a problem setting the parameters |
| 143 | PurgeComm(portHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR); |
| 144 | if (CancelIoEx) |
| 145 | CancelIoEx(portHandle, NULL); |
| 146 | SetCommMask(portHandle, 0); |
| 147 | CloseHandle(portHandle); |
| 148 | portHandle = INVALID_HANDLE_VALUE; |
| 149 | } |
| 150 | } |
| 151 | return portHandle; |
| 152 | } |
| 153 | |
| 154 | void closePortNative(void *portHandle) |
| 155 | { |