Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IO to COM port

Status
Not open for further replies.

bubak

Programmer
Jun 25, 2001
208
SK
Hello
I have this problem:
When I CReateFile("COM1",GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0, 0);
I can WriteFile to that handle and it works fine. But when I do ReadFile(comhandle,buffer,1,&count,NULL), it functions just when sth is waiting there. When not, it waits for some data. How can I make the function working so, that it will read some data or return 0 READED when there is nothing instead of waiting? Can I use FILE_FLAG_OVERLAPPED somehow for this? Because when I use it, I can write and read once, but after it , it reads nothing (like when reading with nNumberOfBytesToRead setted to zero (for ReadFile).

Thanks
Bubak
 
Use a COMSTAT object!
Be careful , I used non-overlapped I/O !!!
Hope this works! For further documentation have alook at
the article "Communications in Win32" in the MSDN, it perfectly explaines the I/O with serial ports.

Example:

COMSTAT ComStat;
DWORD dwErrorFlags=0;
ClearComError(comhandle,&dwErrorFlags,&ComStat);
if(!ComStat.cbInQue) return(0);//Nothing in the buffer,
//so now you can use ReadData:

ReadFile(comhandle,buffer,1,&count,NULL);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top