12-21-2017 09:34 AM
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?
Solved! Go to Solution.
12-22-2017 04:52 PM
.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.
12-22-2017 05:33 PM
You need to get it from a System.Windows.Forms.SystemInformation property node.
12-22-2017 05:54 PM
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.