From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

create array of structs from a .NET DLL

Hello @,
 
i get a .NET DLL and it's my first time to work with it in LV. At first I've a constructor of a class. With an Invoke-Node I call a method of this class. The repeat values of method will be written in a defined struct. So the method need an arrayList of these struct. The struct is part of the DLL. How is it possible to create such a arrayList? I think it should be an array with elements of the struct from the DLL. Please help me!!!
 
Thanx Thomas
0 Kudos
Message 1 of 17
(3,403 Views)
I can't understand exactly what you are asking for. Can you post the method definition?
 
Structures and ArrayLists are .NET constructs and so you need to create them via the constructor node in LabVIEW. You can then pass them into methods that take them. You can also put values into them via the property node and the invoke nodes.
 
That's kinda generic information, but until I see the method or sample VB/C# code, I'm not sure what else to tell you.
0 Kudos
Message 2 of 17
(3,378 Views)
Hello,
 
I've attached a picture of the program. At first you see an constructor of USBController. Over an Invoke-node i call the method with the function search-devices. Her you can see the green input for connected devices. this should be an arraylist with elements of deviceinfo. Deviceinfo is a struct from the .net dll. Here I have called it over a constructor and a property node. I tried to create an array over the property nodes with a reference to the input connected devices. But it doesn't work. Could you help me now?
 
I think the question is either LV could use the included construct reference of the .NET DLL ?
 
Thanx,
 
Ciao Thomas
0 Kudos
Message 3 of 17
(3,371 Views)
Okay, here is what you need to do.
 
1. Use the constructor node as you have done to create an instance of the DeviceInfo struct. Wire this up to a property node, again as you have shown, but change them to writes rather than reads. This will let you initialize one of the DeviceInfo structures.
 
2. If the input to the SearchDevices method is actually a System.Collections.ArrayList, then you need to use one of those rather than an array. An Array and an ArrayList are two very different things (see http://detritus.blogs.com/lycangeek/2005/09/array_vs_arrayl.html and http://detritus.blogs.com/lycangeek/2005/09/getting_the_arr.html). So, like the structure, drop down a constructor node for System.Collections.ArrayList (you'll find it in the mscorlib assembly) and use it's Add method to put your DeviceInfo refnum into the list. You'll call Add for each DeviceInfo you create.
 
3. Pass the reference to the ArrayList to the SearchDevices method
 
4. Make sure you call Close on any reference you create. For example, after creating a DeviceInfo structure and putting it into the ArrayList, you need to close your reference to the DeviceInfo. Failure to do so will result in a memory leak (because the memory is actually owned by .NET).
0 Kudos
Message 4 of 17
(3,364 Views)
Hi,
 
thanks for your help. I follow your instructions and now it's possible to start the vi. But i get an error at the status from my search devices function. But this could be an other reason. Please have a look at the attached picture again to check if all it's right.
 
Thanks again
 
Cu Thomas
0 Kudos
Message 5 of 17
(3,360 Views)
Other than closing the reference to the ArrayList and the USBController (which you might not want to do at this point in the code, don't know), the program itself looks correct from LV's point of view.
 
The only thing I can think of is that you aren't initializing the DeviceInfo value to anything. I don't know exactly what the method does, but my guess is that the DeviceInfo is used as a filter for what devices to find. That you pass in ten identical, uninitialized structures might be a problem.
 
What exactly is the error it is returning?
0 Kudos
Message 6 of 17
(3,354 Views)

Hi Brian,

thanx for your help up to now. The program works fine. But now there is a other problem with a Byte Array from the mscor.lib . I need a input and a output Byte-array from the mscorlib. So I make a constructor Byter and array. With a cast I tried to get the correct input. But it doesn't work. I tried some other solutions but I had no succes. Could you help me again, please.

Thanx Thomas

0 Kudos
Message 7 of 17
(3,340 Views)
I'm going to guess that you are using LV 7.x, because I think you have run into a bug that was fixed in 8.0. The problem is that LV doesn't recognize the byte array parameter correctly, due to the in/out nature, and doesn't automatically map it to a LV byte array. However, if you go to <vi.lib>/platform/dotnet.llb, you'll find a VI called To Object. You pass in a regular LV array of bytes and out the other side comes a .NET object reference. You then use To More Specific to convert it to the .NET array of bytes and pass that in.
 
On the other side, use To Variant, again in the dotnet.llb, to covert the .NET reference to a LV variant, and then the Variant To Data to get the LV array.
 
It is a bit of work, but not bad. The main problem is that it isn't easy to define a .NET array of doubles as the input to the To More Specific since it doesn't exist in mscorlib. The easiest thing to do is find a method that takes an input of byte[] (such as System.IO.BinaryWriter, and the Write() method) and use that to create the refnum constant. You can't use your method, because it is a byte[]&.
 
Or, you could upgrade to LV 8. That is easier, but obviously means spending money, and your project may not allow it.
0 Kudos
Message 8 of 17
(3,334 Views)
Hi Brian,
 
I'am using LV 8....what is the solution in this case?
 
Cu Thomas
0 Kudos
Message 9 of 17
(3,333 Views)
Can you post up the assembly so I can take a look? It doesn't matter if it will run or not, I just want to see exactly how the method is defined.
 
Thanks
0 Kudos
Message 10 of 17
(3,328 Views)