LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback function in LabView

As a LabWindows CVI user for many years I'm used to have callback
functions in my user interface. These are functions which are run only
when the user is (left/right...) clicking on the bottom or changing the
value of a numeric control.
In Labview I have to run a VI permanenely which is looking for changed
states of the controls, at least this is the way it is done normally. I
would prefer to do it with callbacks here as well.

Example: I have a table with many values I sometimes have to change
manually. If this is done I have to calculate some other values. When
I'm happy with everything I quit the (Sub)VI. This has to be done with a
while loop which is stopped when the VI is quitted.
I would prefer to have it like this:
Everytime a value
is changed the calculated values are calculated
(once). Nothing happens else - so no waste of processor time.


My main interest is not on how to solve this example, but how to
implement callback functions
I'm running LV5.1 on win98

Thanks for any hints
Urs
0 Kudos
Message 1 of 4
(3,601 Views)
You could do a CIN, or perhaps DLL, that registers a callback function for
your VI and put it into a sub-VI such that when called, it will not return
until a Windows message is received. This is the only way I can think of,
and I don't know how well it would work since I assume Labview itself
already has callback functions registered.

Polling every 100ms doesn't take a great deal of CPU though. Don't know if
it's really woth the effort.

urs wrote in message news:3BF92903.BD6D0CF8@no.com...
> As a LabWindows CVI user for many years I'm used to have callback
> functions in my user interface. These are functions which are run only
> when the user is (left/right...) clicking on the bottom or changing the
> value of a numeric control.
> In Labview I
have to run a VI permanenely which is looking for changed
> states of the controls, at least this is the way it is done normally. I
> would prefer to do it with callbacks here as well.
0 Kudos
Message 2 of 4
(3,601 Views)
Well it is the LabVIEW paradigm. LabVIEW is data driven (execution flow directed by the availabilty of data) as call back function are event driven (execution triggered by the occurence of a predetermined event).
Staying with pure G code, it is not possible to detect if the value of a control has changed without comparing in a loop its actual value with its previous value. Detection of mouse hovers and clicks is not available except for the picture control.
However, with appopriate coding, this change detection can be encapsulated in subVIs and made transparently outside the main diagram, emulating call back *VIs* on data change on a front panel control. I have attached a set of VIs (5.1) that illustrate the technique. Changes are detected in a reen
trant subVI (GeneralChangeDetect.vi) that fires some code when a change occurs on the polled control. For example, it can call a subVI when a change occurs (Greetings.vi).
Obviously it is not the answer you expected but it is an illustration of how such things are coded in LabVIEW.
This code is even simpler with LabVIEW 6 where the VI refum and control name string used to identify the polled control are replaced with a single control reference and variant data type is used instead of flattened data.
As LabVIEW evolve as a graphic programming langage, I expect to see more and more features related to control related events. I wouldn't be surprised to, sooner or later, have a property node that allows to detect data change and mouse events, like an occurence refnum or something similar.

To LV6 users: just drop the "Write to VISA" case to repair the broken "GeneralChangeDetect.vi". VISA controls are not refnums anymore...

Happy wiring.


LabVIEW, C'est LabVIEW

0 Kudos
Message 3 of 4
(3,601 Views)
Looks like we need to use a 'endless' loop for any kind of 'callbacks', but with the help of
some VIs it seems to be possible to walk around some problems resulting in a very simple loop
approach and to have it 'feel like'. I think your VIs are worth to study in detail !
Thanks a lot for the very interesting VIs

Urs

Jean-Pierre Drolet schrieb:

> Well it is the LabVIEW paradigm. LabVIEW is data driven (execution
> flow directed by the availabilty of data) as call back function are
> event driven (execution triggered by the occurence of a predetermined
> event).
> Staying with pure G code, it is not possible to detect if the value of
> a control has changed without comparing in a loop its actual value
> with its previous value. Detection of mouse hovers and clicks is not
> available except for the picture control.
> However, with appopriate coding, this change detection can be
> encapsulated in subVIs and made transparently outside the main
> diagram, emulating call back *VIs* on data change on a front panel
> control. I have attached a set of VIs (5.1) that illustrate the
> technique. Changes are detected in a reentrant subVI
> (GeneralChangeDetect.vi) that fires some code when a change occurs on
> the polled control. For example, it can call a subVI when a change
> occurs (Greetings.vi).
> Obviously it is not the answer you expected but it is an illustration
> of how such things are coded in LabVIEW.
> This code is even simpler with LabVIEW 6 where the VI refum and
> control name string used to identify the polled control are replaced
> with a single control reference and variant data type is used instead
> of flattened data.
> As LabVIEW evolve as a graphic programming langage, I expect to see
> more and more features related to control related events. I wouldn't
> be surprised to, sooner or later, have a property node that allows to
> detect data change and mouse events, like an occurence refnum or
> something similar.
>
> To LV6 users: just drop the "Write to VISA" case to repair the broken
> "GeneralChangeDetect.vi". VISA controls are not refnums anymore...
>
> Happy wiring.
>
> ------------------------------------------------------------------------
> Name: GeneralChangeDetectEx.zip
> GeneralChangeDetectEx.zip Type: Zip Compressed Data (application/x-zip-compressed)
> Encoding: base64
> Description: Change detection
0 Kudos
Message 4 of 4
(3,601 Views)