Solved

How to implement a service loop with threads.

Posted on 1998-11-14
1
159 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now