09-03-2020 07:39 AM - edited 09-03-2020 07:46 AM
Hello everyone,
I have an issue with a part of my code in LabVIEW.
The purpose in my VI is to measure T values that allow to calculate variable A and C. (P.S:"Jumping values Stop" is just abutton to activate following code)
Before to show variables at the front panel, they go through the first condition: "C > 1000 ?"
- if it's false: values go directly to indicator.
- if it's true: values enter in a For structure.
The idea is to measure N times C and A and register ALL values in an array. In same time, my VI display "C=0" (false case) until we reach N-1. At this moment (true case), it display the last measured value*(1).
Then if "C is no more > 1000 ", the array with all values is transfert and it takes only latest value and it displayed*(2)+registered in file later.
(*I realize that I display twice the same value at different moment... is it a problem ?)
BUT it doesn't work, and I check with probe tool that my values are no more updated after the first condition: "C > 1000 ?"...
(That's why I cut wires at red square, I was thinking that creating a new calculation box IN For structure will uptdate my measurements but no way..)
My array show the same value whatever N is and it seems to be the first C > 1000 ... and I wanted updated values with a C < 1000 at the end of the array.
If somebody have any ideas, do not hesitate !
09-03-2020 07:43 AM
Hi Sa,
@Sa5m974 wrote:
If somebody have any ideas, do not hesitate !
Ideas:
Replace any "Value" property node visible in your image by wires to remove those race conditions!
Why do you use InsertIntoArray when you want to build an array? Use BuildArray!
For more/better help you should attach your code (aka VI) instead of showing just an image of a small part of your code.
(Usually you don't bring a picture of your car to the garage to get it repaired!)
09-03-2020 08:34 AM - edited 09-03-2020 08:36 AM
Thanks GerdW to take time to answer.
I heard what you said and I replace all replaceable node by wire and I InitAnArray instead of BuildArray to have dimension in-put parameter.
You can download my VI below (it's a version without any external driver required that was needed to measure T).
(P.S: you can put probes at different wire intersection of C to see what happen)
Good metaphor btw 👍
09-03-2020 10:20 AM
@Sa5m974 wrote:
I heard what you said and I replace all replaceable node by wire and I InitAnArray instead of BuildArray to have dimension in-put parameter.
No, you did not replace all replaceable nodes (none of your value properties are needed). Init.array was never suggested to be used this way (the suggestion was to replace "insert into array" with "built array"!). Have you tried execution highlighting? You need to start with some simple tutorials about dataflow.
09-03-2020 11:16 AM
I replace value properties of C by what else ? I don't understand. Can you show me ?
I replace by InitAnArray because when I used BuildArray I have only 1 element register instead of the other function that allow me to connect N.
But I may be use it very badly in this case..
I try highlighting and the problem is T value: why is it always the same during my N times calculation ?
Did I need to randomize again its value inside For structure in my "NI-VI_test" ?
That's means, in my final VI, I need to bring back all drivers and sub-VI inside For structure to get new value of T ?
(I will check dataflow tutorial)
09-03-2020 11:33 AM - edited 09-03-2020 11:37 AM
Here's is a quick suggestions how to potentially organize the code while honoring the rules of dataflow. It is not clear at all why your two formula nodes contain completely different definitions of A and C based on the inputs, but I left your code.
09-04-2020 02:39 AM - edited 09-04-2020 02:41 AM
Thanks for this example.
This is the kind of details that a newbie like me don't take care instinctively haha
@altenbach a écrit :
- There is absolutely no reason to maximize the diagram and front panel to the screen. You need to be able to look at the help while programming
I will make an update post when advices have been apply in my VI.
09-04-2020 01:49 PM
@Sa5m974 wrote:
- I didn't know for race condition. I read article and they purpose your method with time and another with semaphore. Which is the best in order to lost less acquisition time ?.
Typically you will use a wire to determine execution order. A wire as in the thick blue line below will naturally use the current i for the comparison. Similarly, the "Nbr of Acq" can also get it's value from a wire. Value property nodes are very rare in code from a skilled programmer.
A node (structure, subVI, function, etc) can only execute once all inputs have received data and will only produce an output once it has completed.