| 145 | } |
| 146 | |
| 147 | int uart_open (const char *port) |
| 148 | { |
| 149 | char str[20]; |
| 150 | |
| 151 | snprintf (str, sizeof (str) - 1, "\\\\.\\%s", port); |
| 152 | serial_handle = CreateFileA (str, GENERIC_READ | GENERIC_WRITE, |
| 153 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
| 154 | 0, // FILE_FLAG_OVERLAPPED, |
| 155 | NULL); |
| 156 | |
| 157 | |
| 158 | if (serial_handle == INVALID_HANDLE_VALUE) |
| 159 | { |
| 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | DCB dcb_serial_params = {0}; |
| 164 | dcb_serial_params.DCBlength = sizeof (dcb_serial_params); |
| 165 | if (GetCommState (serial_handle, &dcb_serial_params) == 0) |
| 166 | { |
| 167 | CloseHandle (serial_handle); |
| 168 | return -1; |
| 169 | } |
| 170 | |
| 171 | dcb_serial_params.BaudRate = CBR_256000; |
| 172 | dcb_serial_params.ByteSize = 8; |
| 173 | dcb_serial_params.StopBits = ONESTOPBIT; |
| 174 | dcb_serial_params.Parity = NOPARITY; |
| 175 | if (SetCommState (serial_handle, &dcb_serial_params) == 0) |
| 176 | { |
| 177 | CloseHandle (serial_handle); |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | void uart_close () |
| 185 | { |