07-13-2018 01:04 AM
Good morning
I'm trying to control a camera with labview. With the help of the forum, I have managed to import the DLL to labview because I do not have much idea of programming in C ++, only the basics. I have find a problem when programming, is allocate memory for the image. I have a example code but i dont know how to do it in labview.
// Pointer to WORD-Array:
WORD *pwImage=NULL;
// allocating memory:
pwImage=new WORD[g_nNumberOfPixel*nNumberOfLines];
// check allocation:
if (!pwImage)
{
// insufficient memory, terminate image acquisition
}
/* Memory allocated, go on: Be sure to use physical memory
ZeroMemory((void*)pwImage,g_nNumberOfPixel*nNumberOfLines*sizeof(WORD));
I would be very grateful if someone can help me with this
Pablo
07-13-2018 01:10 AM
The problem is the same for deallocate:
delete [ ] pwPixel;
pwPixel=NULL;
07-13-2018 05:53 AM - edited 07-13-2018 06:00 AM
It expects a pointer to memory, and there are several ways to do that in LabVIEW.
1) Configure the dll to accept a 1D array of bytes (no input wired), and set the minimum size of the array to the next input (the size). Note you need an output or an input, or the VI will be broken!
2) Pre allocate a 1D array of bytes (Initialize Array function) or a string and configure the dll to accept it. Make the size match the value wired to size.
3) Use memory dll functions from LabVIEW to allocate memory (and release it at will).
4) Use memory dll functions from Windows to allocate memory (and release it at will).
Ordered as I would try them (1 and 2 are a match). As you are not that experienced, I'd stay away from 3) and 4), only mentioned them for completeness.
1) and 2) should be pretty straight forward. As you add these parameters, all values should be default, e.g. pass as pointer, not handles or handles to pointers, etc..
Image for 1):
Image for 2):
07-13-2018 06:02 AM
@Obli33 wrote:
The problem is the same for deallocate:
delete [ ] pwPixel;
pwPixel=NULL;
As the memory is allocated by LabVIEW (scenario 1 and 2), it's automatically deallocated by LabVIEW. No work for you at all!
3 and 4 do need deallocation, but skip it for now. You won't need them in your use case.
07-14-2018 06:40 AM - edited 07-14-2018 06:40 AM
I fully agree with Wiebe about trying to use his methods 1 or 2, and not worry about 3 and 4 unless you want to really dig into and understand how a C compiler works internally.
Just one caveat: The C code you post mentions WORD as datatype of the image array. If you need to mimic this in LabVIEW you should use an unsigned 16-bit integer rather than an unsigned 8-bit integer as array element data type.
07-16-2018 02:28 AM
@rolfk wrote:
Just one caveat: The C code you post mentions WORD as datatype of the image array. If you need to mimic this in LabVIEW you should use an unsigned 16-bit integer rather than an unsigned 8-bit integer as array element data type.
Agreed. The *sizeof(WORD) is a dead giveaway.
There are two options, pass an array of words (16 bit) with as size the nr of pixels, or pass an array or bytes and multiply the nr of pixels by two for the size. This both adds up to the same amount of memory, to the .dll doesn't care (or know) which is passed. There's just the pointer to memory...
As apparently the pixels are 16 bit, there's no reason not to pass an array of 16 bit numbers.