Click here to Skip to main content
15,903,388 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to set text of CButton/ radio button Pin
led mike13-Feb-09 4:37
led mike13-Feb-09 4:37 
JokeRe: how to set text of CButton/ radio button Pin
Rajesh R Subramanian13-Feb-09 4:58
professionalRajesh R Subramanian13-Feb-09 4:58 
GeneralRe: how to set text of CButton/ radio button Pin
CPallini13-Feb-09 7:26
mveCPallini13-Feb-09 7:26 
AnswerRe: how to set text of CButton/ radio button Pin
Hamid_RT13-Feb-09 20:10
Hamid_RT13-Feb-09 20:10 
QuestionMultiThread and Multi DC Pin
Max++13-Feb-09 3:32
Max++13-Feb-09 3:32 
AnswerRe: MultiThread and Multi DC Pin
Stuart Dootson13-Feb-09 3:53
professionalStuart Dootson13-Feb-09 3:53 
AnswerRe: MultiThread and Multi DC Pin
Rajesh R Subramanian13-Feb-09 5:02
professionalRajesh R Subramanian13-Feb-09 5:02 
AnswerRe: MultiThread and Multi DC Pin
Roger Stoltz13-Feb-09 5:34
Roger Stoltz13-Feb-09 5:34 
As Stuart said you should only use a DC from the same thread as the window was created.
But I consider that a minor problem as I believe that you don't need multiple threads for drawing the graphs. Read on... Wink | ;)
I've written quite a few (>25) applications with similar functionality, so perhaps I can contribute with some thoughts.

You have to distinguish between the different layers in your application.
You have at least three layers here that should not be mixed up: the hardware layer, the data acquisition layer and the presentation layer.


Max++ wrote:
The read data from each sensors is so fast(less than millisecond) So,I separate 4 thread for draw graph in each sensor.


Here's the mix up.
Even though your sensors can barf up measured data at that rate, it doesn't necessarily mean that the data should be presented to the user at the same rate, or in other words "in real-time". There's no point since the human eye cannot cope with that speed.
You need to think about the requirements of your application; shall it e.g. be possible to save the sampled data and what is the sample frequency, or is it just for presentation?
Perhaps the data acquisition layer should save every sample, but the presentation layer only need to ask for the current value of each sensor at e.g. 2Hz rate.

You have to tell us more about the requirements of your application for us to be able to suggest a suitable design.
But, based on my experience of common demands for such an application, I would suggest to have the following in mind:
  • The main (UI) thread is responsible for drawing all the graphs that are supposed to be presented to the user and would update the graphs on timer based events with rather low frequency, e.g. 2Hz to 5Hz. This would be the presentation layer.
  • The hardware layer continuously issues read requests in a "reading worker thread" with calls to ::ReadFile() that will return one or more data samples. They should probably be put in a queue from which the data acquisition layer can read them. In order to prevent immense memory allocation and deallocation I suggest using reference counting smart pointers as elements of the container.
  • If the gathered data needs some kind of interpretation, each sensor could have a thread that collects the data and save it in e.g. list in order to be able to save it later. When this thread runs it moves the data from the queue shared with the hardware layer into the its own container and updates the "current value" shared with the presentation layer. This would be the data acquisition layer.

If the raw data can be used for presentation you can omit the data acquisition layer and simply read the top element of the queue, or list, for each sensor that the "reading worker thread" puts the data in.
This way you have a clean design, you don't do any unnecessary updates to the GUI and you're able to save every data sample gathered from each of your sensors.
Sometimes the samples should be tagged with the time that it was sampled, but that depends on the requirements.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: MultiThread and Multi DC Pin
Max++13-Feb-09 6:32
Max++13-Feb-09 6:32 
AnswerRe: MultiThread and Multi DC Pin
Roger Stoltz13-Feb-09 23:43
Roger Stoltz13-Feb-09 23:43 
GeneralRe: MultiThread and Multi DC Pin
Max++14-Feb-09 2:47
Max++14-Feb-09 2:47 
AnswerRe: MultiThread and Multi DC Pin
Roger Stoltz14-Feb-09 15:15
Roger Stoltz14-Feb-09 15:15 
GeneralRe: MultiThread and Multi DC Pin
Max++14-Feb-09 17:25
Max++14-Feb-09 17:25 
QuestionNetFileEnum and GetLastError 997 Pin
aks.13-Feb-09 3:02
aks.13-Feb-09 3:02 
QuestionRe: NetFileEnum and GetLastError 997 Pin
David Crow13-Feb-09 5:50
David Crow13-Feb-09 5:50 
QuestionNeed help on how to set DDX control for dynamically created slider Pin
John50213-Feb-09 1:21
John50213-Feb-09 1:21 
AnswerRe: Need help on how to set DDX control for dynamically created slider Pin
Code-o-mat13-Feb-09 1:35
Code-o-mat13-Feb-09 1:35 
GeneralRe: Need help on how to set DDX control for dynamically created slider Pin
John50213-Feb-09 2:25
John50213-Feb-09 2:25 
GeneralRe: Need help on how to set DDX control for dynamically created slider Pin
Code-o-mat13-Feb-09 2:29
Code-o-mat13-Feb-09 2:29 
GeneralRe: Need help on how to set DDX control for dynamically created slider Pin
John50214-Feb-09 5:10
John50214-Feb-09 5:10 
GeneralRe: Need help on how to set DDX control for dynamically created slider Pin
Code-o-mat15-Feb-09 1:21
Code-o-mat15-Feb-09 1:21 
QuestionIntercept drop file operations between two explorers Pin
Nuno Esculcas13-Feb-09 1:20
Nuno Esculcas13-Feb-09 1:20 
AnswerRe: Intercept drop file operations between two explorers Pin
Sarath C13-Feb-09 1:38
Sarath C13-Feb-09 1:38 
GeneralRe: Intercept drop file operations between two explorers Pin
Nuno Esculcas13-Feb-09 7:29
Nuno Esculcas13-Feb-09 7:29 
GeneralRe: Intercept drop file operations between two explorers Pin
Sarath C15-Feb-09 17:12
Sarath C15-Feb-09 17:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.