Hi

I want to read data from the serial port using api. Why don't I want to use the ms comm control? Who told you I was working in VB?

Right now, I'm opening the com port as a file, change the settings of it and I use ReafFile to read data from it.

The problem is, I want to read the port only when new data arrive.
If I use ReadFile, I have 3 options:
1- the function returns even if there are no data, so I need to put it in an infinite loop that takes 100% of cpu usage(not good)
2- Infinite timeout - It needs to be in a separate thread so the app will not lock. But there is no way to kill a thread doing a ReadFile, the ReadFile need to return before the thread can be killed.(not good)
3- A not infinite timeout, also in another thread but I only have to test if the thread should die before reading again. This is the best method up to date.
I'd like to read the port ONLY when new data arrive.

So, how would I read the serial port using a blocking reading, reading that I could unlock everytime I want to?

I think that the key to this answer is with ovelapping I/O, WaitFoSingleOBject and CreateEvent but I can't figure out how to use them.

Any help would be appreciated.

Thanks