From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Which to use: .lvlib, class, or xcontrol?

I'm fairly new to Labview and am just getting started in some of the more advanced features.  In my current application I need to manipulate 2D (and possibly 3D) spatial vectors.  I started off by creating a Vector typedef containing 2 values, Magnitude and Angle.  I then added several other functions to operate on vectors:  Add Vectors, Subtract Vectors, Change Angle, Change Magnitude, Negate Vector, XY Components, etc.
 
Initially this was just a collection of VIs stored in a folder, but I really don't like that organizational method.  For one, there are a couple helper VIs that have no real use to the end user and don't necessarily fit in with the Vector theme.  It also seems like it would be too easy for some VIs to be copied to another computer without the Vector typedef, potentially making maintenance and support a nightmare.  I really prefer a nicely packaged solution.
 
I switched the implementation over to a class, thinking a Vector object would fit well with my task and I could inherit a 3D Vector class from my 2D Vector class.  I still think like a procedural programmer so I find the Labview class implementation rather odd and am no longer sure it fits well.  Overriding methods in particular I found rather confusing.
 
Another thing I am considering is a Labview Library, which until yesterday I thought was depreciated in favor of Labview Projects.  From what I understand, Labview Libraries, or .lvlib files, are still "okay."  It's the .llb files that are discouraged.  Is this correct?
 
I would like to include a sample app that shows the end user what all of the different operations do when they input their own data.  (It also helps me with debugging.)  I wanted to have a drop in control that would take a vector object, display the magnitude and angle, and calculate and display the X and Y components of the vector.  I figured there had to be a better way than repeatedly unbundling my data and doing the calculations for each method.  That led me into XControls, which I have just started reading about.
 
This (finally) leads me to my question:  I think any of these three technologies (Labview Library, Class, XControl) will work, but I don't understand what the tradeoffs are or which technology is "best" for my application.  Any suggestions or insight is appreciated.
 
I realize I am likely overthinking this and making it much harder than it needs to be.  One of my reasons I am doing it this way is for the learning experience.
0 Kudos
Message 1 of 2
(3,201 Views)

Ok, I just typed a huge post to this, but IE died just before I submitted - very frustrating!

In any event, let me give a briefer response here.

First let's draw some distintions between the ideas you're considering.  Starting with Libraries, an llb is basically a folder of VIs - there is an llb manager in LabVIEW that will allow you to toggle between an llb and a folder of VIs.  On the other hand, an lvlib file is nothing more than an XML file which gathers links to VIs that you "add" to the library.  Thus, those are fundamentally different objects.

The lvclass is the graphical answer to the OOP call.  It sounds like you're having some trouble with the interface/paradigm it presents.  Some of that is dicussed well - I would encourage you to read the "additional resources" linked at the following page: LabVIEW OOP 

In particular, be sure to check out: LabVIEW Object-Oriented Programming: The Decisions Behind the Design 

An Xcontrol is a very "special" object in LabVIEW - it allows you to build an object which behaves like a control (has a block diagram node, you can build properties and access then via a property node, etc.) but also allows that control to have dynamic behavior at both edit and run time.  LabVIEW is actually processing things in the background to handle some of the Xcontrol behavior.  There is a simple example in the Example Finder which you can launch from LabVIEW as Help -> Find Examples...

With that said, another idea you may consider is building a code module.  This is basically a VI which is an interface to some data.  This probably sounds like a lvclass, and it's similar.  The idea is that you create a subVI which has a while loop with a shift register - unitialized.  The loop conditional should be wired to only run once - it's only purpose is to get the shift register.  The primary idea is that an uninitialized shift register (not wired from outside the loop structure) will hold its value across distinct calls/instances of a subVI.  Thus, you can pass data to the VI and store it there for subsequent calls. The final piece of the puzzle is simply to put a case structure inside the loop - that case structure can have a case for each "operation" you want.  More specifically, you will have an initialize case, which takes in your data and initializes the shift register from within the loop.  After that, you won't have to wire your data to that VI anymore because it'll be stored in the shift register.  Anyway, you can then build as many operations you'd like, and expose an inputs to the subVI for selecting the operation and passing parameters.

One difference between this and a lvclass is that the code module will only really work on one instance of your data, since it's operating on a consistent and stored piece of data across all calls to the subVI.  To use the code module on two distinct copies of your data, you would have to make a copy of the code module.  That's not too expensive actually, because you can make the guts of the subVI into subVIs (each case can call a subVI for example), so the copy/remame of your code module VI is all that's necessary and it'll use the same VIs underneath - we just need a new shift register to hold our second piece of data.  On the other hand, if you only need to manage one piece of data. 

Here's an example if you're interested: 3D Vector Code Module with Example

Finally, it sounds like the lvclass or the code module are good choices for you.  In addition to the "copy" tradeoff - a potential downside of the code module against the lvclass - you may also consider that the complexity of the code module implemetation etc. is simpler (arguably) than the lvclass - your application needs will steer you to which is better.  If you go the lvclass route, definitely read the additional resources linked at LabVIEW OOP as noted above.

Best Regards,

JLS

 

Best,
JLS
Sixclear
Message 2 of 2
(3,182 Views)