LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get/set a shared variable programmatically?

Oh, I didn't know much about DataSockets.  Do they interoperate with Network Shared Variables?  I'm trying to update an existing, complex VI and didn't want to do any major rewrites and I'm not sure what impacts we'd have if I switched to sockets.

0 Kudos
Message 11 of 20
(1,885 Views)

Just to respond more specifically to your question:

Your original request:   "How do I write my VI so that it takes as an input references to the shared variables?  Can someone please give me an example?"

To clarify - your VI would have a text control "VariableReference" wired to the VI connector pane.

Some other VI would call your VI with the DataSocket reference string, such as "psp:\\localhost\Untitled Library 1\Numeric1".  You'd feed this into a DataSocket Open, then a DataSocket Read and a Close.  You'd do another DataSocket Open and then a write to the Boolean output version.  You can pass that output reference string into the VI as well, or just use some string manipulation to change "Numeric1" into "Boolean1" in the full URL.

I hope I have answered the question you intended!

Mike

0 Kudos
Message 12 of 20
(1,884 Views)

Yes, the DataSockets work across the network to a shared variable engine running on a different machine.

I think you will find this very easy to add to your existing VI.

Mike

0 Kudos
Message 13 of 20
(1,881 Views)
So you're saying that on one end I can use a DataSocket and on the other end, use a shared variable block like we've done before?


0 Kudos
Message 14 of 20
(1,879 Views)
"So you're saying that on one end I can use a DataSocket and on the other end, use a shared variable block like we've done before?"
 
I don't fully understand the architecture of the system you have, but here is my best guess...  You have a Windows XP machine running LabView connected to some sort of device.  On that pc you use some shared variables between different VIs, created by dragging a shared variable onto your block diagram from the "Programming>Structures" palette.  Then you right-clicked the the blank shared variable and selected "Select variable..." and navigated to the variable you wanted to access. 
 
The Shared Variable Engine is a separate process that is included with LabView, so this machine is your "shared variable server".
 
 
Now you want to process some data on a different computer on the network.  It needs to connect to the server, so I'm calling this computer the Client.  You have at least two ways to connect to those shared variables on your server computer.  One is, on the Client machine, to drag a shared variable block onto your block diagram from the "Programming->Structures" palette and then right-click it and navigate to the variable on the server that you want.  As long as the server computer is up and running you will be able to see the variables it is hosting and add them to your program.
 
The only reason you'd need to use datasockets to connect to variables on that server is if you don't already know the names of the variables ahead of time in which case you'd have to get the variable name to your client computer somehow.  That is what this whole thread has been about - how to do it the "slightly harder way" with with DataSockets - but I'll bet you don't even need that - I'll bet all you need is some more standard shared variables on your Client.  Try it on the client computer - drop a shared variable and right click it and "select variable" and see if you can see the variables you need on the Server.
 
Let me know if this helps or confuses.
Mike
0 Kudos
Message 15 of 20
(1,874 Views)
My understanding of what this thread has been about is that the user has many pairs of shared variables, and he wants a generic VI that will operate on a pair. This VI can be called one time with one pair, and another time with another pair. The VI doesn't know what the variable names are, or even care. Initially the user said they weren't using Datasockets (for whatever reason), and was trying to get references to a shared variable in the same way as you get references to "regular" controls/indicators. At least, that was my understanding. However, as is often the case in these forums, what people initially ask for turns out to be different from what they actually want.
0 Kudos
Message 16 of 20
(1,851 Views)
OK, let me be more specific about my problem.  I've inherited a host-target system with the host VI on a Windows machine and the target VI on a RT PXI, and I'm tasked with getting this this to work because the original author is on extended leave.  The host is the GUI and the target does the work and data logging.  I've attached a snapshot of a portion of the target VI.  The first thing I want to do is simplify the thing because I think it will be much easier to work on and fix if it's simpler.  As you can see, the conditional boxes are nearly identical.  Each only does something if the "trigger" condition is true.  It sets a NI-DAQmx digital output channel to true or false, sets an indicator to the same boolean value (so the GUI can see the command was sent), and adds an event entry line to a log file.  (This example of course is only writing to a SV but I have other cases where I need to do both.  But I thought this would be a simple enough example to share.)  I'd like to create a single VI that is instantiated 4 times (in this case).  I can feed in the boolean state to be used on trigger and the event log string.  But I'm trying to get the SV reference into the VI.  Since this is on the target, I can't use the indicator reference bound to a SV because the indicator is on the host.  But what about this: can I create a control for the target even though there is no GUI when it's deployed?  Then I could use the data binding trick with a reference.  Or would a data socket be more appropriate?

Thanks,
Keith.

0 Kudos
Message 17 of 20
(1,842 Views)
I prefer to post a pic but since my present PC only has version 7.1 (no SV) here goes my suggestion.
 
Use the "Open Application Reference" in th Application Control pallette. Wire a text const using the IP address of the target machine. Wire a "Invoke method" you can get a list of Datasockets. If this is preferred wire a "Open VI reference" wire then wire a property node to the "Open VI reference". You must wire the name of the VI on the target machine to get its properties (else the default is the current VI). find the reference to the control your interested in passing.
 
Again I was able to programmatically use SV (i.e create destroy bind) programmatically its all in the examples of LV 8 SV. This way a reference is not needed the binding takes care of this...off the top of my head. One glitch I missed on th fine print when creating SV programmatically is that one property ("enable change" paraphrasing here) allows all the SV properties to go into effect.... see the example
0 Kudos
Message 18 of 20
(1,826 Views)

It now looks to me like you simply need a "good old-fashioned shared variable".  One that is statically defined - defined while you are editing your program.  I don't think you need to "programmatically reference shared variables" - that is dynamic variable binding and not something you would use if you don't need it.  I think the use of the word "programmatically" threw us off.

I think what you want to do is exactly what NI intended.  Read this document several times - it takes a while to soak in and figure out which parts are relevent and which are not, but still it gets the point across:  http://zone.ni.com/devzone/cda/tut/p/id/4679

 

As a shortcut, try this:  open a new project.  Right-click on the top-most item in the project explorer - the "Project:" node.  Right click it and select "NEW->Targets and Devices".  You should find your RT system.  After adding it it should appear after the "My Computer" node in the project explorer.  Then right-click the RT system node and select "NEW->Library".  Then right-click the library and select "create bound variables".  You should be able to navigate to the variables available on the RT system.

Caveat:  These details may not be exactly right, but at least it should help you become more familiar with all the different ins and outs of the shared variable system.  Let me know if this helps or hinders.

Mike

0 Kudos
Message 19 of 20
(1,824 Views)
One last detail...   
 
Look at figures 2, and then 10, in this document, and hopefully you will have a "connect the dots" moment...
 
Mike
0 Kudos
Message 20 of 20
(1,818 Views)