LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shift Registers and Boolean ctrls

So I went here: http://www.ni.com/white-paper/7585/en/

and followed the instructions.

 

It looks right, but the globals still don't seem to work.  When I press the "Freeze!" button in 'Stop Button Overlay.vi' the array in the subvi just keeps on updating...

The example given is for two 'while loops' that are running parallel, while mine is a single while loop nested inside another .vi, but I didn't think that would make a difference.

0 Kudos
Message 21 of 30
(971 Views)

Your Freeze! button is only read once in your main VI.  Once it is read, it is never read again even if you change the button.

 

You have a race condition also that you don't know whether the state of the freeze button is read and written to the global variable first or second relative to the start of your subVI.

 

In your subVI, once the global boolean is read, it is not read again until the stop global inside the inner while loop is read to be True and stops that loop.  Again, the Stop global will never change because the unnamed boolean terminal in the main VI (why didn't you show the label on that control in the mainVI's block diagram?) has already been read and written to the stop global.

 

You have basic dataflow problems you are fighting here.  I'm kind of surprised because you've been on the forums a while.  I would've figured you would have been beyond these beginner level problems and misunderstandings for LabVIEW.  I'd suggest looking at the tutorials again.

LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 22 of 30
(956 Views)

My first guess was that my problem is how often LabVIEW reads the values of my 2 buttons, Freeze! and Stop, so I made a 3rd .vi and put them in a while loop so it would constantly check the values, to no avail.

0 Kudos
Message 23 of 30
(954 Views)

"In your subVI, once the global boolean is read, it is not read again until the stop global inside the inner while loop is read to be True and stops that loop."

 

I would have thought it would have read the state of the global boolean every time the for loop repeats itself?

0 Kudos
Message 24 of 30
(953 Views)

...that was not a rhetorical question, btw.   If my sub.vi is not reading the state of the boolean global each time the for loop repeats itself, that is clearly the problem I am running into.

0 Kudos
Message 25 of 30
(933 Views)

Hi Lars,

 

as was explained to you the problem is not with the reading but with writing the global variable...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 26 of 30
(925 Views)

Cleaned up version, uses a while loop so the main controls should be polled continuously (attached) but still doesn't work.

 

I don't entirely like this direction, because now it is 2 independent programs rather than one single program, but it is a workable solution if it solves the problem of writing data to the global variable.  It sounded like (from RavensFan) that I also have a problem when the variable is read in (what was) the sub.vi.

0 Kudos
Message 27 of 30
(920 Views)

oh hey, now it works...

0 Kudos
Message 28 of 30
(910 Views)

@LarsUlrich wrote:

  It sounded like (from RavensFan) that I also have a problem when the variable is read in (what was) the sub.vi.



No.  The original problem was when the control terminal was read in the main VI and that value written to the global variable in the main VI.  It only happened one time, and was even a race condition as to when that reading and writing occurred relative to the start of the SubVI.

 

The subVI was reading the global variables okay, but the global variables were never getting any new information because the terminal reading/global writing process never happened again in the main VI to update the values in the global variable.

 

Now that you have a while loop around the terminal/global read/write in the main VI, the globals will be updated.

 

You don't necessarily need to have "two" programs.  You can still make your second program a subVI within the main.  You just need to have it run in parallel to your new while loop.  Just drop the subVI outside the main while loop.  Now the main VI will start the subVI.  Note you could still have a race condition between when the subVI starts vs. when the first iteration of the while loop occurrs.  You may want to add an initialization frame in order to reset the global variables to a default state before the while loop and the subVI start.

Message 29 of 30
(895 Views)

"Note you could still have a race condition between when the subVI starts vs. when the first iteration of the while loop occurrs."

 

Yeah, that is the problem I was worried about if I tried to make it a sub.vi.  Either the sub.vi wouldn't run until I had already exausted the while loop, or the while loop wouldn't run until the sub.vi had already ran and finished the counter.

 

Thanks for all your help!

0 Kudos
Message 30 of 30
(888 Views)