From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

.NET Reference requirements

Solved!
Go to solution

Some .net calls require a reference to be passed to them, some do not. If a reference is required but there is no constructor available how do I get a valid reference?

 

DotNetReferenceExample.png

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub

0 Kudos
Message 1 of 4
(3,569 Views)

Hi Ben, 

 

.NET automatically loads mscorlib (most of the System namespace) as part of the .NET runtime hosting process that hoists up the .NET runtime in EXE apps, or some other kind of runtime hosting environment. In hosting environments like LabVIEW, the runtime host may also pre-load a bunch of assemblies on its own.

 

It is good practice to always create a .NET reference, regardless of the assembly. To do this you can drop in a ".NET Constructor node", double click and navigate to the assembly you are loading. This creates an instance of the .NET object for you to use as a reference with the .NET property and invoke nodes. LabVIEW has a great built in example of this under Help>Find Examples>Calling a Private .NET Assembly. 

 

Happy Holidays! 

Clint T.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,522 Views)
Solution
Accepted by Ben_Manthey

Battery life percent.png

 

You need to get it from a System.Windows.Forms.SystemInformation property node.

Message 3 of 4
(3,515 Views)

I think you misunderstood the original post, Clint.

 

The class the OP wants to use is System.Windows.Forms.PowerStatus.

If you create a constructor node you can browse to that class but get the message that there is no public constructor for it. 

If you create a property node you can also browse to that class and then select the BatteryLifePercent or another property from it but end up with a broken arrow since the property node expects a valid class refnum.

So this looks like a catch 22. Of course one can write a private .Net DLL which calls this property in this way and then call that .Net DLL with LabVIEW but that feels quite a bit like a roundabout way to do this.

 

The solution is to know how this is done in .Net:

 

PowerStatus power = SystemInformation.PowerStatus;

batteryPercent = power.BatteryLifePercent;

So the PowerStatus object is a static object class read from the SystemInformation.PowerStatus property.

 

And if one checks in System.Windows.Forms one also sees a SystemInformation class and if you create a property node you see lots of properties, all with a prepended [S]. This indicates that it is a static property and for static properties (and methods) one does not need a class refnum at the input. 

 

.Net Power Status.png

Rolf Kalbermatter
My Blog
Message 4 of 4
(3,513 Views)