Jump to content

Passing array to asynch call


Recommended Posts

I have to interface with a DLL that uses a data buffer asynchronously e.g. the buffer is filled in background after the function returns.

In C it looks like this:

pBuf =(uint16 *) malloc(size);StartAcquisition(pBuf);while (GetStatus() != DONE);/* start using pBuf here */

I know I can preallocate the data buffer in LabVIEW by initializing an array of the proper size but will the data in the wire output from the CLN be updated? I can't test this actually because I don't have the hardware yet.

post-447-1143596923.png?width=400

Alternatively, the DLL has functions to allocate and free buffers but I can't figure how to retrieve data from these pointers .

Is there a solution apart from a wrapper DLL?

Link to comment
I have to interface with a DLL that uses a data buffer asynchronously e.g. the buffer is filled in background after the function returns.

In C it looks like this:

pBuf =(uint16 *) malloc(size);StartAcquisition(pBuf);while (GetStatus() != DONE);/* start using pBuf here */

I know I can preallocate the data buffer in LabVIEW by initializing an array of the proper size but will the data in the wire output from the CLN be updated? I can't test this actually because I don't have the hardware yet.

post-447-1143596923.png?width=400

Alternatively, the DLL has functions to allocate and free buffers but I can't figure how to retrieve data from these pointers .

Is there a solution apart from a wrapper DLL?

The picture as you have shown it should actually work. Since the wire is going through the loop AND is not modified in anyway on its way LabVIEW will maintain the memory buffer for the time until the while loop is finished and it will 99.99999999% for sure not bother to reallocate or otherwise interfere with the buffer.

As to your second question: This would be more proper and not rely on a specific wiring and/or LabVIEW internal mechanismes that "might" change with a future version.

If you have a pointer you can actually configure a Call Library Node to call the LabVIEW manager function MoveBlock to copy data from and into this pointer from a LabVIEW array or string.

Basically MoveBlock has following syntax:

void MoveBlock(void *src, void *dst, int32 numByte);

Configure the CLN as follows:

Library: LabVIEW

Function: MoveBlock

Calling Convention: C

return value: void

1st param: **

2nd param: **

3rd param: int32 by value

1st and second parameter depend if you want to copy to or from the pointer. Lets assume you have a pointer that you want to get data out then you would for instance configure the first parameter as uInt32 by value and wire the pointer you got from the allocation function to it (which of course must be a uInt32 too.

The second parameter would be for instance an array of uInt8 passed as C array pointer. Make sure you preallocate that array to the needed size and then pass that same size as third parameter.

This of course has a slight drawback of requiring an additional data copy (the MoveBlock operation) but will work irrespective of some not so intuitive wiring or not and possible pitfalls with future LabVIEW versions.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.