LabView Drukuj
Wpisany przez Krzysztof Dobek   
wtorek, 30 sierpnia 2016 08:38

Arrays in Formula Node may store local values during subsequent executions.


Recently, I found a LabView feature that looks like a bug, which however can be used by an aware of it programmer. Take a look at the diagram shown below:


There are two While loops with Formula nodes within. Both loops are stopped by the same Stop button set to "Swith When Released" mechanical action. Within Formula nodes there are two variables, "z" whose value is always given outside of the Formula node, and "y" which is a single element array. The only difference between both While loops is that in the one on the right side "y" array is declared as an output of the Formula node. Execution of the code increments the "z" indicator value, while set "z 2" indicator value to 1. It means the "y" array acts as a Shift Register, unless you "reinitialize" it to 0 at each loop iteration only by declaring it as an output! It turned out that stopping the VI and starting it again does not reinitializes "y" array in the loop on the left side. However, if you change anything within the Formula node code the variable will be set to 0. Obviously, closing the VI and loading again reintializes tha variable as well.


How to create a VI that accumulates values passed to it

LabView offers many VIs that accumulate single values in an array and perform calculations on these accumulated values (see XXX PtByPt VIs). A simple way to achieve such functionality of a VI (subVI in fact) is to use single iteration loops with a non-initialized shift register as shown below. To make the example below fully functional you have to pass as connectors of the VI the RESET boolean control, the New Value control and as output connector the result of the calculation. The RESET control is used to clear the array (buffer).


When a latch button supposed to return to false value reacts as a switch button (LabView 2012)

Depending on the position of the button control in your code, it can act as a button of latch or switch type. Even if set previously as a latch one.

The code on the top will make OK Button of switch type, whatever you set in the editor. The code below will work as you expect.

Poprawiony: poniedziałek, 16 lipca 2018 19:23