07-24-2014 10:38 AM - edited 07-24-2014 10:39 AM
@cli21 wrote:
How to connect the two PGV?I attached my idea but definitely it's wrong.
You missed the point of how to make a FGV. A FGV is supposed to be its own VI that has uninitialized shift registers. Action Engine <- Nugget every LabVIEW developer should read
Though, the way you will be using it here, you might as well just use a global variable.
07-24-2014 12:31 PM
Hi,
I tried global variable. It works, but I still want to figure out what's the problem with FGV, do you mean I should save the uninitialized shift register as a individual VI, and call out it at different place?
Thanks,
CJ
07-24-2014 12:36 PM
cli21 wrote:do you mean I should save the uninitialized shift register as a individual VI, and call out it at different place?
That's how a FGV works. You have a non-reentrant VI that has an uninitialized shift register. By calling it in one place, you can set the value. By calling the same VI in another place, you can get the value that was set by the other thread. But if all you are doing is the Get/Set, just use the global. It is more efficient and does the exact same thing.
Now if you go into that Action Engine nugget, you will see some true power of the unitialized shift register.
07-24-2014 01:46 PM
Hi,
I tried package the PGV as a sub VI, but it doesn't work, "write" is OK, but the read data always be 0, would you please tell me the reason?
Thanks,
CJ
07-24-2014 01:55 PM - edited 07-24-2014 01:56 PM
You are just outputting the data you wrote to the shift register when you are trying to read. Default value of your control is 0, so you got a 0.
Add a boolean input for "Write?" When that Boolean is TRUE, you write to the shift register. When it is false, you keep that value that was previously in the shift register.
07-24-2014 02:08 PM
Yes, adding a boolean is going to work, but then I have to manually define the boolean to be true or fulse, that's different from what I expected. I hope the program will automatically read the data from the array and transfer to the setpoint, just like what a global variable does.
Also, I am still confused about the data flow, shouldn't the data coming from the array first flow to the register and then flow to setpoint?If it is, why the default value is read?
Thanks,
CJ
07-24-2014 04:09 PM
The two loops truely act in parallel. So there should be nothing connecting the two loops. So with that, you have to pass data from one loop to another via some construct. So what happens with a FGV is that only one place can run the VI at a time. So when your Write calls the VI, you need to set the data point. When the Read calls the VI, you need to get the data that is put in there. So what happens when the Write calls the VI and is running it when the Reader suddenly wants to call it? Since the VI is non-reentrant, the Reader must sit there and wait for the Writer to be done with it.
The reason you had the default value on your reader is because you didn't supply a value for an input. So what does a VI do when a non-required input is not supplied? It uses the default value for that data type. For a numeric, it is 0.
I highly recommend you try running your code with Highlight Execution turned on. It slows your code down A LOT, but it shows you how the flow of data works.