LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically write all shared variables to a .txt file?

Hello everyone,

      Long time lurker, first time poster. The forums have been a treasure trove of info. Especially for a mostly self taught Lavbiew programmer like myself. I am an Electrical Engineer, and not a "real" programmer, so occasionally some of the finer points get past me. 🙂

          So if you have a lot of shared variables >50, would there be a way to programatically write their values all into a .txt file? Something on the order of "Variable 1: XXXX, Variable 2: XXXX", etc? I have wired up each variable separetely and concatenated all of them together into the text file, and it works fine. However, over time, whenever I might add another shared variable, I now have to add another shared variable to the list that goes to the .txt file. I was wondering if their might be a more elegant and global way to basically save ALL of the shared variables into a text file. That way, no matter how many there are, I do not have to keep appending the list. Thanks....

0 Kudos
Message 1 of 5
(2,844 Views)

Hi,

 

You could use property nodes to read the shared variable names depolyed in the target PC, refer this link

 

https://decibel.ni.com/content/docs/DOC-22268

 

Once the variable names are read, then the same could be logged to text file.

 

Hope this helps.

0 Kudos
Message 2 of 5
(2,833 Views)

I would start here:

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/usingdynvarapi/

 

At the very bottom is shows an example for opening a reference to a variable container and then reading all the current values out of that container.  Once you have those values, you can easily write them to a file using other labview functions.  As far as an identifier for each variable goes, you can easily convert the variable name to a string, and create a label for each item that way as you write the file.

 

If you need to do all this very quickly or often,  you might look into pushing your file writing into a separate loop using a queue to pass it data.  

0 Kudos
Message 3 of 5
(2,802 Views)

I am only using single process shared variables. Is there a way to do this without the PSP-engine? Thanks....

 

 

0 Kudos
Message 4 of 5
(2,769 Views)

@Z4CRUZN wrote:

I am only using single process shared variables. Is there a way to do this without the PSP-engine? Thanks....

 

 


Unfortunately, unlike Network Shared Variables, there does not appear to be way to programatically access single process shared variables.  Maybe someone at NI can provide more info, but I could only find this in the "idea exchange" regarding single process variables and I couldn't find a way to get a reference to one.  

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Add-Programmatic-Access-for-Single-Process-Shared-Vari...

 

I guess without knowing your program and use case I'm not 100% sure what to suggest next.  Probably the easiest way to get what you want without having to change too much would be to change all your Single Process variables to Network Shared.  You could then use the example listed earlier.  If you use the Multiple Variable Tool Editor, you can quickly mark all the variables to network shared.  

 

There are other options but like I said it all depends on your use case.  A Single Process Shared Variable(SPSV), is essential global variable with metadata attached.  Are all your SPSVs the same data type?

 

One other thing you could consider doing is replacing all of your SPSVs with a single function global or multiple functional globals.  How to structure this FG also depends.  The most flexible way I've found is to make the data type a variant and use Variant Lookup Table to store information about each SPSV.  If you look through the forums you should be able to find info about Variant Lookup Tables.  Basically you use an empty variant and read/write its attributes to store information "within" the variant.  THis is a very very fast way to make a dictionary type structure in labview.  By wrapping the variant in a Functional Global you are preventing read/write race conditions.   

 

0 Kudos
Message 5 of 5
(2,750 Views)