LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a new Shared Variable programmatically to an existing and deployed library?

Hi there!

 

I am trying to accomplish this on both LabVIEW 8.6 and LabVIEW 2010 and seems like it's not any different in this situation.

 

My case: A project has a library with 4 Shared Variables (SVs). The library and the variables are deployed (visible in Distributed System Manager 8.6/2010). I want to add 2 more variables into this library. It is possible to do this manually from Project Explorer window's options menu. But while running an application it has to be done programmatically. Can I provide the library reference to the one currently existing without creating a new one?

"Create Or Add Library To Project" function in the Datalogging and Supervisory Control (DSC) toolkit does not help in this case. That function, as the name suggests, just tries to create a new library in the project.

 

Two possible methods:

 

The function "Add Shared Variable To Library" (DSC>EngineControl>Libraries & Processes) needs a library reference, which could be provided via "CreateOrAddLibraryToProject" function, but this function tries to create a new library, and if I provide the path of the existing library it throws an exception that the library already exists in the project (yes, as I wrote above, I need to add new variables to an existing and deployed library).

 

OR

 

The function "Create Shared Variable" (DSC>EngineControl>Variables & I/O Servers) will add Shared Variable in a process, and not physically in a library file, and the problem (limitation) with this approach is that it doesn't allow to add complex data type Shared Variables (for example in LabVIEW 8.6 it has only 4 datatype options in input parameter, and even in LV2010 it does not have "Image" datatype that I need).

 

The scond method is my preferred method as it allows to work on Online Shared Variables and doesn't create them physically in libraries (and this is good as the variables' scope remains only till the Variable Engine is running). But it doesn't support advanced data types, and the first method is powerful in terms that it supports to virtually any datatype, it just seems tricky to get that reference to the library.

 

 

Any tips?

 

Thanks ahead!

Vaibhav
0 Kudos
Message 1 of 6
(3,213 Views)

It is possible to add variables to an existing SVE process by using the MeasurementStudios NetworkVariable library, but this means programming with MS VisualStudio instead of LabVIEW.

I haven't tried to use the NetworkVariable assembly within LabVIEW. This could be a kind of recursive use.

 

Best regards

Christian

0 Kudos
Message 2 of 6
(3,194 Views)

I suppose you could use the variant data type for images or convert the images to arrays.  Also if you can use template libraries that were created offline, you could programatically deploy them over existing libraries and then modify variable properties to some extend.  In general, I think you will have more flexibility if you are willing to reconstruct the library on the file system and the programatically deploy.

Message 3 of 6
(3,183 Views)

Thank you for your comments.

 

@ Christian

 

Where do I find that library? Inside Measurement I/O I don't see any name similar to Network Variable. Can you please tell me a bit more specifically.

 

 

@ sachsm

 

Yes, I have used the variant data type for now, and will check the effect when I could run the system (right now trying to fix another issue to be able to run this test).

Yes, I also believed on that methodology and yes, after posting the above message, I continued to do it that way - creating offline libraries on the file system and then programmatically deploy them. 

My question was, how do I find the reference to library (without creating a new one) and then after searching the Application properties, I could finally find one node.

 

I will publish the code in my next post from another computer. 

 

Nevertheless, if there is any better way, I will appreciate feedbacks. 

 

Thanks again!

Vaibhav
0 Kudos
Message 4 of 6
(3,172 Views)

To get a reference of library while adding to the project.   <<<<>>>>    Getting reference to an existing library (on disk and in project) without creating a new library.

 

As the above two images show, while a library does not exist, it is easy to use the "CreateOrAddLibraryToProject.vi" which will add a new library to the project (if it doesn't exist on file system, a new library will be created) and that way, using the reference (the green wire going out from the function and the Case Structure, can be used to add Shared Variables to the library. The problem was what to do when a library already exists in the project, how to add more variables to it. I was looking for a way to get a library reference, and somehow I could not see it inside a Project's property (VI Server functions). Hence I posted the question. And upon continuing my search, I found it on the Application's property list.

 

I hope it was useful for someone else as well. And thanks for the replies. Please share a better idea if you have.

Vaibhav
0 Kudos
Message 5 of 6
(3,168 Views)

@Vaibhav

here is what I mean

 

Measurement Studio

 

C# example lines:

 

...

using NationalInstruments.NetworkVariable;

..

for (int i = 0; i < var_names.Count(); i++) // check existing variables
{
    if (ServerVariable.Exists(sve_process_name,var_names[i])== false)
    {
    ServerVariable.Create(sve_process_name,var_names[i]); // create missing var
    }
}

...

 

______________________________

method description

 

public static NationalInstruments.NetworkVariable.ServerVariableInfo Create(string processName, string variableName, bool singleWriter, int maxItems)

 

Member of NationalInstruments.NetworkVariable.ServerVariable

Summary:
Creates a network variable in the specified process with the specified configuration.

Parameters:
processName: The name of the process that contains the variable.
variableName: The name of the variable.
singleWriter: If true, the variable only accepts connections from one writer at a time.
maxItems: The number of items the variable buffer holds.

 

Message 6 of 6
(3,150 Views)