#ifndef SERIALCOM_H_INCLUDED #define SERIALCOM_H_INCLUDED #include #include #include #include //#include "stdafx.h" const int QUEUE_SIZE=512 ; class SERIAL { public: HANDLE hComPort ; HWND hDbg ; const char* error ; COMMTIMEOUTS orgTimeouts ; unsigned char rxbuffer[1024] ; DWORD rxlen,rxpos ; void debug(const char* txt) { if(hDbg)std::cout<=rxlen) { debug("rxin") ; int rxCount=0,startTime=GetTickCount() ; for(bool wait=true;wait;) { DWORD errors=0 ; COMSTAT comState ; /* COM-Port Status-Information */ ClearCommError(hComPort, &errors, &comState) ; debug("checking") ; rxCount=comState.cbInQue ; /* dirty time consuming section */ if(rxCount>0 || timeout==0 || (int)GetTickCount()-startTime>=timeout) wait=false ; } if(rxCount>=1024) rxCount=1024 ; if(rxCount>0) { rxpos=0 ; rxlen=0 ; debug("reading") ; bool ok=(ReadFile(hComPort,rxbuffer,rxCount,&rxlen, NULL)==TRUE) ; if(!ok || rxlen==0) throw "ReadFile failed" ; } debug("rxout") ; } return (rxpos