Solved

How to implement a service loop with threads.

Posted on 1998-11-14
1
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 137
Host to IP 7 84
Define unique primary key 9 99
Problem to open Excel file 15 258
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

737 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