38 namespace rp{
namespace arch{
namespace net{
41 :
rp::hal::serial_rxtx()
42 , _serial_handle(NULL)
53 CloseHandle(
_ro.hEvent);
54 CloseHandle(
_wo.hEvent);
77 GENERIC_READ | GENERIC_WRITE,
81 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
93 _dcb.BaudRate = baudrate;
95 _dcb.Parity = NOPARITY;
96 _dcb.StopBits = ONESTOPBIT;
97 _dcb.fDtrControl = DTR_CONTROL_ENABLE;
117 if (!PurgeComm(
_serial_handle, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR ))
146 DWORD w_len = 0, o_len = -1;
149 if (
data == NULL ||
size ==0)
return 0;
155 if(GetLastError() != ERROR_IO_PENDING)
169 if(GetLastError() == ERROR_IO_PENDING)
173 if(GetLastError() != ERROR_IO_INCOMPLETE)
186 PurgeComm(
_serial_handle, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR );
195 if (WaitForSingleObject(
_wo.hEvent, timeout) == WAIT_TIMEOUT)
205 if (returned_size) *returned_size = w_len;
215 if (WaitForSingleObject(
_ro.hEvent, timeout) == WAIT_TIMEOUT)
223 if (returned_size) *returned_size = r_len;
234 if (returned_size==NULL) returned_size=(
size_t *)&dummy_length;
239 if (rxqueue_remaining >= data_count) {
240 *returned_size = rxqueue_remaining;
251 if(GetLastError() == ERROR_IO_PENDING)
253 if (WaitForSingleObject(
_wait_o.hEvent, timeout) == WAIT_TIMEOUT)
265 *returned_size = stat.cbInQue;
277 if(stat.cbInQue >= data_count)
279 *returned_size = stat.cbInQue;
300 return com_stat.cbInQue;
323 memset(&
_co, 0,
sizeof(
_co));
324 _co.ReadIntervalTimeout = 0;
325 _co.ReadTotalTimeoutMultiplier = 0;
326 _co.ReadTotalTimeoutConstant = 0;
327 _co.WriteTotalTimeoutMultiplier = 0;
328 _co.WriteTotalTimeoutConstant = 0;
330 memset(&
_ro, 0,
sizeof(
_ro));
331 memset(&
_wo, 0,
sizeof(
_wo));
345 namespace rp{
namespace hal{
virtual void flush(_u32 flags)
virtual int waitfordata(size_t data_count, _u32 timeout=-1, size_t *returned_size=NULL)
virtual int waitforsent(_u32 timeout=-1, size_t *returned_size=NULL)
static serial_rxtx * CreateRxTx()
static void ReleaseRxTx(serial_rxtx *)
virtual size_t rxqueue_count()
volatile bool _is_serial_opened
virtual bool bind(const char *portname, uint32_t baudrate, uint32_t flags=0)
virtual int senddata(const unsigned char *data, size_t size)
virtual int recvdata(unsigned char *data, size_t size)
typedef _word_size_t(THREAD_PROC *thread_proc_t)(void *)
GLuint GLsizei GLsizei * length
volatile HANDLE _serial_handle
virtual int waitforrecv(_u32 timeout=-1, size_t *returned_size=NULL)
GLsizei GLsizei GLenum GLenum const GLvoid * data