You can programmatically change the data binding source in LabVIEW using the Datalogging Supervisory (DSC) Module or using LabVIEW's native functions. The steps for each method are detailed below.
Using DSC Module
- Create a property node by selecting Application Control >> Property Node in the Functions Palette.
- Right click on the property node and select Class >> Shared Variable >> SharedVariableIO.
- Click on the property node's default property and select Network >> URL.
- Wire a new URL value to this property.
- Extend the property node to add another element to the Property Node and select Network >> Use Binding.
- Create a constant and set the value to True.
- Wire a Shared Variable constant to the reference input of the Property Node. See the two methods below to create a Shared Variable constant:
- Right-click on the reference terminal and select Create >> Constant
- Select DSC Module >> Engine Control >> IO Primitive >> Shared Variable Constant from the Functions Palette
- Browse to or select the desired Shared Variable in the Shared Variable Constant. If you are working on multiple Shared Variables within a library:
- Use the Get Shared Variable List VI available at DSC Module >> Engine Control >> Get Shared Variable List to retrieve multiple Shared Variable references in an array.
- Feed this array into an auto-indexing For Loop and change the URL for each Shared Variable.
Once this functionality is coded in the VI, the LabVIEW DSC Run-Time System is not required if you wish to distribute the executable and are not using other DSC features such as logging, alarming, or security.
- Check the Enable Enhanced DSC Run-Time Support checkbox in the Advanced category of the Build Specifications
- Check the NI Enhanced DSC Deployment Support checkbox in the Additional Installers section of your installer properties.
Using Native LabVIEW Functions
Please note this method will only work on computers with LabVIEW Development System installed.
Right-click on the block diagram and select Programming >> Application Control >> Invoke Node.
- Click on Method and select Library >> Open.
- Right-click the path terminal and select Create >> Constant.
- Enter the path to the library containing the variable you want to change the binding of.
- Right-click the Library.Open terminal and select Create >> Method for Library Class >> Get All Descendents.
- Wire the Library.Open terminal on application invoke node to the reference terminal on the library invoke node.
- Add an index array vi to the block diagram by right-clicking and selecting Programming >> Array >> Index Array.
- Wire the Get All Descendents terminal into the Array terminal on the index array vi.
- Right-click the index terminal and select Create >> Constant.
- Enter the index of the variable you would like to change the binding of.
- Right-click the element terminal and select Create >> Property for Project Item Class >> Variable Reference.
- Wire the element terminal into the reference terminal on the property node.
- Right-click the Variable Reference terminal and select Create >> Property for Variable Class >> Network >> URL.
- Wire the Variable Reference terminal to the reference terminal on the variable property node.
- Right-click on Network.URL and select Change to Write.
- Right-click the Network.URL terminal and select Create>>Constant.
- Enter the path to the variable to bind to in the following format: \\Computer_name\Library_name\Shared_Variable_name
- Redeploy the library to use the new binding immediately:
- Right-click on the block diagram and select Programming >> Application Control >> Invoke Node.
- Click on Method and select Library >> Deploy Library.
- Wire in the same library path from the Library.Open invoke node created in Step 1 above.
Using the native LabVIEW functions only works on computers with LabVIEW Development System installed because the Network.URL
property is not available with LabVIEW Run-Time Engine unless the DSC Module is installed.