LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic shared variable node

Hello, i'd like something like a Shared Variable Node, but with ability to choose at runtime which variable to read/write, for example passing a variable name. Is it possible?
I have the DSC module and it supports "Shared Variable Costant", which can be passed to a Property Node and allows to dinamically access a SV's properties, but apparently not its value and error status.
I tried to retrieve the DataSocketURL property and pass it to "Datasocket Read"; it kinda works, but i'm not sure if it's equivalent to a SV Node... it's slower and error status is not easily detected. May it be the right way?
0 Kudos
Message 1 of 8
(5,386 Views)

Greetings and Merry Christmas,

 

I guess I’m a little confused about your application. An idea for choosing a variable to read/write from your front panel would be with a state diagram. This could be placed in a stacked sequence to occur first. Is that what you are trying to accomplish? Would you please elaborate on your application as well as what you mean about “choosing a variable”

 

For the Shared Variable Constant, I’m not sure why you would want to pass the value or error status when you could just deploy the shared variable?

 

Let me know of any head way and good luck!
Jordan Randall
National Instruments Italy
0 Kudos
Message 2 of 8
(5,341 Views)

Sorry for late reply, i've been on holiday.

My current apllication is a typical DSC with data binding and Fieldpoint. There isn't a particular problem i need to solve, but a "dynamic SV" would be generally useful and make some code more clean.

By "choose" i mean select, wiith an input wire in the block diagram, which variable a r/w node refers to. It's got nothing to do with front panel and user's choices.

For example, suppose i wish to  turn on 30 boolean variables. Normally i need to place 30 variable nodes!! A For loop with a dynamic node and an array of variable names would be much better.

Other example: i have a complex r/w operation which may be done on SV a, or SV b, or SV c... depending on a Case. Normally i need to duplicate the whole operation for each case; or to put in a Case every variable.node. It would be much better to pass just the name of the variable as an input!

Note: i can't use arrays because binding a SV of type "array" to multiple Fielpoint channels isn't possible.

0 Kudos
Message 3 of 8
(5,254 Views)
I think a solution is (was) accessing variables with Datasocket blocks and a psp:\\... url. The url is a string and can be easily changed at runtime. Right?
0 Kudos
Message 4 of 8
(4,298 Views)
Right. Below there is an excerpt from http://zone.ni.com/devzone/cda/tut/p/id/4679.
Buon lavoro!

Use the Datasocket API in applications where you need change dynamically the shared variable that a VI reads and writes. You can change a shared variable dynamically by building the URL of the Datasocket connection programmatically. You also can control other shared variable features, such as buffer size, programmatically. Additionally, the Datasocket API has a blocking read that returns only when the shared variable updates.

Figure 14. Using the DataSocket API to Programmatically Read and Write Shared Variables



Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 8
(4,295 Views)
Grazie (ormai avevo risolto piazzando miliardi di nodi SV, ma sarà utile la prossima volta Smiley Happy)
0 Kudos
Message 6 of 8
(4,290 Views)

Hi pincpanter,

The link you had attached is getting failed now.

Can you please give the correct link again ?

I m in need of it now, thats why I m replyng to this a-bit old post when I got it while searching...

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 7 of 8
(3,856 Views)
Hi Partha, the link fails simply because I inserted it the wrong way Smiley Wink
Here is a valid link: http://zone.ni.com/devzone/cda/tut/p/id/4679
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 8 of 8
(3,853 Views)