Solved

How to implement a service loop with threads.

Posted on 1998-11-14
1
194 Views
Last Modified: 2013-11-20
I had asked a question earlier about timers to help in determining if there was data to read at a serial port.  Now that I have data waiting, I would like to setup a threaded service loop to send and recieve data to the port without interferring with other tasks that might be occurring? Sample code as an example would be great. Thanks!
0
Comment
Question by:beardenc
1 Comment
 
LVL 2

Accepted Solution

by:
wyy_cq earned 50 total points
ID: 1324696
HANDLE hPort;
//thread entry
dword threadA(lpvoid)
{// you read 50 bytes once
BYTE buf[50];
ReadFile(hPort,....);// when return you can know how many bytes you have read
while(1)
 DealWithBuf(buf);//your code to process the read data
}

there an other simple way,
in the Win32, the serial Device can read or write asynchronously.
you need use the FILE_FLAG_OVERLAPPED flag when you call CreateFile(....);
to know more please read the vc5 help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
child constructor and parent constructor, overriding and overloading 6 93
EvenOdd challenge 10 144
Making an alias 7 110
Way to decrease size of apk file 9 104
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question