Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to implement a service loop with threads.

Posted on 1998-11-14
1
Medium Priority
?
220 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

886 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