Hi,
I am using window mobile 5 pocket pc platform.
My serial application has two threads in which one is for keep reading data
from external device and another is for sending data.
The application nature is "while data is keep coming in, the application may
have to send back the data to the external device"
I control the reading thread with WaitCommEvent so that the thread doesn't
need to call read api forever if the data hasn't arrived to the com port yet.
Initially read thread is waiting on WaitCommEvent followed by the write
thread sends data.
The read thread is then notified that the data is arrived and keeps
receiving data.
The program works fine until this stage.
The below problems occur follwed by the first initial successful
communication.
(1) After that, the read thread keeps reading and the write thread needs to
send back the data.
When I call WriteFile during the other thread is keep calling the ReadFile,
the thread which calls
WriteFile hangs in the WriteFile api.
or , In some situation
(2) The read thread calls again the WaitCommEvent. The other thread calls
the WriteFile api and
WriteFile api fail with the error of "ERROR_INVALID_HANDLE".
or
(3) The write thread calls the WriteFile and before returning from this api,
the read thread calls the
WaitCommEvent api. The WaitCommEvent fail with the error of
"ERROR_INVALID_HANDLE".
According to my observation:
- Window mobile 5 serial driver doesn't support full-duplex that's why I
could not call the serial APIs from different threads at the same time, is it
right?
- In this case, I cannot use the WaitCommEvent and i have to use keep
calling the ReadFile api even though there is no data coming in. It makes
this thread keep busy and it will effect the performance issue.
Is there better way to control this situation?
- If not support full-duplex, why at the initial time, calling WaitCommEvent
from read thread first followed by WriteFile from write thread successful?
Can anyone help me?
Thanks a lot.