04-25-2014 08:45 AM
Say I have a numeric slide on one panel. When I move the slider I need the value to be updated on another panel.
How can I do this?
Both panels are loaded as top level windows.
It seems like I read something about using queues to pass data between panels but I can't seem to find where I read that.
Solved! Go to Solution.
04-25-2014 09:20 AM
Why not installing a callback on the numeric, trap EVENT_VALUE_CHANGE and update accordingly the control on the other panel?
04-25-2014 09:26 AM - edited 04-25-2014 09:35 AM
Thanks for the reply.
I do have a callback installed for the slider. I'd rather not constantly poll a variable in panel1 unless there's no other option.
Ideally, panel2 would notify panel1 that there is data ready. Then panel1 would read it. Coming from the C# world I'm used to
using delegates and events.
EDIT: I may have found the answer with QueueUserEvent and GetUserEvent
04-25-2014 12:40 PM
I do not understand your comment on "poll continuously".
If you want to reduce the number of events, trap EVENT_COMMIT on the slider, which is fired only once after the user has finished moving the slider.
This is an event: if the user does not moves the slider, then no event is generated and no code is executed.
Using GetUserEvent can be tricky, as it returns every commit event generated on the user interface, that is, also events fired from controls other than the slider.
04-25-2014 12:52 PM
Can I install a callback in panel1 for a control on panel2 (the slider)?
In other words, Can I catch the slider's EVENT_VAL_CHANGE in panel1?
04-25-2014 12:57 PM
Callbacks are installed on the controls you want to trap events for. They can also be installed on the panels the controls are on, but I don't remember an easy way to have a panel be warned of an event in another panel.
Do you have a specific reason to reject a callback on the slider?
04-25-2014 01:03 PM
What I basically need is a multithreaded DAQ application.
I know C but this is the first time I've used CVI. I'm trying to experiment with the best way to get data from the DAQ thread to the main thread.
So far I've found that I can use Async timers and a thread pool. Those are both acceptable. I was just experimenting with other ways.
04-25-2014 01:51 PM - edited 04-25-2014 01:51 PM
Found what I needed.
Even though the slider is on panel2, I needed to install the slider's callback in panel1.c.
Maybe this isn't good coding practice though?
At least it works.
04-25-2014 06:20 PM
One basic concept that differentiate CVI from other languages is that there is no relation between a panel and a specific source file. I mean, you do not need to put functions related to one panel in a specific source file: they may be spread over multiple source files; at the other hand, you could have one source file only which collects callbacks for all panels in your application. What drives callback execution are panel handles and control IDs. (An effect of this paradigm is, you could have one callback installed on controls located on different panels).
For this reason, there is no problem in putting the slider callback in panel1.c. Besides it, you could call the source file in any other way.
Coming to the core of your problem, a multithreaded DAQ application is really different from a single-threaded user interface application.
Putting data acquisition functions in a separate thread can be beneficial for your application as they are not prone to suffer from user interface happenings.
CVI additionally supplies you with different methods of passing data between threads; the most powerful in DAQ applications is probably a Thread Safe Queue.
I suggest you to look at Programmer Reference >> Creating Multithreaded Applications chapter in the help,where the fundamentals of multithreading programming are explained and informations are given on all the instruments CVI includes.
If you want to discuss about this scenario, I suggest yu to start a new thread, as it has no relation with the original question with which you started this discussion.
04-28-2014 06:16 AM
Thanks for the reply.
I've got the multithreaded part down pretty good. No issues there.
The original issue arose from coming from object oriented C# to C. Using OOP was so ingrained in me, I had to train myself to use C.
It's becoming easier now. Thanks!