LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.net constructor?

I develop a software in LabVIEW, which is at the end compiled as a .NET interop assembly. The project is programmed in LabVIEW OOP, where I have a high level class with its data. When the sources are compiled, I want to have a constructor, which initializes the class data - the constructor should use user inputs. 

 

I am wondering, whether there is a possibility to do that. 

 

If I place a .net constructor node on the block diagram, select the newly created .net assembly by LabVIEW, I have no access to the data of the LabVIEW class. In the application builder there is only one entry for a class name, and basically this is the only .NET class of my LabVIEW project. The "internal" classes has to be accessed in another way.

0 Kudos
Message 1 of 10
(2,058 Views)

Hello!

 

As far as I know, there is no classical constructor in LabVIEW that you can pass parameters to as you know it from C#. When you create a new class in LabVIEW you get an Init.vi which you can use to initialize all your class private data. Just call it right after you called the .Net constructor node in LabVIEW and you are ready to go.

0 Kudos
Message 2 of 10
(2,032 Views)

Thanks for the respone, Jens. 

 

I have another question. If I create a .NET assembly in LabVIEW, I have to define the assembly's class name. In the caller, i.e. in C# or VB, I can refer to this class. But, which private data, methods and functions does this class have? 

Madottati_0-1621935874987.png

 

0 Kudos
Message 3 of 10
(2,023 Views)

Hey!

 

The class just consist of the methods and class private data you define for your class in LabVIEW. For each method (VI) you add to a class you can select different access types so you can define which methods can be called from a third party application for example.

You should really consider to take some time and read some tutorials to get some basic knowledge about OOP. The fundamentals are exactly the same like for any other OO language like C++ or C#.

 

There are a lot of very good introductions on this topic:

 

https://www.ni.com/de-de/innovations/videos/12/how-and-why-to-use-labview-object-oriented-programmin...

https://www.ni.com/de-de/innovations/videos/14/introduction-to-oop-and-hardware-abstraction-layers.h...

 

Edit:

 

If you mean creating an .Net Interop Assembly from an entire LabVIEW project then you need to select the VIs/ folders you want to include under "Source Files" in your build specification.

0 Kudos
Message 4 of 10
(2,008 Views)

Hi,

 

I guess I know the basics of OOP, I can work with objects of my classes in LabVIEW. The problem begins, when I build a .NET interop assembly using my class, then use it in any other language - for the time being in LabVIEW. 

 

1. If there is no "functional" constructor in LabVIEW, like C# constructors, I can use one method to initialize my object, okay it is not a problem. 

 

2. If I use the constructor node on the block diagram, I can access the methods of my class...

Madottati_2-1621952552085.png

 

3... but not its accessors (properties):

Madottati_3-1621952676042.png

 

why is that so?

 

 

0 Kudos
Message 5 of 10
(1,989 Views)

The class private data (class properties) in LabVIEW is always private so it can only be accessed by methodes inside the owning class (this can not be changed). To change this and make the properties read or writeable for other classes or applications you need to create getter and setter methods like you would in C#. Go to the class right click it and select "Add" -> "VI for data member access..".

 

You can acces the class pivate data the way you set/ select the access rights for the created accessor VIs (private, public, protected, community)

 

For you build spec:

- You must add the Accessor VIs to "Source Files" -> "Exported VIs"

 

- In LabVIEW you can use the Invoke node to call the accessor VIs (you should also be able to use a property node)

- in C# you need to call the accessor methodes to read or write data (not 100% sure, its bin quite a while since I did this)

 

Unfortunately I can't test it on my machine cause LV is crashing all the time when I try to build a .Net Assembly

0 Kudos
Message 6 of 10
(1,979 Views)

Hello Jens,

 

I appreciate your answers, thank you!

 

Another question is, how to use the reference created by the .net constructor node in LV. In the application builder, I export a function "write name". I can access this method with the invoke node:

Madottati_0-1622017524597.png

 

But the WriteName.vi has an object reference input and an object reference output. I see these as parameters on the invoke node, but basically this should be the "new reference" wired through the invoke nodes. Yes, the object references are in- and outputs on the VI's ocnnector pane, I just don't know how to use them as a refnum in LV later, once the .NET assembly is compiled. 

0 Kudos
Message 7 of 10
(1,930 Views)

Hey!

 

Did you try to split the EOL refnum to the EOl__32in terminal? I'm not sure how the class data will be handled. Maybe you then need to use the EOL__32out refnum and wire it to the next invoke/ property node. Just try it...


I would love to try this by my own but as stated before I can't build a .Net Interop Assembly on my machine (god knows why).

 

Maybe this article can help you:

https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/charac_net_interop/


I don't know if using a "LabVIEW" .net dll in another LabVIEW application/ project does make sense or if it ever should be done this way. To share code between different LabVIEW projects there are many other and "better" ways to do this.

 

Is it really necessary to build a LV application into a .Net dll just to use it back again in LabVIEW?

0 Kudos
Message 8 of 10
(1,922 Views)

I develop .NET assemblies in LabVIEW for test systems using VB and C#. 

 

As I have only LabVIEW and TestStand on my PC, I can play with calling the resulting assembly, that's why I call it from LabVIEW - but this is not the way we use the .NET assembly. If I would use my code only in LV/TS, I would create packed libraries.

0 Kudos
Message 9 of 10
(1,916 Views)

Ah ok..

 

So it might be a better way to test the dll in C# to not get more confused with the way LabVIEW handles .Net dll's. Maybe you can upload a simple test dll so I can try it in C#.

0 Kudos
Message 10 of 10
(1,911 Views)