LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW invoke .NET overloaded methods?

Solved!
Go to solution

I'm trying to implement a tool to enable/disable network adapter ports on a PC using the "InvokeMethod" method of ManagementObjects:

 

http://msdn.microsoft.com/en-us/library/system.management.managementobject_members(v=VS.90).aspx

 

(this appears to be the only way to get to the Win32_NetworkAdapter.Enable and Win32_NetworkAdapter.Disable methods, http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx)

 

However, the list of methods available for this object in LabVIEW does not contain the InvokeMethod method.  Can calls be made from LabVIEW to overloaded methods such as this?

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 1 of 14
(3,521 Views)

Yes, you can call overloaded methods. They should simply appear as additional items in the popup menu.

 

As to what you are trying to do: Be aware that those methods are not fully supported and may not even work, depending on your OS. It depends on what has actually been implemented in the hardware driver for the device.

 

Do you actually need to enable/disable the adapter, or is it just sufficient to enable/disable the connection?

0 Kudos
Message 2 of 14
(3,510 Views)

The DUT I am trying to test has a 4-port Ethernet switch in it.  I need to ping each port to make sure they work.  I have 4 Ethernet cards in my PC (one wired directly to each port on the DUT), and am planning to enable them one at a time and ping the DUT.  From what I have read, this appears to be the most reliable method for enabling/disabling ports in a generic sense (i.e., not interfacing directly with the NIC manufacturer's drivers)

 

I wrote a bit of code (see attached) that can query the interfaces available and return their properties.  In the For loop, there is a disabled invoke node which should contain the "InvokeMethod" method, but it is not listed when you pull-down the methods.  Referring back to the first link in my previous post, none of the methods marked "Overloaded" are listed (hence my suspicion that overloaded methods are not supported).

 

The OS I'm using is Win'7 32-bit (x86).

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
Message 3 of 14
(3,504 Views)
Solution
Accepted by topic author Joe_Gerhardstein

Well, I can assure you that overloaded methods are supported, since I've used them before. The issue in your case is that you have a different class inside your loop. The array that is being autoindexed is an array of ManagementBaseObject classes, not an array of ManagementObject objects. The former class has no Invoke methods. The latter has 4. Inside the loop you need to use the To More Specific Class to typecast to a ManagementObject class.

 

Note: an alternative to using .NET is to use the netsh command line. E.g., netsh interface set interface <interface name> DISABLED. However, that is known to not work on Windows 2000 and XP. Not sure if Windows 7 works differently in this respect. 

 

Another alternative is devcon, though I do not know if it works under Windows 7.

Message 4 of 14
(3,496 Views)

We had looked at the netsh command, and it was not terribly reliable.  We were leaning toward using the wmic command (e.g., wmic path win32_networkadapter where index=17 call enable), but you are using SystemExec for that, which is not my favorite thing.  However we were so close with the .NET implementation, that it seemed this was the way to go.

 

Your suggestion on doing the TypeCast was spot-on.  Once I did this, I ended up with the expected list of methods (including all the overloaded ones), and was able to enable/disable the Ethernet card!

 

 

Thanks!  

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 5 of 14
(3,467 Views)

Hello Joe,

 

I am trying to implement a similar test.  I need to enable/disable 4 ethernet cards in a computer in order to test the funcitonality of each one.  I tried to take a peak at your code, but I am using Labview 2010 and can't see your VI.  So, I have a favor to ask. 🙂   Is there any way to could take a screenshot of your code and post it?  I'd greatly appreciate it. 

 

Thanks!

 

Erica Weems

Niitek, Inc.

Test Engineer

http://www.niitek.com

0 Kudos
Message 6 of 14
(3,431 Views)

It's too big to do one screen shot, so there are two that overlap each other 🙂

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
Download All
0 Kudos
Message 7 of 14
(3,418 Views)

Thanks so much!

 

Erica Weems

Niitek, Inc.

Test Engineer

http://www.niitek.com

0 Kudos
Message 8 of 14
(3,412 Views)

Helo Joe,

 

I hate to bother you again.  I've used your screenshots and they were a big help, but a couple things I'm not sure how to replicate.  I'm fairly new to Labview.  But I've learned alot in a short amount of time.  I downloaded the demo version of LabVIEW 2011, don't know why I didn't think of that before.  Can you post the same code again, please? This would be so helpful for my test application.  Again thank you so much for your help.

 

Erica

0 Kudos
Message 9 of 14
(3,371 Views)

Why does he have to post the VI again? It's already available in message #3.

0 Kudos
Message 10 of 14
(3,360 Views)