LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use Control References?

Hello,

 

I have LabView 2011, and I am trying to make a program that controls a waveform generator and occiliscope at the same time.  Unfortunatly, when I copy and paste the two vi's into one vi, The scope on the vi does not read correct data....  So I thought I would put each program into a sub vi.  However, I want to have the stop button on the main vi so it can stop both.  As I have seen on the web, global variables seem to be shunned upon.  So I came upon references.  It seems that there is a constant reference and control reference.  Since the point of a button is to change, I can't use the constant reference.  However, I am not sure how to use to control reference.  From what I saw http://labviewwiki.org/Control_References here, the solution seems to be to cast it to the class and then use the property block on the class.

 

I have a boolean control, that I want to pass to the stop of a while loop.  The stop block requires a boolean value (meaning when I get the value of the control, it needs to be "strict boolean").  However, casting to the boolean class does not satify the stop block...  see attachment c

 

Also, If I let it be a boolean reference, then get the strict value of it (as shown in b), I get an object reference is not valid error.  Finally attachement a shows the main vi boolean control refnum.

 

Thanks for any help,

 

Eric

 

Download All
0 Kudos
Message 1 of 9
(3,838 Views)


Eric,

 

It is a bit difficult to tell from an image.

 

Create the reference from the button on the front panel of Main or from the terminal on the block diagram.  Choose Create >> Reference from the pop up menu.  Then wire that reference to the reference controls on the subVIs.

 

However, using property nodes this way is usually not the best way to pass data between subVIs.  They are slow and force a switch to the UI thread.

 

Consider Notifiers or Queues or a functional global.

 

Lynn

0 Kudos
Message 2 of 9
(3,825 Views)

Thanks for the reply.

 

I am now working through creating a notifier to pass data.  What I don't understand though, is how to get the sub vi block to pass the notify wire to.  For example, in the following example they pass a wire to "User 1" "User 2" and "User 3".  I have sub vi in my main vi, and I inserted a boolean notifier in the sub vi, however there is no spot on the sub vi's block in the main vi to connect the notify wire to.  Is there something obvious I am doing wrong, or should I post screen shots of the sub vi and main vi?

 

Thanks,

Eric

 

0 Kudos
Message 3 of 9
(3,766 Views)

I don't quite understand. Did you create the notified control on the subVI and wire it to the connector pane?

0 Kudos
Message 4 of 9
(3,762 Views)

Eric,

 

Are you asking about creating Notifier Refnum controls and indicators?  You can pop up on the connecotr pane on the block diagram where you have the Obtain Notifier, Send Notification or Wait for Notification and select Create Control (Indicator).

 

Lynn

0 Kudos
Message 5 of 9
(3,756 Views)

Ok, I got something working, and I would just like your feedback about whether this is a good way to do it.  I was originally trying to using the notifier refnum because I had found an example using it.  However, I started using two notifiers, one at each end with the same name.  In order to propagate the stop value, I just put it in a while value and check its value at each iteration.  It it is true, I exit the loop and send a notification.  I also have a push button which works similarly.  Attached is a screenshot of my main vi and sub vi.

 

Thanks,

Eric

 

NOTE: uploading the files wouldn't work in ie9 on w7....

Download All
0 Kudos
Message 6 of 9
(3,726 Views)

Eric,

 

Your main VI has some timing problems.  The upper loop will run as fast as possible, generating millions of notifications per second.  The loop should have some knid of delay or wait to slow it down.  Also, it does not seem to make sense to send a False notification over and over.  Just send the True after the loop stops.  That is the only one which means anything. Similarly the lower loop needs a wait.  And it only needs to send a notification when the value of Run Freqeuncy Scan changes.  And it needs a way to stop.  Both loops could be combined into one loop with an event structure.

 

The subVI will wait 100 ms for a Run notification if none is available and will wait forever for a stop notification.  Of course since you are sending millions of each, you never notice any delays.  I am not sure if it is possible to miss the one stop notification after the millions of do not stop notifications.  It is also possible that the Release Notifer will execute before the Wait on Notification receives the Stop notification.  I think that if that happens, your subVI will never stop.

 

Lynn

0 Kudos
Message 7 of 9
(3,706 Views)

Hello,

 

Is this what you meant (see attached pics)?  Oh, btw I figured out my orginal problem, which was why the occilscope wouldn't display properly when I send commands to both the arb. waveform generator and occiliscope at the same time.  I originally figured the solution was to put them in subvis.  Turn's out I only need to delay the occiliscope 🙂  If there is a more elegant way to delay, please let me know.  Also, Labview gives meaning to writing tight code... Is there a shortcut to automaticlly route things better?

 

Thanks,

 

Eric

Download All
0 Kudos
Message 8 of 9
(3,656 Views)

Eric,

 

Last question first: I do not know of a better autorouting.  I just turn off auto wire routing and try to do a bit of planning before dropping things on the diagram.

 

You are using the for loop to do the delay? It is difficult to tell exactly what is going on in your images.  All the subVIs have the same icon, so I cannot tell which is which!  That is a rather inelegant way to produce a 1 second delay.  Just wire 1000 to the Wait and run the oscilloscope after the delay. No loop.

 

In sub_vi2 you do not need both the Wait and the notifer timeout.  If the stop notification occurs, you really do not want to wait for the delay to finish. (At 10 ms it is not a big deal, but if the wait was 30 seconds it could be).  If the stop notification was not received, the loop will iterate after the timeout.

 

Lynn

0 Kudos
Message 9 of 9
(3,639 Views)