Jump to content

Best way to re-initialize?


Recommended Posts

I need to add a routine that will re-initialize almost all the controls and indicators of the top-level vi to the start state (but retain a few that show history etc).

Two ways spring to mind - a straight-forward wiring of required values (eg FALSE constant wired to all LEDs that should be off, etc) or use of an invoke node for Reinitialize to Default for each control/indicator.

Invoke nodes have the advantage of always matching the default value set on the FP, but I could (and probably will) call the re-initialize routine at startup anyway, so that shouldn't be a big issue. Then I started wondering whether the performance hit for property nodes applied to invoke nodes as well. Granted I will probably use DeferPanelUpdates anyway to only refresh the FP once after all values are set, and the user won't mind a small pause at reset (in fact they'd probably expect it) but the function could be called frequently so I'd still like to make it efficient.

Anyway, just wondering what other people think .....

Link to comment

Anyway, just wondering what other people think .....

I think local variables are faster than reinitializing each control through an invoke node. If you have lots of fp controls and only a few controls you want to preserve you could buffer those values on a wire and copy it back into the control after resetting all the fp controls. That would probably make your code easier to read than a bunch of local variables or invoke nodes. I don't know if there is a performance difference between reinitializing each control separately and the entire fp at once. You'd have to benchmark it.

post-7603-092433800 1277234528_thumb.png

Link to comment

I wouldn't bother with individual controls, even if you're going to do this fairly often. It should probably not take long to execute if you defer updates.

Based on your description, I would say you should get the references to all the controls on the FP once (using the Controls[] property or, if you have nested controls, using <vi.lib>\utility\traverseref.llb\TRef Get All FP References.vi) and then build the controls you don't want to reset into an array and remove them from the first array using a for loop. You now have an array of all the controls you want to reset which you can go over in a for loop. You can call the reinit method for each one.

  • Like 2
Link to comment

I wouldn't bother with individual controls, even if you're going to do this fairly often. It should probably not take long to execute if you defer updates.

Based on your description, I would say you should get the references to all the controls on the FP once (using the Controls[] property or, if you have nested controls, using <vi.lib>\utility\traverseref.llb\TRef Get All FP References.vi) and then build the controls you don't want to reset into an array and remove them from the first array using a for loop. You now have an array of all the controls you want to reset which you can go over in a for loop. You can call the reinit method for each one.

Good idea - and any new controls I add will be automatically added to this too. Thanks!

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.