06-15-2011 08:55 AM
I am using a .NET library to get a result from a search for USB devices and the method returns a structure data type with two member values, one is UINT32, and the other is String. The output of the Invoke method for the class has the output as a 2-D refnum. How can I convert and display it with LabView indicators?
06-15-2011 09:04 AM
I don't understand. Does the method return a structure, or a 2D refnum? Or a refnum that's a 2D array of structures?
A structure can be treated as a class. Wire it to a property node and get the individual elements.
06-15-2011 09:17 AM
The output from the method call states that the output is a 1D array of .NET RefNum.
06-15-2011 09:19 AM
That's what LabVIEW is interpreting as. What does the method's prototype look like? Have you tried simply auto-indexing a for loop with this output? You're not providing a whole lot of information here.
06-15-2011 09:28 AM
Here is the definition of the structure.
public struct UsbDevice
{
publicintDeviceIndex;
publicstringDeviceName;
}
Here is the prototype and implementation of the method.
publicstaticUsbDevice[] GetConnectedUsb()
{
List<UsbDevice> devices = newList<UsbDevice>();
try
{
Usb usb = newUsb(0);
intdevicecount = usb.Discover();
BinaryProtocolConnectionbp;
string name = string.Empty;
for (inti = 0; i < devicecount; i++)
{
bp =
newBinaryProtocolConnection();
bp.Connect(i);
if ((name = bp.ModelName()) != string.Empty)
{
UsbDevice device = newUsbDevice();
device.DeviceIndex = i;
device.DeviceName = name;
devices.Add(device);
}
bp.Disconnect();
bp =
null;
}
}
06-15-2011 10:00 AM
Soooo.... have you tried simply auto-indexing a for-loop and using a Property node inside the loop? If you are unable to get it to work, upload your VI along with the assembly. You will likely need to put the files into an compressed archive.
06-15-2011 10:24 AM
I am new to LabView and I am not quite sure how I can read the members of a structure. I can supply the reference number to a property node, but not get the values of a resulted output that is in the form of a 1D refnum.
06-15-2011 11:13 AM
Do you know .NET? Or is your issue how to use it in LabVIEW in general? If it's the latter, have you taken a look at the examples that ship with LabVIEW? Do you know about loops? Do you know about auto-indexing of loops? Have you done any of the LabVIEW introduction material, tutorial(s), and other material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials? Note that you can also take the online courses for free. Here is a simple example that extracts properties from a class: https://decibel.ni.com/content/docs/DOC-5921.