Non Overlapped Serial Ports

I am using Embbeded Visual C++ 4.0 to write an application on Pocket PC 2003 platform to communicate with another device via bluetooth serial port profile. I undestand that serial ports on PPC are Non Overlapped. I have to create a thread to read data and a thread to send the data. My problem is that my application can only send data once and then hangs. How do I synchronise the write thread and the receiving thread. is there any difference in using AfxBeginThread and CreateThread functions ? I also need to read all the data when it arrives in  the receive buffer instead of reading it character by character and specificing the receive buffer size limit. How do I implement an event handler to do this ? I have not put any of my code because I have decided to start all over again. Could someone please help it's quite urgent.

Thanks
Panashe
LVL 2
Code_AngelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteHCommented:
I would suggest to have only one thread which does all the communication with the serial port. The advantage of 2 threads for sending will be removed by the need of synchronising access to the serial port. My idea is to use an UI thread:
http://www.flounder.com/uithreads.htm
and do the reading in the OnIdle of the CWinThread class and writing is done in a message handler.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
>> How do I synchronise the write thread and the receiving thread

You'd use a CRITICAL_SECTION to protect the data and e.g. an Event to signal 'data ready'

>>is there any difference in using AfxBeginThread and CreateThread functions ?

The 1st one is MFC-only and can handle CWinThread objects, that's the main difference.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.