Jump to content

First Run and Error Handler for Event structure


Recommended Posts

I think two needed events for the <This VI> Event Source are First Run, and Error Handler.

The First Run could be used for any initialization code you need to do. I've faked this function by wiring a Select function to the Timeout terminal with a 0 and -1 and when the While loop iteration terninal equals 0, it passes in the 0 so it times outs right away, then on the next iteration, it passes in the -1 so it never times out. Of course, if you don't need the Timeout feature for some other reason, you'd need to add a Case structure in the Timeout event case to run different code when the loop count does not equal 0.

post-47-1094047646.gif?width=400

The Error Handler event would watch a single error cluster and if it contains an error, that case would run any error handling code that have.

I know all of these features can be accomplished registering a dynamic event and triggering a user event for them, but it would be nice not to have add all that extra code since these are two things that almost every application needs.

Ed

Link to comment
I know all of these features can be accomplished registering a dynamic event and triggering a user event for them, but it would be nice not to have add all that extra code since these are two things that almost every application needs.

1600[/snapback]

So the dynamic events sounded promising to me after I said it, so I made up an example of how it would work.

post-47-1094056510.gif?width=400

The sub-vi on the left creates and registers the dynamic events. It also can fire the first Run event so it will run right away. The Trigger Error sub-vi watches the error cluster and will fire the error user event when ti sees one. Pushing the code into sub-vis cleaned up the diagram a lot and saves space. (until NI adds these events natively to the event structure :rolleyes: )

I've attached the example library if your interested.

Ed

Download File:post-47-1094056528.llb

Link to comment
Ed,

Is the element First Call? in the palette Advanced->Synchronisation not what you were looking for?

Didier

1606[/snapback]

The First Call? function by itself can't fire an event. You'd either have to write to a Value Signaling property node or have a Case Structure around your Event Structure to catch the First Call? value. I've used both in the past, but the Dynamic Events is much cleaner in my opinion. You end up with just a While Loop with an Event Structure and just a single VI outside the loop.

Plus, if you need to run your init code again, you just need to fire the First Call user event.

Ed

Link to comment
  • 5 months later...

I've updated this Event structure a bit.

It's now saved as a VI Template with front panel and block diagram images for the template browser.

I've also added an "Exit" event to handle all the shutdown code.

I keep the two sub-vis in my user.lib directory.

This is built in LabVIEW 7.0, but works just as good in 7.1

Ed

Download File:post-47-1109606765.zip

Link to comment

I catch Event errors with the subvi in the attached image - even if the Stop button is not visible on the FP. For init, I still use one subvi before the While-Event loop. Usually, the init vi enqueues commands that are interpreted by queue handlers outside the Event-While loop. I agree it would be more convenient if there were First Run and Error events.

post-107-1109620290.gif?width=400

post-107-1109620306.gif?width=400

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.