Willem-Jan Vreeling wrote in message
news:3A1B8D97.695C9C50@sron.rug.nl...
> In an application for measuring the resistance of several samples, I
> have problems reading the data out of a For Loop. The samples are heated
> up and after each temperature step, the resistances are measured. So in
> each step of the loop I increase the temperature and read out the
> resistances. At the end I get an array of the data.
>
> However, it would be better if I could also follow the measurement
> realtime. So I put the digital indicator in the same for loop. This
> seemed to work. The problem arised when I used this VI as SubVI in the
> main program. Now I can only read the complete array at the end of
> measurement.
> How can I solve this problem and read out the data realtime in the main
> program?
First consider not using the for loop in the sub-VI, but instead have the
subVI go to a single temperature, passed to it as an argument, and return a
single set of resistance values. This is far simpler to handle and to debug.
If you MUST have a sub-VI that is called and then runs the entire
experiment, periodically reporting back to the calling VI, there are three
common ways in which the communication can take place. In order of personal
preference,
1) Queues. The calling VI creates a queue, the reference of which is passed
to the sub-VI (or the sub-VI simply opens the reference itself each time
it's needed). The sub-VI puts the data in the queue as it is ready, and the
calling VI periodically polls the queue to retrieve any pending data.
2) VI server. The sub-VI can open a reference to controls on the front panel
of the calling VI and can itself directly read and write these
controls/indicators. This can become difficult to debug because there is no
way you can start at the control and trace wires back to see where the data
is coming from, for debugging purposes.
3) Globals. The subVI writes the data to a global variable, and sets a
global Boolean "true" to indicate the presence of data. The calling VI
checks the Boolean at a faster rate than the data can arrive, if the Boolean
is true it reads the data from the global and sets the Boolean back to
false. This is the "old" way but is pretty crap in comparison to the queue
method.
In cases 1 and 3 you must make sure the calling VI continues to run while
the sub-VI is running. This means putting the call to the sub-VI in an
independent loop from the main program code, and some thought should be
given to interloop communication. Remember that if you have a sub-VI call
within a structure- a loop, sequence etc- that structure will not complete
until all sub-VI calls within it have completed.