LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with global variable!!

Hi!
I am using some cluster (global variable), and certain fields in the cluster don't be updated.I can't understand where is the problem, because some fields are updated correctly and others no!!

Any idea?

Thanks in advanced!!

Graci
0 Kudos
Message 1 of 5
(3,934 Views)
Without seeing your code it will be virtually impossible to see what is going on. Are you writing all of the elements in the cluster at the same point in your code? I suspect that you're not and that your problem is the result of a race condition. I would recommend that you replace the global variable with a Functional Global (also called a LV2 style global)and ensure that every time that you're changing an element in the cluster that you first read the current cluster from the functional global vi. There is considerable information on this website about the use of functional globals, which essentially are subvis with uninitialized shift registers.
0 Kudos
Message 2 of 5
(3,934 Views)
Thank you!!

It is true that I am writing in the same cluster in differents point in my code, but I am writing in differents fields or these clusters!!

I am trying the solution you have given me!

Thanks!

Graci
0 Kudos
Message 3 of 5
(3,934 Views)
Dear John,

I was reading the application note about multithreading ..., in which I have found information about functional global variable. I also saw an example in the NI Developer Zone, but I don´t understand it very well.
Is functional global a global variable or is it a way to avoid to subvis access the global variable at the same time? But if it is the second option, it would be similar to use a semaphore, wouldn´t it?
Can you explain me what is a functional variable? I don´t understand "that they are subvis with uninitialized shift registers".

Thank you in advanced!

Graci
0 Kudos
Message 4 of 5
(3,934 Views)
A functional global acts as a global variable in that it allows LV applications to access the data from different parts of the vi or from different vis for as long a LV is running. The vi is set to not be reentrant so that race conditions are avoided. Since functional globals are subvis that you write you also have the ability to store many global variables which are dependent upon only one input by performing the calculations within the functional global vi. You can certainly achieve this by using semaphores, but with functional globals this synchronization is built in.

In the functional global vi you have a while loop which is set to stop after 1 iteration. This while loop has a shift register which holds the global data. There is a cas
e structure to determine whether to read or write the functional global variable. In the write case the data from the input is written to the shift register on the right side. In the read case the data from the left shift register is written to the output and also passed on through to the right shift register. A good example can be found at the following link.

http://sine.ni.com/apps/we/niepd_web_display.DISPLAY_EPD4?p_guid=B45EACE3DB4956A4E034080020E74861&p_node=174821&p_submitted=N&p_rank=&p_answer=&p_source=External
Message 5 of 5
(3,934 Views)