...The DLL has a routine to pass the a pointer for the
> array and a second routine which, when called, actually fills the
> array... it expects that a pointer to the array has
> already been passed to the DLL by a call to the first routine
> ...how do I guarantee that
> the pointer passed will still point to the array when I make the
> second call.? Second, how to I access the array in a diagram after
> the second call? Ideally, for reason I won't go into here, I would
> like to make the two calls in separate subVIs if I can figure out how
> to safeguard the array between calls and access its data after the
> second call. I should mention that the first routine can accept
> buffer arrays of a variety of different atomic types (e.g. int16 and
> single) depending on how the "Call to Library" node is configured. It
> actually treats the array pointers as (void *). All type dependent
> processing occurs in the second routine.
There are several things that seem inflexible about this interface, and
I'd encourage you not to keep the same interface and pass it on to your
diagram, or your customer's diagram. Instead, make two subVIs, one that
takes the parameters for the acquisition and returns on int16s, and
another that takes the parameters and returns floats. Each of these
will call the various entrypoints in the DLL and return the data all in
one step.
The first step that has to happen is determine exactly how the buffer is
allocated and sized. At this point I still don't see how this interface
would be used from C code. If the first call is given a pointer and
expected to resize it, then the original pointer is not guaranteed to be
valid -- this would require a handle or pointer to pointer type of
structure. If the first call allocates the buffer on its own, then this
pointer has to be returned on either the first or second call. So the
first thing to do is draw a simple bubble diagram of how the buffer is
created and how each entity know how to access the buffer.
To answer your direct questions, the DLL can be a passed an array in
several ways. The one called Array Data Pointer points into the LV
handle, past the int32 size and to the first data element. This is
normally accompanied by another parameter that tells the DLL how many
elements it can access. The DLL needs to be careful not to access
memory past end of the array pointer, and it cannot reallocate the data
as it only contains a pointer and has no way to tell the caller about
the new pointer.
The other way to pass the data is in the LV handle or pointer to the LV
handle. A LV handle is a pointer to a structure of (sizes,data). For a
1D array, there is only one size, then some alignment depending upon
platform, then the data elements. The handle can be resized using the
appropriate LV helper functions.
Whenever you pass either of these into the DLL as a parameter, you can
wire the array out of the right side. If do wind up putting the various
DLL calls into different subVIs, you cannot guarantee that the LV array
will not be copied due to a branch in the wire. The contents of all
copies will be the same, but a pointer into the array is not guaranteed
to be valid.
So, I'm not sure how much this helps, but the first thing to do is
determine how this API would be used from C. Once you know that, it is
relatively straightforward to ma it over to LV. I'll answer the
typecast question in the other posting.
Greg McKaskle