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: 

array pointer from dll

If it is the case that your dll is expecting a preallocated memory, things are potentially easy. The two issues you face are to: a) get the pointer value of your allocated array (allocated in LV) into the 'struct'/cluster and b) avoid that LV reuses the memory before you receive the data.

 

For a) you need to write a simple funtion call that passes the pointer from param_1 to param_2. Then you Initialize an array of the correct type and size, pass it to param_1 and receive an I32 from param_b. Pass this I32 to the struct.

In order to have LV not reusing the memory, you need to keep all the code in the same vi, I also suggest to place a sequnece (single frame around the dll calls. wire the array to the output terminal of the sequence in a way, that the sequence is left after the dll has copied the data into the memory location. I'm not sure if this still works, it did use this solution for (b) sucessfully in LV 7.1. where the first call to the dll did accept the pointer and a second call was necessary to have the data written to the array.

 

Felix

 

PS: Thanks nathand for mentioning MoveBlock

0 Kudos
Message 11 of 36
(5,911 Views)

Here's a small snippet that demonstrates DSNewPtr, MoveBlock, and DSDisposePtr.  You'll need to do something like this, except bundle the pointer into a cluster, then unbundle it after the DLL call, and you only need one MoveBlock.

21545i72357204BC09A261

Message 12 of 36
(5,899 Views)

Great! I will code that up this week and provide feedback.

Thanks you

jim

0 Kudos
Message 13 of 36
(5,897 Views)

Nathand

We are getting somewhere now! I coded up the memory functions you have shown me and I finally got a huge INT32 value from my dll that looks like a pointer. I did not carefully size it and it has blown up LV, but I had vi's saved up in project.The fog started clearing when I studied the other posts, but now I believe you have pushed me in the right direction. I will update the post when I have more success stories.

Thanks

jim

0 Kudos
Message 14 of 36
(5,884 Views)

Using the last set of tips, I am making a new pointer, passing to my dll to fill the data space, and using MoveBlock then dispose the pointer.

 21628iCD9C191ED0EC7118

It will run once if I enable trace. I get error 1097 from DSDisposePtr, but the knowledge base seems to indicate that is not a fatal error. The first value in the data block array is the value of the pointer. Other integer values are kind of randomly dispersed in the array, which sort of looks like I have numeric or data type mismatch.

 21630iF7DEF77660B73A64

Also after the first run the pc performance indicators look normal, but after the 2nd, LV locks up, the task manager shows 2 LV instances, and the CPU and memory indicator hang up. It looks like it os the moveblock that gets stuck.

 21632i32D538B5C858CC4A

 

0 Kudos
Message 15 of 36
(5,863 Views)

Seeing the memory address in your data usually indicates that you configured the MoveBlock parameters incorrectly and are passing the address as a pointer when you should be passing it as a value.  The MoveBlock call should be set up with the source parameter as an unsigned pointer-sized integer passed BY VALUE since you have the actual pointer value - the memory address - on the wire.

 

Are you certain that you have allocated enough memory for the data that your function returns?  Remember that the size you pass to DSNewPtr is in bytes, not array elements.  The Visual Basic example you posted suggests that the waveform is an array of short ints, which are 16 bits / 2 bytes each (I16 in LabVIEW).  You probably want to initialize an array of I16 and set up the MoveBlock destination parameter to match.

0 Kudos
Message 16 of 36
(5,858 Views)

Nathand

I am starting to make progress now. The key for me to keep LV from crashing, is the pointer datatype in the Labview DLL nodes. The last one, DSDisposePtr, the pointer input was not an Unsigned Pointer-size int/value. When I changed that LV stopped crashing and I am getting repeatable values from the vendor DLL. Now I probably need to be real careful with datatypes.

0 Kudos
Message 17 of 36
(5,824 Views)

Jim,

 

Did you ever conquer this?  It looks like you are also using a Yokogawa scope and trying to open the wdf file in labview.  I am currently faced with the same issues and was hoping you could post some snippets of code.

 

Thanks,

Josh

0 Kudos
Message 18 of 36
(5,402 Views)

Hi jrayeske,

 

Could you explain the issues you're having in a little more detail? If the above steps didn't help you in solving the problem then we'll probably need to start fairly fresh with the issue, I'd suggest you make a new topic and lay out troubles you're having so we can work through the issue more personally.

 

Peter W.

0 Kudos
Message 19 of 36
(5,380 Views)

Peter,

 

I did have another thread going which got me to search for other terms, then I found this thread.  Nathand was able to solve the issue for me.  Please follow the link...

 

http://forums.ni.com/t5/LabVIEW/DLL-Pointer-within-a-Cluster/td-p/1480492

 

Regards,

Josh

0 Kudos
Message 20 of 36
(5,368 Views)