The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Shift Registers and Local Variables

SercoSteveB
Active Participant

The value in 'Numeric Value In' is 5.  What are the values of 'Numeric Value In' and 'Numeric Value Out' following execution of the VI?

Shift Register and local varables.bmp

a)      Numeric Value In=5, Numeric Value Out=12

b)      Numeric Value In=7, Numeric Value Out=11

c)      Numeric Value In=9, Numeric Value Out=10

d)      Numeric Value In=11, Numeric Value Out=12

Comments
mini09
Active Participant

the ans is D. when the loop runs first time the value 4 is initialized to the numeric value in read and the second loop process the value 11 is initialized by using shift register. then the value 12 passes out of the loop to numeric value out.

RustyStrings
Member

I agree the answer is D

One thing this demostrates is a dataflow issue

At one time I would have thought that when the Numeric Value In was change to 4 on the first iteration it looks like 4 would be passed in on the 2nd iteration

but dataflow  only allows the local variable to read once, if it changes afterwards it will not be read again until the next time the code is executed

the loop will use the value that was input the first time

(Just a note for anyone interested)

Knowing when your controls are being read is important

I once had a loop that did some I/O in a long chain of code there was a stop control in the loop

when running the code after the first vi in the chain was done I pressed the stop button, but the the loop went on to the next iteration

it soon occured to me that the stop button had already been read for this iteration and would have no effect until the next iteration

you need to tie the control in at the end of the chain using a sequence (error in error out connected) in order for it to be read after the chain is executed

SercoSteveB
Active Participant

Answer:D  Nice one gnshmrthy and RS.  As Rusty pointed out this question is primarily about data flow.  Remember to consider structures (loops, case structures, event structures etc.) the same as other BD elements in terms of data flow. 

Data Flow Programming - From NI.com

'A block diagram node or structure must have all input data available before the node or structure can execute,  on execution the values of the inputs are read (from the question; it is at this point the value of the Numeric Value In local is read, once).  When execution is complete; data is passed to the outputs.'

mini09
Active Participant

hw to make the program to go back to the initial values after running the program for once?

RustyStrings
Member

You can either select Edit.Reinitialize Values to Default (this will do all controls and indicators in the vi) you would have used the make default first for it to have the proper effect

or you can right click on individual controls and indicators and selcet the same thing (under Data Options)

srinath@elsys.in
Member

Ans is 

At first iteration

Numeric Value In=6, Numeric Value Out=10

secon iteration

Numeric Value In=11, Numeric Value Out=10

RAMESHB
Member

D

ashwinilele
Member

Ans is D

skian
Member

D