Hello,
I am using two maxsteram XTEND modems. i am havnig some trouble doing some simple io.
i send a string "hello" from one to the other in a loop. if i send less than 500 tiems, it works. .. if i try to send more than 500 times, the receving end receives the string as "eohell".. i am using non overlapped io.
sending code (this works since we have "while (i<500)".. if i make it "while (true)" or "while (i<600)" it does not work)... i have marked the line with "//HERE********************" in the code.. i have also marked two other lines that i would like you to see (with waitcommevent).
receiving code:Code:int main(){ HANDLE hport; hport=CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,0,NULL); DWORD dwCommEvent; if (hport==INVALID_HANDLE_VALUE ){ std::cout<<"PORT UNAVAILABLE"<<std::endl; } else{ initcomport(hport); SetCommMask(hport, EV_CTS|EV_DSR); char * test="hello"; int i=0; while (i<500){ //HERE******************** DWORD dwNumBytesWritten; int bsent=0; while (bsent<buffersize){ WriteFile(hport, test+bsent, buffersize-bsent, &dwNumBytesWritten, NULL); bsent=bsent+dwNumBytesWritten; } //WaitCommEvent(hport, &dwCommEvent, NULL);//HERE******************** //dwCommEvent=0;//HERE******************** i++; } }//close else return 0; }
It seems that i have some sort of synchrozniation issue here... i tried using "WaitCommEvent()".. but it waits indefinitely when i use that... (this can be seen in the commented liens in the sending part)..Code:int main(){ HANDLE hport; hport=CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,0,NULL); if (hport==INVALID_HANDLE_VALUE ){ std::cout<<"PORT UNAVAILABLE"<<std::endl; } initcomport(hport); //function to initialize the port. char * test=new char [buffersize+1]; while (true){ DWORD dwBytesTransferred=0; int brec=0; while (brec<buffersize){ ReadFile(hport,test+brec,buffersize-brec,&dwBytesTransferred,NULL); brec=brec+dwBytesTransferred; //test[dwBytesTransferred]='\0'; } test[buffersize]='\0'; std::cout<<"Buffer is: "<<test<<std::endl; } return 0; }
what i'm really looking for is to know when the modem is ready to send out more data and when the modem is ready to receive. i hope someone can h elp me out!
thanks a lot!
drew.





Reply With Quote