Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to implement a service loop with threads.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

715 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