wait time in serial communication

A

Thread Starter

Anonymous

Hi,

I am writing RS232 serial communication software in VC++. What function should I use for waiting receive data after I transmit data? Can I use sleep()?
 
I'm not familiar with Visual* or C++, but in C I usually use select() or pselect() to find out when data is available and the process interval timer with setitimer() to handle communication timeouts.
 
Do not use sleep(). You can use it, but that will make your program sleep for the time you specify in the sleep() call. If data is available sooner than that, your program will not notice this and keep sleeping till timeout. A better approach is to use SetCommTimeouts(). You can set specific timeout for reading/writing data to the com port. Next, when you call ReadFile(), if data is available immediately, the readfile will suceeed otherwise it will wait for the time ou specified in SetCommTimeouts().

Hope this helps.

[email protected]
 
Top