LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems: Threading (Data acquisition)

Hello!

I am new to labview and I am currently working on my first project using
labview.

I am trying to start data acquisition using some external libraries (dll)
and display the data.

My project looks like this:

One big while loop with one button for ending the program
Within this while loop I have two main tasks:

1. Data acquistions in a Sub-Vi, using calls to a DLL Library (ADS DLL from
Beckhoff Industry electronics to access profibus devices). The Sub-Vi writes
the data to a hidden display element (cluster).
2. Display of this data. A button is associated with a Sub-Vi whichs pops up
a new dialog. The Display SubVi is connected to the display element
(cluster).

The current status is, that after one cycle of
data acquisition (about 2
seconds). data is updated in the display.

I am also able to take a deeper look into the data by pressing the button,
which then pops up a dialog and displays a more specific view of the data.

Now my two main problems:

1. After pressing the button for the pop-up dialog it takes up to two
seconds before the dialog pops up (this is no wonder, because the Sub-Vi for
Data acquisition must have finished before)
2. In the dialog I see the data, which was taken before the dialog popped
up. When I am looking at the dialog no data ist updated (this is also clear,
because the only Vi which is executed is the Sub Vi of my dialog)

I thought about threading and I read the labview manuals, but I was not able
to get the Sub Vi of data acquisition working while I am in the display
dialog.
Threading is enabled for labview and I tried different approaches to make
the Data acquisition Sub-Vi working independent of the whole other
structure. (sub-vi set to data acquisitons, .
..)

Can somebody help me?

--
Torge Szczepanek
0 Kudos
Message 1 of 7
(2,927 Views)
> Threading is enabled for labview and I tried different approaches to make
> the Data acquisition Sub-Vi working independent of the whole other
> structure. (sub-vi set to data acquisitons, ...)
>
> Can somebody help me?

You misunderstand the purpose of the "threading" settings- they only concern
what happens within the guts of Labview's general housekeeping like keeping
the display updated etc.

If you want "threading-like" behaviour within your code you have to do it
yourself. Labview is data-driven, so the program flow is governed solely by
when data arrives at different nodes.

There are lots of ways this can be done; I'm outlining only one example,
which I think is easiest to explain even if it's not necessarily the most
efficient or elegant.

You need to abs
tract your code into two independent VIs. Use queues to
transfer the data between the two. One VI reads the data and writes it both
to a file and to the queue; the other VI reads the queue and adds the new
data to the display. Some thought is needed about how to store the data- if
you simply keep using "build array" to add each new datapoint to the buffer
then you rapidly start to suffer performance degradation and the machine
will grind to a halt.

In your DAQ vi, which is the "controller" of the system, you have a loop
running independently of the data-taking loop. Make sure you have a delay in
it! The second loop simply checks the state of a front panel Boolean; if it
changes from false to true, you use the VI server to open the panel of your
display VI. If it changes from true to false, you use the VI server to close
the panel of the display VI. Note that the display VI is running
continuously, so if you want to selectively show and hide it to save CPU
power then you need to modify
this approach.
0 Kudos
Message 2 of 7
(2,927 Views)
Hi Torge,

Torge Szczepanek wrote:

> One big while loop with one button for ending the program
> Within this while loop I have two main tasks:
>
> 1. Data acquistions in a Sub-Vi, using calls to a DLL Library (ADS DLL from
> Beckhoff Industry electronics to access profibus devices). The Sub-Vi writes
> the data to a hidden display element (cluster).
> 2. Display of this data. A button is associated with a Sub-Vi whichs pops up
> a new dialog. The Display SubVi is connected to the display element
> (cluster).

As to 2 of above, do you connect a logical signal from a button
to a case structure involving a sub-Vi to pop up a new dialog ?
Only to make sure, not offense meaning.


> The current status is, that after one cycle of data acquisition (about 2
> seconds). data is updated in the display.
>
> I am also able to take a deeper look into the data by pressing the button,
> which then pops up a dialog and displays a more specific view of the data.
>
> Now my two main problems:
>
> 1. After pressing the button for the pop-up dialog it takes up to two
> seconds before the dialog pops up (this is no wonder, because the Sub-Vi for
> Data acquisition must have finished before)
> 2. In the dialog I see the data, which was taken before the dialog popped
> up. When I am looking at the dialog no data ist updated (this is also clear,
> because the only Vi which is executed is the Sub Vi of my dialog)

I think of a simple way using attribute node instead of
subVi to pop up. Please take copies of the cluster on the
display subVi and parts of data processing on the diagram,
then paste on the main Vi's front panel and diagram.
In the diagram, if right click on the pasted cluster value,
you will be able to look at attribute node, involving variable
attributions of the value. And then, please select a mode
of "Visible" and connect the logical signal from the button.
Please do as same for the display data on the main Vi with
only one difference that the connected logical signal is
contradicted.

You will look at a more specific data instead of a main
data by pushing a button. If you would like to look at
both simultaneously, such a simple way will be mean less(-;)
Hopefully, my description might be a referential knowledge,
any way.

Thanks,
Tom
0 Kudos
Message 4 of 7
(2,927 Views)
"Tomoya Ito" schrieb im Newsbeitrag
news:39E4AEC3.D4D678AB@rd.fujitec.co.jp...

> As to 2 of above, do you connect a logical signal from a button
> to a case structure involving a sub-Vi to pop up a new dialog ?
> Only to make sure, not offense meaning.

Yes. Thats what I am doing.

> I think of a simple way using attribute node instead of
> subVi to pop up. Please take copies of the cluster on the

I need a Sub-Vi and a new window, because I do not have enough space on my
Screen. I like to add more than one data source and much more display to my
vi.

My big problem is that I need to start data acquisition, while the rest of
the programs runs without waiting for the data acquisition to finish. I need
to spawn a seperate thread for
data acquisition.

--
Torge Szczepanek torge@szczepanek.de http://www.szczepanek.de/
0 Kudos
Message 3 of 7
(2,927 Views)
> > As to 2 of above, do you connect a logical signal from a button
> > to a case structure involving a sub-Vi to pop up a new dialog ?
> > Only to make sure, not offense meaning.
>
> Yes. Thats what I am doing.
>
> > I think of a simple way using attribute node instead of
> > subVi to pop up. Please take copies of the cluster on the
>
> I need a Sub-Vi and a new window, because I do not have enough space on my
> Screen. I like to add more than one data source and much more display to my
> vi.
>
> My big problem is that I need to start data acquisition, while the rest of
> the programs runs without waiting for the data acquisition to finish. I need
> to spawn a seperate thread for data acquisition.
>


You really don't need to think in terms of threads to use LV. If you
have parallel loops, they can execute in parallel. Of course this is
influenced by how LV uses the underlying OS resources, which is where a
little thread knowledge comes in handy.

The first thing to recognize is that a LV loop doesn't continue until
all of the nodes in it have completed. This means that things like
calling a subVI that doesn't return until its window is closed will keep
the calling loop from doing another iteration. The ways to avoid this
are to use a parallel loop and have them communicate through local or
global variables, or you can use the VI Server to launch a parallel VI
and again communicate to it through globals.

The threads knowledge may come in handy when dealing with things like
DLLs that cannot share a single thread while carrying out their
execution. To get around this, it is possible for any LV execution
system to have more than one thread executing on its behalf. There are
VIs in the Utility section of vi.lib, sysinfo, threadConfig.vi. This
will allow for increasing the number of threads so that parallel loops
within one execution system run in parallel threads and the OS will
multitask between them. The subVI called form the VI Server can do this
more easily since it is a simple VI Property that controls which
execution system that it runs in. Each execution system runs in a
different thread; so the subVI and VI will run in different threads.

Greg McKaskle
0 Kudos
Message 5 of 7
(2,927 Views)
"Greg McKaskle" schrieb im Newsbeitrag
news:39E530BC.A1C7FA0E@austin.rr.com...

> You really don't need to think in terms of threads to use LV. If you
> have parallel loops, they can execute in parallel. Of course this is
> influenced by how LV uses the underlying OS resources, which is where a
> little thread knowledge comes in handy.

Thank you! Now it is working fine.

--
Torge Szczepanek torge@szczepanek.de http://www.szczepanek.de/
0 Kudos
Message 7 of 7
(2,927 Views)
Torge Szczepanek wrote:

> Yes. Thats what I am doing.

One more question, excuse me.
Is a data associated with a sub-Vi separated from a main
data wire in a while loop ? If the sub-Vi is involved in
a while loop in which data acquisition is done, the display
data on front panel of sub-Vi will be possibly updated.


> I need a Sub-Vi and a new window, because I do not have enough space on my
> Screen. I like to add more than one data source and much more display to my
> vi.

You will be able to change data displayed on the window
with attribute node, which can determine whether each data
are visible or invisible. Enough space is not necessary every
when displayed data are changed.


> My big problem is that I need to start data acquisition, while the
rest of
> the programs runs without waiting for the data acquisition to finish. I need
> to spawn a seperate thread for data acquisition.

This point would be the most important, as you mentioned
above. Is another data acquisition needed to get more
specific data ?

Detailed notes:
1. You said it takes up to 2 seconds per 1 loop. If you
need to get data which is got from an acquisition
device intermediately, it would be better for you to
mainly set a data acquisition loop for specific data
and choose out of those at every time for the main
panel display. Data acquisition span may be freely
selected, so you can give span time by pushing button
using case structure.
2. If you really need to spawn a separate thread, it will
be needed to add a new device for specific data and
to set a new data acquisition procedure in the same
while loop.

I hope at least one of descriptions above will make effect
on your work.

Tom
--ito@rd.fujitec.co.jp
0 Kudos
Message 6 of 7
(2,927 Views)