Jump to content

Event handling from subVIs


Recommended Posts

Hey all,

I have a VERY newbish question today :thumbdown: , and I am pretty sure the answer is no, but just in case: Is it possible to use event structures in subVIs such that they handle events of the main program? I know it's very likely this is not possible since it is out of scope of the main, but I am not 100% sure about it. I would find it REALLY useful to implement event handling in subVIs, as my main is already very large as it is.

Link to comment

Ok, here's what I want to do: I want to enable user drawing on a graph (similar to examples > general > uievents.llb > Draw Graph with Events.vi), but the graph I have has two plots. I only want to allow drawing on one plot. The problem with the Draw Graph example is that it only supports one plot graphs. In addition, having used LabVIEW for just two months, I am not too familiar with event structures and references. Moreover, it seems I cannot modify the example to be a subvi without having to rely on shift registers (I require the while loop to be in the main and the event subvi to be within two nested case structures in the loop, which makes using shift registers even more complicated. Maybe I could use local variables). Well, this is kinda a mess :oops:. I don't expect you, Neville, or anyone else to spend TOO much time on this, because it is probably tedious for you experts. BUT it would be much appreciated if you could show me how to have a subvi that controled drawing of one plot on a multiple-plot graph (that is in the main) using a while loop in the main and relying on the smallest amount of shift registers.

Link to comment

Just an FYI.... I use a producer/consumer architecture to handle events for large apps... you can look it up on NI knowledgebase... that lets you have a main event handler that queues up the events (the producer) and another loop (the consumer) that processes them independently in the order received. This allows most of the code to be disconnected from the main event handler and stuck in smaller subvi's if necessary. I know this isn't the direct answer to your question but it might be new for you. I also always recommend 100% learning how to use LV2 style globals as they make extracting code off the main VI into subvi's much MUCH easier.

Link to comment
Is it possible to use event structures in subVIs such that they handle events of the main program?

5720[/snapback]

Yes you can do it but It will add some complexity to your code.

The Dynamically Monitor VI's.vi in the examples is a good place to start.

as my main is already very large as it is.

5720[/snapback]

I haven't seen your code but I doubt the event structure is the primary reason your diagram is so large.

SubVi have always been my main tool for shrinking the block diagram. If you are going to spend time shrinking

the block diagram I would recommend focusing it there first.

And (plug plug) if you want to save time wiring and cleaning up your sbuvis try using the Subvi fixer.

http://forums.lavausergroup.org/index.php?showtopic=1597 ;)

Link to comment
Ok, here's what I want to do: I want to enable user drawing on a graph (similar to examples > general > uievents.llb > Draw Graph with Events.vi), but the graph I have has two plots.Ā 

5726[/snapback]

Could you post what you have so far so we have something to start with.

It makes it easier to help if we are all talking about the same thing.

Don't worry about how messy it is we just need someplace to start.

By the way this is not trivial stuff.

Link to comment
I haven't seen your code but I doubt the event structure is the primary reason your diagram is so large.

SubVi have always been my main tool for shrinking the block diagram. If you are going to spend time shrinking

the block diagram I would recommend focusing it there first.

5728[/snapback]

Well, I already use about 10 subVI's (which are called multiple times) and plan to use more. I do have to agree though that many of my core calculations and functions are done in the main. I did this because I programmed the basics of the program first in the main and later became too lazy to change it afterwards :headbang: .

And (plug plug) if you want to save time wiring and cleaning up your sbuvis try using the Subvi fixer.

http://forums.lavausergroup.org/index.php?showtopic=1597

Link to comment
Could you post what you have so far so we have something to start with.

It makes it easier to help if we are all talking about the same thing.

Don't worry about how messy it is we just need someplace to start.

By the way this is not trivial stuff.

5729[/snapback]

Ok, here it is...

Have fun!!!

Download File:post-2549-1124480207.vi

Download File:post-2549-1124480223.vi

Download File:post-2549-1124480268.vi

Download File:post-2549-1124480275.vi

Download File:post-2549-1124480285.vi

Download File:post-2549-1124480300.vi

Download File:post-2549-1124480317.vi

Download File:post-2549-1124480385.vi

Download File:post-2549-1124480429.txt

Download File:post-2549-1124482786.vi

Link to comment
Ok, here's what I want to do: I want to enable user drawing on a graph (similar to examples > general > uievents.llb > Draw Graph with Events.vi), but the graph I have has two plots.Ā  I only want to allow drawing on one plot.Ā  The problem with the Draw Graph example is that it only supports one plot graphs.Ā  In addition, having used LabVIEW for just two months, I am not too familiar with event structures and references.Ā  Moreover, it seems I cannot modify the example to be a subvi without having to rely on shift registers.

5726[/snapback]

To use multi plots in the example see attachment. Also have moved one case to a sub VI to give you some idea of the use of the graph refnum.

I have some more advanced code that can add any number of plots to a multi plot graph and changed their labels and a few other things and is done in sub VI's but this is at work. If you want a look let me know but you will have to wait to tuesday (Melbourne Time) when I go back to work. Moday RDO :D

Download File:post-2707-1124510958.zip

Link to comment

Ok so you see how to do a multi user plot but the next question how to get it into your existing code still remains.

To expand on what m3nth was talking about we covered some of this in this post.

http://forums.lavausergroup.org/index.php?showtopic=1474&hl=

In it I posted a Que Structure demo showing how to separate the user interface from the process code.

Understanding that you are trying to digest and understand these new Ideas, a total rewrite doesn't get your code working any sooner.

So here is what I would recommend until you are more comfortable with ques.

1: In Sequence 1 inside the While Loop create a Event Structue around all the code and make it the timeout case with a timeout of 100ms.

2: Insert kel712 code in the event structure and test it out. This should get you to where you need to be with out a total rewrite.

3: Now one by one take the items in the timeout case where you are looking for user input and create an event case for them.

Example: Create a event case for the Go Home button and in that case place the code.

This will also help reduce the size of your block diagram. Remember to test your code after every change.

Link to comment
Sorry I couldnt ZIP it, my work firewall filters uploaded zipz

5733[/snapback]

Does your firewall filter ZIPs which have been renamed to have a different extension?

It should be easier for people to download one file and rename it.

Also, an important tool is the LLB, which allows you to save many VIs to a single file (although you need to be careful in how you use it). You can save as an LLB by going to File>Save with Options>Development Distribution.

Just a tip for next time. :arrow:

Link to comment
Does your firewall filter ZIPs which have been renamed to have a different extension?

It should be easier for people to download one file and rename it.

Also, an important tool is the LLB, which allows you to save many VIs to a single file (although you need to be careful in how you use it). You can save as an LLB by going to File>Save with Options>Development Distribution.

Just a tip for next time.Ā  :arrow:

5743[/snapback]

Yeah, I forgot about using libraries... duh! I'll be sure to use them in the future. Thanks :shifty:

Link to comment
Yeah, I forgot about using libraries... duh!Ā  I'll be sure to use them in the future. ThanksĀ  :shifty:

5763[/snapback]

Ok the future is now.

Can you please post the vis as a development distribution.

In your main vi go to

File>>Save with Options

select Development Distribution

and Save.

post-584-1124830382.png?width=400

LabView will create a llb with all the vis needed to run the main.

This makes it much easier to help. :)

Link to comment
Ok the future is now.

Can you please post the vis as a development distribution.

In your main vi go to

File>>Save with Options

select Development Distribution

and Save.

post-584-1124830382.png?width=400

LabView will create a llb with all the vis needed to run the main.

This makes it much easier to help. :)

5807[/snapback]

Ok, sorry about that... my last post's attachments were not in this format, though, because they were only two files.

Link to comment

Ok

Here are the changes I needed to make to get it to work.

1: The bool wire in the event structure time out case needs to be passed through

2: The integer controls and indicators from kels code were changed from I32s to U32s this caused big problems when negative values were used.

After that it worked.

I also added a stop button and replaced local variables with shift registers.

I would highly recommend learning to use shift register instead of local variables.

By using local variable this way you created a race condition which means there was no way to determine if the graph was updated first or the data was modified first.

Although a minor problem in this case they can become big problems.

lets us know if you need more help.

Download File:post-584-1124948981.llb

Link to comment
Ok

Here are the changes I needed to make to get it to work.

1: The bool wire in the event structure time out case needs to be passed through

2: The integer controls and indicators from kels code were changed from I32s to U32s this caused big problems when negative values were used.

After that it worked.

I also added a stop button and replaced local variables with shift registers.

I would highly recommend learning to use shift register instead of local variables.

By using local variable this way you created a race condition which means there was no way to determine if the graph was updated first or the data was modified first.

Although a minor problem in this case they can become big problems.

lets us know if you need more help.

Download File:post-584-1124948981.llb

5837[/snapback]

Nice! :thumbup: The only problem I have (a very minor one at that) is that the point where drawing occurs is above and slightly to the right of the cursor (see picture).

post-2549-1124972259.jpg?width=400

Link to comment
the point where drawing occurs is aboveĀ  and slightly to the right of the cursor (see picture).

5840[/snapback]

Because your Graph is different in size the offset values in the Scale Values.vi need to be tweaked.

maybe kel can explain how he figured out what offset values to use.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.