LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use Event structures in a subVI?

Hi,
I have a subVI (ProvaEv1.vi) that use an event structure inside. But when I use it in a VI (ProvaVI.vi) the event structure in the subVI doesn't catch the events.
I tried to insert the event structure in a while loop but it doesn't work too.
Could you help me?
 
Thanks Ius
 
Download All
0 Kudos
Message 1 of 6
(3,350 Views)
Well... in fact what happens in your VI is that the event struct in the subVIs checking if the control called "boolean" changes ; and the value you are modifying from the main VI is "Boolean 3"...

In general, when using an event struct, is to catch "User Interface Action"... so if the event is not in the interface VI then it's alot more complicated to make it work. I think you should try to keep the event struct in your main VI and then you can run associated code in subVIs.

Hope this helps 😉

We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 2 of 6
(3,344 Views)
Hi,


You can use an event structure in a sub vi, but it might not do what you expect.


If you catch a front panel mouse down event, and put in a sub vi, it will respond to a click on the subvi's front panel.


You can make user events, and pass the event registration to the subvi. To do this, you'll have to put a "register for events" node in the main vi, and wire a (vi or control) reference to it (to the "event" area). Then you can click the "event" area and select one of the events that correspond to the reference type. You can scale it to add more events.


It doesn't work very nice though. If you add, remove or change any of the events, the "Event Registration Reference" will get another type, and won't match the control in the subvi...


Events are much easier if you put it in the diagram of the main vi.


Regards,


Wiebe.


"iusn" <x@no.email> wrote in message news:1156941608527-410258@exchange.ni.com...
Hi,
I have a subVI (ProvaEv1.vi) that use an event structure inside. But when I use it in a VI (ProvaVI.vi) the event structure in the subVI doesn't catch the events.
I tried to insert the event structure in a while loop but it doesn't work too.
Could you help me?
&nbsp;
Thanks Ius
&nbsp;



ProvaVI.vi:
http://forums.ni.com/attachments/ni/170/203179/1/ProvaVI.vi



ProvaEv1.vi:
http://forums.ni.com/attachments/ni/170/203179/2/ProvaEv1.vi
0 Kudos
Message 3 of 6
(3,340 Views)

hi there

as an alternative you may check the usage of event callback functions (see attachment). but they have their caveats too...

if possible i'd do the way Wiebe suggested.

 

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 4 of 6
(3,334 Views)

Thanks to all for your answers!

Wiebe! I tried to do as you suggested but I am not able to link the Event Reference Number inside te SubVI with the Event Register Number of the Register for Event in Main VI. There is e class conflict.
Another question: how the SubVI can know the structure of the Register event outside?
My aim was to create a modular structure but it seems very difficult, wath do you think about these problems?
I have already create my application using event structure just in Main VI but it seems very complicate to read and keep update, I would have wanted to give modularity to my application.

Thanks Ius

Download All
0 Kudos
Message 5 of 6
(3,313 Views)

"iusn" <x@no.email> wrote in message news:1156952408221-410369@exchange.ni.com...
Thanks to all for your answers!
Wiebe! I tried to do as you suggested but I am not able to link the Event Reference Number inside te SubVI with the Event Register Number of the Register for Event in Main VI. There is e class conflict. Another question: how the SubVI can know the structure of the Register event outside?My aim was to create a modular structure but it seems very difficult, wath do you think about these problems?


The broken wire is related to your question. The event structure inside the sub vi knows about the events you register in the main, because the reference wire/control has a "strong" type. It contains information about the registered events. That is also why the wire is broken. You have to register all events, then create an indicator/control of the output. Use that control in the subvi. You have to do this every time the events change (you might use a type def if you use the control a lot).


Usually, the events that you would want to put inside subvi's are those related to user interface objects. I've had this a lot. You make a nice interface, but it's not reuseable, because the events are mixed with all the other events. Only solotion is to manually add the needed event cases in your program, and copy the code.


Even if you can put the events in a sub vi, I'd expect hanging vi's when more subvi's are registered for the same event. It's hard to tell without trying. So it's not a real solution either.


Like Chrisger suggested, the event callback might help a little, but they are tricky, and actually ment for this (they are intended for activex callbacks).


Perhaps you should look at XControls (if you use 8.2). It would be more work to replace your code to XControls, but once you're done, you have reusable code.. Haven't worked with them jet, but they are invented for this problem...


Regards,


Wiebe.






I have already create my application using event structure just in Main VI but it seems very complicate to read and keep update, I would have wanted to give modularity to my application.
Thanks Ius



SubVIEventMain.vi:
http://forums.ni.com/attachments/ni/170/203225/1/SubVIEventMain.vi



SubVIEvent.vi:
http://forums.ni.com/attachments/ni/170/203225/2/SubVIEvent.vi
0 Kudos
Message 6 of 6
(3,272 Views)