LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Values not updated in array with For and Boolean structure

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.

 

Loop1.png

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 ! 

0 Kudos
Message 1 of 8
(1,193 Views)

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!)

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(1,190 Views)

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 👍

0 Kudos
Message 3 of 8
(1,166 Views)

@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.

0 Kudos
Message 4 of 8
(1,131 Views)

I replace value properties of 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)

0 Kudos
Message 5 of 8
(1,121 Views)

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.

 

  • Your loop needs some timing.
  • There is no way to tell if your iteration value property gets read before or after the indicator has been updated (glaring race condition!)
  • Your temperature inside the inner loop will not get new values unless you update it inside the loop.
  • 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.
  • etc.etc.etc.

 

Message 6 of 8
(1,117 Views)

Thanks for this example.

 

  • The different formula for A and C is a mistake, I mix two code to make this VI test.
  • 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 ?
  • I will find a way to update it in For structure then.

  • @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
    This is the kind of details that a newbie like me don't take care instinctively haha

 

I will make an update post when advices have been apply in my VI.

0 Kudos
Message 7 of 8
(1,067 Views)

@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.

 

 

altenbach_0-1599245109744.png

 

 

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.

Message 8 of 8
(1,063 Views)