LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global and/or shared variable help

Okay so this is what I'm trying to do... I have a VI that reads some data from a microprocessor.  I need this data later on during my testing.  It's just a simple string value.  So I read the data, put it in a global variable, and access it from my other VI that needs this value.  Well this works perfectly in the development environment but once I create an executable it no longer works.   I don't understand how the global variable is "loossing" its data.  The process doesn't enable the user to read the global before setting it.  I tried to do this with a shared variable instead but it also yields the same behaviour.  I'm thinking my problem has to do with the way the global gets loaded but I used globals before without any problem.  The only difference is that everytine I used them before it has been with static data read from a file not dynamic data obtain from a device like I'm trying to do now.  I guess I can create a VI "holder" to just hold the value I want to save and call that VI to return the value when I needed.  I just thought using a variable would be easier since it's only a simple string that I want to capture.  Any thoughts....?

 

0 Kudos
Message 1 of 7
(2,759 Views)
Okay so I just tried using a separate VI to hold the data but that doesn't work either.  I guess my problem has to do with what gets loaded into Memory at what time.  See my application spawns the different test modules (VIs) by opening a referece with their name so they run on a separate thread than the main application.  So my problem is that I call by name the VI that sets the global/shared variable and then I call by name the VI that reads that variable.  Unless I have the VI that set the variable open I can't read it.  Please help!
0 Kudos
Message 2 of 7
(2,755 Views)

Hi nelg87,

 

I tried to re-create your issue by putting together the attached project with a read and a write string VI communicating through a single process shared variable. I was able to successfully communicate in the executable that I built. Please try to use this project to re-create the issue on your machine. Thanks!

 

Cheers,

 

Jonah

Applications Engineer

National Instruments

Jonah Paul
Marketing Manager, NI Software
Message 3 of 7
(2,714 Views)

Thanks for the reply JPaul.  See the thing is that my main program acts like a test manager and the VI's that I'm calling are the individual automated tests that I run so I call them by opening a reference with the VI name.  One of my test vi sets the variable another one reads it, but this happends at different times during the execution.  I knew my problem had to do with the correct VIs not being loaded at the right time.  I found a solution by placing a static reference to the variable on the VI that reads it.  The static reference is not really doing anything it's just there to load the variable back into memory.  This seems to work every time.  I attached the project you send with an additional Main.vi that calls the write and read vi programatically by reference like I'm doing in my application.  And with the changes I made to make it work.  Take a look at it and let me know if there is a more efficient or proper way to do this.

 

Thanks

0 Kudos
Message 4 of 7
(2,694 Views)

Hi nelg87,

 

To quickly make sure that I understand what you want to do, are you trying to ensure (in the case that you sent me) that the write_str.vi is successful in writing the variable before you call the read_str.vi (in which you read the variable back)? The shared variable should keep its value even if the write_str or read_str is not running. You can verify this by running the Tools >> Shared Variables >> Variable Manager and observing the current value of the shared variable thorughout the process.

 

Cheers,

 

Jonah
Applications Engineer

National Instruments

Jonah Paul
Marketing Manager, NI Software
Message 5 of 7
(2,669 Views)
I know the write_str.vi is writing the variable because I've watch the front panel prior to reading and the value is there.  However, it's the read_str.vi that doesnt' get the value unless I reload the variable by reading the static reference to it  If you put a diagram disable around the static reference on the Main.vi you will see what I'm talking about.  You'll see that the shared variable value cannot be read succesfully.
0 Kudos
Message 6 of 7
(2,652 Views)

Hi nelg87,

 

To follow up, I need a little more information about how you want your application to run. Would you like the write_str to run, then stop and then run read_str? In that case the write is not going to be able to update the shared variable since it is stopped. Or would you like to have the write_str start running first and then the read_str starts to run? If this is the case the Wait Until Done on the Run VI to programmatically open/run the write_str needs to be false.

 

Cheers,

 

Jonah
Applications Engineer

National Instruments

Jonah Paul
Marketing Manager, NI Software
Message 7 of 7
(2,618 Views)