LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Translate Visual.Net code into LabView

Solved!
Go to solution
Hi,
I'm looking for a way to retrieve some machine dependant information. Apparently this bit of visual code would do the trick.
Unfortunately I'm at a loss of how to translate that into LV8.6.
Anyone ever got beyond the PerformanceCounter example?
Thanks
  Jannis
Public Function GetMotherboardSerialNumber() As String
 Dim searcher As New System.Management.ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard")
 For Each obj As System.Management.ManagementObject In searcher.Get
 Return obj.Properties("SerialNumber").Value.ToString
 Next
 Return String.Empty

End Function

0 Kudos
Message 1 of 8
(4,364 Views)
Solution
Accepted by topic author Jannis

This seems to work (at least, it produces a result and doesn't return an error).  There might be a bug in your VisualBasic code - there's a "Return" statement in the middle of your For Each loop.  As a result, I think that it returns only the first item found (in which case there's no need for the For Each loop at all).  The attached LabVIEW code returns the entire array, although at least on my machine that's only a single element.  VI snippet is in LabVIEW 2009, but the attached VI is saved for 8.6 (hope that works with the .NET components) since you mentioned that that's what you're using.

ManagementObjectSearcher Example.png

Message 2 of 8
(4,343 Views)

natahan, You rock! Quick and Good!

Your code produces results that seem to be reasonable on my machine and I'll have to check them on other PCs.

Now I wonder where did you get that inspiration from to use the "GetEnumerator"- and than "MoveNext"-, "Current"-nodes? Is there any reading out there you can suggest, or is that your experience after years of trial-and-error? I'm not a LV newbie and would like to save me the embarrassment of asking you again with the next .Net problem.

Of course I'd also like to know if "great" MSDN is providing us somewhere with a list of their Enums?

The above VB code by the way I found at http://www.vbdotnetforums.com/security-obfuscation/15338-computer-id.html and some more query pairs at http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/08bb5fdc-7f00-4fd6-908c-f6465e734a39/

Thanks for the LV8.6 code; it works.

  Jannis

0 Kudos
Message 3 of 8
(4,315 Views)

I know from experience that any time there's a For Each loop, you'll be iterating through a collection.  I started poking through the available methods and properties and found "GetEnumerator" which looked promising.  I ran a search for GetEnumerator and the first result returned was http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.getenumerator.aspx which explains how to use MoveNext and Current to get each element of the collection in sequence.

Message 4 of 8
(4,298 Views)

@Jannis wrote:

Now I wonder where did you get that inspiration from to use the "GetEnumerator"- and than "MoveNext"-, "Current"-nodes? Is there any reading out there you can suggest, or is that your experience after years of trial-and-error? I'm not a LV newbie and would like to save me the embarrassment of asking you again with the next .Net problem.



This is common programming knowledge :-). Honestly it helps to have some experience in both the .Net language and also the actual flavor your example code is in. Although here Visual Basic and C# are reasonably close to each other to work either. The For each (foreach in C#) keyword in the .Net language is simply an invocation for an iterator, and the logical implementation of iterators in .Net is the object enumeration. Java has a similar construct where you use "for (ObjectType obj : objectCollection)".

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 8
(4,287 Views)
Right! And here for those like me missing "the common programming knowledge", a list of query pairs with some usefulness when inquiring about your system.
Again I can't find a full list in the holy MSDN, which is why I'm asking for a useful link, as nathand has provided and is getting another Kudos.
"SELECT * FROM Win32_BaseBoard" - "SerialNumber"
"SELECT * FROM Win32_BaseBoard" - "Product"
"SELECT * FROM Win32_DiskDrive"   - "Model"
"SELECT * FROM Win32_DiskDrive"   - "InterfaceType"
"SELECT * FROM Win32_PhysicalMedia" -"SerialNumber"
"SELECT * FROM Win32_Processor"  - "ProcessorID"
 
     Jannis
0 Kudos
Message 6 of 8
(4,280 Views)

Great! Exactly what I wanted and couldn't find! Guess I'll be sitting down now and improve my "common programming knowledge".

Thanks nathand and merry X-mas

  Jannis

0 Kudos
Message 8 of 8
(4,252 Views)