08-26-2013 03:40 PM
This seems like it should be a relatively simple application of a while loop, but I can't seem to find the solution 😕 Basically I have a string control on my front panel for a filename (minus path/extension), and when I start up the VI I check if the file already exists. If it does, I'd like to start a while-loop in which each subsequent iteration only occurs when the string control is changed by the user.
The way I have it wired up now works fine (see attached), but it loops every 50 ms even while there's an invalid string. If possible I'd like to pass to the next iteration only after the control value has changed. This way I can display an error dialog of some sort that won't pop up every 50 ms. (Note: this is a piece of code from a subVI, hence the refnums and property nodes.)
Thank you!
08-26-2013 03:58 PM - edited 08-26-2013 04:01 PM
Use an event structure and a value changed event for the input control.
Overall, your code makes very little sense. Is this supposed to be a subVI? There are no connectors defined.
08-26-2013 04:04 PM
Look into how to use an event structure and then use that to detect a change in the string control. You also need to brush up on datflow concepts.
08-26-2013 04:39 PM - edited 08-26-2013 04:40 PM
Okay okay, I only took the portion of the subVI that actually had the loop in it so I could illustrate what I am currently doing and what I wish to do and I made it its own file. There's obviously more to it than what I put in here, but I didn't include the rest of it because I didn't feel it was necessary. The reason for all the refnums is that I'm trying to check controls that are on the main front panel while I'm within this subVI loop. If you have a better idea than that, feel free to let me know. As far as I know references are the only way to access a control that may be changing once you've already entered a subVI.
Thanks for the tip on the event structure, I'll give that a shot tomorrow.
08-26-2013 04:47 PM
You could bundle all your control refs into a cluster. Typedef the cluster. Use that cluster on your subvi front panel. Update the typedefs you add more controls to your main front panel. That way you don't have to keep updating the subvi front panel every time you add a control to the main front panel.
08-27-2013 06:24 AM
@phogan wrote:
The reason for all the refnums is that I'm trying to check controls that are on the main front panel while I'm within this subVI loop. If you have a better idea than that, feel free to let me know. As far as I know references are the only way to access a control that may be changing once you've already entered a subVI.
Thanks for the tip on the event structure, I'll give that a shot tomorrow.
Yes, refs are the only way to control front panel objects from another vi, but do you need to? Send the value to the checking vi and react to that, if need be return a Valid boolean or similar, that's how it's usually done.
/Y
08-27-2013 07:16 AM
The inputs to the subVI are set once the process is begun, no? So if I have to monitor user-input while a loop is running then I have to pass references in order to have the latest values.
08-27-2013 07:26 AM
@phogan wrote:
The inputs to the subVI are set once the process is begun, no? So if I have to monitor user-input while a loop is running then I have to pass references in order to have the latest values.
Yes, but then you have some poor design choices, why should the sub-vi monitor main controls? You can send information as events or queues, or even store the information in an AE that's used in the sub-vi.
Still, the only button that should be needed to sent is "start" and "exit"
/Y
08-27-2013 07:51 AM
Fair enough, I'm just working with what I inherited ;). The code originally had image creation as just one small piece of a subVI, but when you're collecting images as data you'd like to not accidentally overwrite a file because you forgot to change the filename. I was hoping to contain all the file checking within the same subVI since it's used in a few different main programs.