Developer Center Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

2d arrays in a cluster

I just recently began learning Labview since something came up here at work and my boss asked me to get something working using this language. The idea was that we have a DLL which has been written in VC++ for a device and we would like to have the same functionality in Labview as we do with our own software. The DLL has several structures and each of those contains arrays and elements of different data types. I was able to get a structure with different data types and arrays to work. The problem came about when I went to try using 2d arrays. I asked for some help on the NI developer’s forum and a user mentioned that I would need to use a wrapper function but I’ve never written one before and nor do I know how to implement it into my VI. Do you think you could help me? Sorry I know this is quite a bit but it seems like not many people know how to deal with these complex functions.

Thanks,

George

0 Kudos
Message 1 of 9
(10,932 Views)

Hi George,

In your email to me, you mentioned that you took a look at the example I created (Calling C/C++ DLLs Containing Simple and Complex Datatypes from LabVIEW) and needed the VIs in LabVIEW 8.5.1. I've attached the VIs to this post, back-saved to LabVIEW 8.2, this should work in LabVIEW 8.5.1 as well.

The example shows how to pass a 2D Array as well as structures (with 1D Arrays) from LabVIEW to a DLL and back, so hopefully that will get you started. However it did not address the case of a structure with a 2D Array. One of the answers suggested in the discussion forum is to basically create another C function (either in the same DLL or in a new DLL) that takes in the individual elements of the struct (which is simpler to do), then packs it into a struct and passes it onto the main DLL function.

Alternatively, you might be able to do this without having to use a wrapper DLL, and pass in the data straight from LabVIEW. I will tinker with your sample DLL and let you know what I find.

By the way, thanks to smercurio_fc and rolfk for tackling this issue on in the forums!

Thanks,

Jervin Justin

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 2 of 9
(4,695 Views)

Hi George,

Attached is the working code. I made a couple of minor changes to your code to clean it up as well.

The major change was switching from a fixed size array to a dynamic array and sizing it inside the function. This allows us to easily pass the array back and forth as a pointer instead.

The VIs are attached in both LabVIEW 2009 as well as LabVIEW 8.2 format. I've tested it in LabVIEW 2009 and then downconverted, I didn't have 8.2 on my machine to verify, let me know if you have issues.

The principles used here are the same as described in the series of articles titled Calling C/C++ DLLs from LabVIEW.

Hope this helps!

Jervin Justin

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 3 of 9
(4,695 Views)

And if you wanted to use the wrapper solution instead (which can be simpler at times if you are willing to have more C code), see the attached...

This time I left your code relatively untouched (except for fixing how you assign the array, you were out of bounds). I added the wrapper function to the same DLL, you could have a separate DLL instead.

Again, the LabVIEW files are tested in LabVIEW 2009 and backsaved to LabVIEW 8.2.

Hope this helps!
Jervin Justin

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 4 of 9
(4,695 Views)

Hi Jervin,

Thanks for posting that information. That's exactly what i was looking for. I'm in the process of trying to get multiple 2d arrays of different data types to work. Now i have a structure with two double 2d arrays and one float 2d array. I haven't been able to get the float array to work just yet and i'm not sure if it's because i'm missing something in the VI. Do you see anything?

Download All
0 Kudos
Message 5 of 9
(4,695 Views)

Hi George,

I ran your VIs and it seems to work for me in LabVIEW 2009... I've attached a screenshot of the output.

Is this not correct? What do you get?

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 6 of 9
(4,695 Views)

Interesting. I've attached a screenshot of what i'm getting. The first two arrays show up like they're supposed to but the third array of floats is coming up with strange values. 

0 Kudos
Message 7 of 9
(4,695 Views)

I tried it on LabVIEW 8.5.1 yesterday on a different machine and I get the same behavior you do (as described in the screenshot, not the new behavior you described...).

I'm going to dig into this a little deeper today and get back to you when I find out what changed.

Thanks,
Jervin Justin

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 8 of 9
(4,695 Views)

Hmmmm, it seems that there was something not working with using GetValueByPointer to dereference floats in LabVIEW 8.5.1 and was fixed in LabVIEW 2009.

Luckily, you can use the other method of dereferencing described in Dereferencing Pointers from C/C++ DLLs in LabVIEW, ie using the MoveBlock function instead.

I've fixed the example and attached it here.

Hope that helps,

Jervin Justin

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 9 of 9
(4,695 Views)