LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Load lvclass Dynamically inside lvlib

Solved!
Go to solution

I have an array of lvclasses inside an lvlib, as shown below. I'm looking to get the reference to the individual lvclass I need dynamically, at run time.

The goal is to be able to modifiy or add classes to this lvlib without having to change the rest of my code. Particularly, the code snippet that loads the lvclass will be from a built EXE.

 

How do I dynamically call these lvclasses inside an lvlib?


LVLIB of LVCLASSes.png

 

Dynamic Class Load.png

0 Kudos
Message 1 of 8
(6,354 Views)

I will look into this to see what I can find. In the meantime, here are a couple documents that may prove useful.

 

Plug-in Architecture using Packed Project Libraries: https://decibel.ni.com/content/docs/DOC-19176

Creating LabVIEW Classes: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/creating_classes/

Using Libraries in LabVIEW Projects: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/project_libraries/

Jason H
Automated Test Software R&D
Message 2 of 8
(6,273 Views)

This might be interesting for you. Also, searching Factory Pattern in LabVIEW will probably turn up a number of hits.

 

http://vishots.com/005-visv-labview-class-factory-pattern/

Jarrod S.
National Instruments
0 Kudos
Message 3 of 8
(6,261 Views)

Are these classes inherited from a common lvclass? If so Factory Pattern works. If not you need some work to correct it. Usually in Factory Pattern, you create an abstract class with some Dinamic Dispatch VIs first. Then create an child class which overrides the Dinamic Dispatching VIs. To the To More Specific Class node (in the image you provided), you only need ot pass the abstract object constant and pass a path of the child class that you want to use.

 

As far as Factory Pattern is concerned, whether classes are in lvlib or on its own does not make difference.

TailOfGon
Certified LabVIEW Architect 2013
0 Kudos
Message 4 of 8
(6,253 Views)

TailOfGon,

 

I suppose I didn't specifically mention it, but yes, I do have a parent class that has the classes in the lvlib above override, all dynamic dispatch. So it is a Factory Pattern already, I'm fairly sure. The parent class is in the EXE, while the lvlib is not. Good to hear that I'm on the right track so far.

 

I think my only issue is what do I put in the path? I'm not sure how to get a path to an lvclass inside an lvlib...

 

I'll need to read through all the other links in this thread that have been posted, to see if I can find that answer.

0 Kudos
Message 5 of 8
(6,239 Views)

Glad to hear that you are in the right track. So only thing you need to do is to specify the correct path. I believe there are several ways to do it.

 

In my previous project, I have built an exe that uses Factory Pattern. In the build specification, I included all the classes to be called dynamically. To make this work, you have to specify the class path using relative path.

 

My first attempt was to automatically detect the child classes under the project. Automatic detection could be useful to dynamically populate Ring control. But soon I figured that I cannot explore files within exe. Also this was not a good idea because my class hiearchy has several levels and did not want a user to select abstraction layers. 

 

Then I took a different approach. I register concrete class names to a global variable. Place an array of string in a global. Then put the names of the class to be used (make sure to correctly save the Global). The project structure includes the plugin classes under a specific folder such as: <app dir>\plugin\<class name>\<class name>.lvclass The global can be used to populate Ring in the UI. Once you receive a command to instantiate the object of the select type from the Ring, pass the name string to the path above, replacing <class name> with the actual name.

 

Hope it helps.

TailOfGon
Certified LabVIEW Architect 2013
0 Kudos
Message 6 of 8
(6,213 Views)

Ok, so I figured some things out. "Friday_the_13th" your link to the plugin architecture helped, but I was hoping that my setup would be a bit easier.

 

If the classes are in a regular library (lvlib), then I figured out how to use invoke and property nodes to get the paths for the classes. This worked in development mode, but when I did an EXE build of the code (and the lvlib is outside the EXE), there's an error 1055. After some research, it looks like I need the "Datalogging and Supervisory Control" module... which I don't have. Someone can correct me if I'm wrong.

 

 Dynamic Class Load - LVLIB Method.png

 

 

If the classes are in a PACKED library (lvlibp), then you can use the "Get Exported File Path" function. Unfortunately, I did not have packed libraries created, but I may have to go that route.

 

Dynamic Class Load - LVLIBP Method.png

 

I thought this might be helpful for others trying to figure out how to call items inside of libraries dynamically.

Message 7 of 8
(6,146 Views)
Solution
Accepted by topic author YavannaKementári

With some help from NI Support, I've discovered that what I'm trying to do isn't available in LabVIEW 2011.

 

In 2012 and later, there is a property called "OwnedItems[]" that lists everything owned in an LVLIB. This allows me to dynamically link to an LVCLASS inside an LVLIB.

 

I thought this would be nice for others to see without having to contact NI Support.

 

Dynamic Class Load - LVLIB Method 2013.png

Message 8 of 8
(5,945 Views)