jpdrolet Posted March 29, 2006 Report Share Posted March 29, 2006 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. 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? Quote Link to comment
Rolf Kalbermatter Posted March 29, 2006 Report Share Posted March 29, 2006 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. 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 Quote Link to comment
jpdrolet Posted March 29, 2006 Author Report Share Posted March 29, 2006 Rolf, Somehow I just knew you would reply to this one... I have implemented the code with MoveBlock and it worked perfectly. GigaThanks Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.