[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

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
0
Code_Angel
Asked:
Code_Angel
  • 2
2 Solutions
 
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
 
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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now