44 :
rp::hal::serial_rxtx(), _serial_handle(nullptr), _baudrate(0), _flags(0)
53 CloseHandle(
_ro.hEvent);
54 CloseHandle(
_wo.hEvent);
72 portname, GENERIC_READ | GENERIC_WRITE, 0,
nullptr, OPEN_EXISTING,
73 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
84 _dcb.BaudRate = baudrate;
86 _dcb.Parity = NOPARITY;
87 _dcb.StopBits = ONESTOPBIT;
88 _dcb.fDtrControl = DTR_CONTROL_ENABLE;
110 PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR))
139 DWORD w_len = 0, o_len = -1;
142 if (
data ==
nullptr ||
size == 0)
return 0;
148 if (GetLastError() != ERROR_IO_PENDING) w_len =
ANS_DEV_ERR;
160 if (GetLastError() == ERROR_IO_PENDING)
164 if (GetLastError() != ERROR_IO_INCOMPLETE) r_len = 0;
178 PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
185 _word_size_t ans = 0;
187 if (WaitForSingleObject(
_wo.hEvent, timeout) == WAIT_TIMEOUT)
197 if (returned_size) *returned_size = w_len;
205 _word_size_t ans = 0;
207 if (WaitForSingleObject(
_ro.hEvent, timeout) == WAIT_TIMEOUT)
215 if (returned_size) *returned_size = r_len;
220 size_t data_count,
_u32 timeout,
size_t* returned_size)
227 if (returned_size ==
nullptr) returned_size = (
size_t*)&dummy_length;
232 if (rxqueue_remaining >= data_count)
234 *returned_size = rxqueue_remaining;
245 if (GetLastError() == ERROR_IO_PENDING)
247 if (WaitForSingleObject(
_wait_o.hEvent, timeout) ==
261 *returned_size = stat.cbInQue;
275 if (stat.cbInQue >= data_count)
277 *returned_size = stat.cbInQue;
298 return com_stat.cbInQue;
320 memset(&
_co, 0,
sizeof(
_co));
321 _co.ReadIntervalTimeout = 0;
322 _co.ReadTotalTimeoutMultiplier = 0;
323 _co.ReadTotalTimeoutConstant = 0;
324 _co.WriteTotalTimeoutMultiplier = 0;
325 _co.WriteTotalTimeoutConstant = 0;
327 memset(&
_ro, 0,
sizeof(
_ro));
328 memset(&
_wo, 0,
sizeof(
_wo));
331 _ro.hEvent = CreateEvent(
nullptr,
TRUE,
FALSE,
nullptr);
332 _wo.hEvent = CreateEvent(
nullptr,
TRUE,
FALSE,
nullptr);