LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering events in a sub-VI

I am trying to incorporate a subVI with event handling into a main VI.  Changing values on the main front panel does not elicit changes in the values of the controls in the subVI to which the main controls are wired.  I have attached a simple example to demonstrate my problem.

In these VI's, the subVI works independently with three different event cases handling 4 different events.  When this sub is placed in the Main Message VI, it loses functionality because the events in the Main VI do not cause the same events in the subVI, which is what I intuitively thought.  (You will be able to use the subVI independently, but the main VI will not act and you will have to use the stop sign to break it). 

This example is redundant, I know.  And I know of a help file and an example of dynamically registering events, however, I can't make heads nor tails of it.  Dynamically registering events seem to work in the opposite way, where the event handler is in the main VI and changes in the subVI elicit event handling in that frame. 

Any ideas?  Am I completely wrong in my conception?

Thanks,
Brad
Download All
0 Kudos
Message 1 of 12
(5,867 Views)
Hi Brad,

Your assumptions are correct regarding events with subVIs and TopLevel VIs.  Successfully detecting an event in a SubVI from a top-level VI requires some more work and can be done with LV 7.0 and higher. I will try to talk it out on how to do it:

The link between the VIs is a reference to the front panel object that will trigger the event. To detect a front panel event that occurs in a SubVI from Top-level VI, do the following:

In the SubVI, do the following:
  • Place a control reference function on the front panel for all the events to be monitored.
  • Place a "register for event" function on the block diagram.
  • Register all the events to be monitored by connecting all the control references to the register for event function and select the event to be monitored
  • Enable the dynamic event terminal on the event structure by clicking on the structure and selecting "Show Dynamic Event Terminal ".
  • Connect the register for event function to the Dynamic Event Terminal and edit the event handled by each case. Make sure you select the control and event to be monitored under dynamic source.
  • Place "unregister event" function after the event struture and wire it to the output of the dynamic event terminal to unregister the event.
  • The front panel event will now be selectable as a dynamic event.

  • In the Top level VI, do the following:


  • Create a reference to the front panel Control in A. To do this, right click on the control and naviagete to "Create»Reference"
  • Place the subVI created in 1 onto the Top-Level VI.
  • Pass the reference from A to B. Connect the control reference to the corresponding control-reference input created in SubVI.

  • I have attached two screenshots on how to do this.  Hope this helps.

    Regards,

    Nadim Rajabi
    Applications Engineering
    National Instruments
    Download All
    Message 2 of 12
    (5,842 Views)
    Sorry bout that.  Here are the pictures.

    Regards,

    Nadim
    Download All
    Message 3 of 12
    (5,840 Views)
    Thank you, Nadim.

    there are two things I don't understand here.  1) Why do you create the control references in the main VI and not the subVI?  Where do you generate the control reference refnums seen in the subVI in order to recognize the specific controls referred to?  2)  How do you change the tunnel into the event structure into a satellite icon thingy?  I have not had this occur automatically nor has it appeared as an option.  Although, I doubt it is called a satellite icon thingy, so I wouldn't recognize it if it hit me in the head.

    Brad
    0 Kudos
    Message 4 of 12
    (5,823 Views)
    OK, the answer the 2nd question was obvious.  Now I should rephrase the first questions.  1)  Why wire the control reference and not simply the control to the subVI icon? 

    Thanks,
    Brad
    0 Kudos
    Message 5 of 12
    (5,822 Views)
    OK, now I've answered my own questions and I still have a VI-subVI combo that doesn't perform.

    I've attached them here, can you check if I've wired them up correctly?
    Download All
    0 Kudos
    Message 6 of 12
    (5,813 Views)
    Hey,

    I believe you are selecting value change and not dynamic value change.  Notice the brackets <  >  in the event case are missing in your application.  I have attached my VI's to this discussion forum. 



    Regards,


    Nadim
    Applications Engineering
    National Instruments
    Download All
    Message 7 of 12
    (5,789 Views)
    Thank you for your insight, Nadim.  I have a working VI, but of course there are peculiarities that relate to my lack of understanding of the event structure. 

    I have attached the main and sub here, it is sort of a chat emulation for example purposes. 

    I needed to put in a timeout case in the subVI event structure in order to have the VI react to the "Send" value change without having to register another event afterwards.  I am not sure why this needs to be done, or how it should best be done.  Now for instance, the "Message is being typed..." constant only appears for the length of the time out while the user mouses over the message text control.  Is there a way to dynamically control timeout lengths?  I.e. make it -1 after the mouse over event but almost instantaneous after the send message and stop value change events?

    These questions relate to my real application where a value change in any of a number controls initiates a subVI that writes a waveform onto an NI card.  This needs to happen instantaneously, once, when the value is changed.  It does not need to happen every time the main VI iterates its while loop.  The subVI cannot hang the main VI up while it waits to pass values through the sub, either.  So this is why I am asking these questions abou the simple VI's posted below.

    Cheers,
    Brad
    Download All
    0 Kudos
    Message 8 of 12
    (5,766 Views)
    Hi Brad,

    The timeout on the Event Structure works like this-  The event structure will wait for a dynamic change.  If no change has occurred before the timeout, then the event structure will implement what is inside the timeout case.  To dynamically control your timeout, wire a numeric control to the timeout.  Create a local variable from the numeric control and copy it to each structure case.   Change the local variables to write and wire your value to them. 


    Regads,

    Nadim
    Applications Engineering
    National Instruments
    Message 9 of 12
    (5,729 Views)

    Hi Brad

     Can you pls convert all these attachments to LV 7.1  because I want to know what's happening as I also experienced the same problem?

     

    regard

    Clement

    0 Kudos
    Message 10 of 12
    (5,192 Views)