LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I copy memory to a Labview Array via CVI?

I would like to declare a singly dimensional array in Labview and pass that array handle to CVI for population.

I have the declaration of the array as such;
typedef struct
{
int32 dimSize;
uInt32 Numeric[1];
} peakArray
typedef peakArray **peakArrayHandle

and the function declaration uses "...,peakArrayHandle Array,.." as the pass-in value.

So I (foolishly) think I can simply declare an array size using;

(*Array)->dimSize = numVals;

..and then pass a value to the container using;

(*Array)->Numeric[counter] = value;

It runs fine..once. Then crashes LabVIEW on the second run..So, I'm sure there are a few LabVIEW specific memcpy functions I'm missing here.

I've read thru the pd
f dox, and there aren't sufficient examples for what I want to do...and I've combed thru the limited amount of CIN and DLL example code you provide, but witness differing techniques for implementing this.

Help !!

Kindest regards,
Warren
0 Kudos
Message 1 of 4
(3,194 Views)
You are resizing the array size but not allocating mem for it. You need to use "DSSetHandleSize" or "SetCINArraySize" function to resize the array. I usually use the DSSetHandleSize for arrays also.

CIN MgErr CINRun(peakArrayHandle Array) {
int32 i,ArraySize=100;
DSSetHandleSize(Array,sizeof(int32)+ArraySize*sizeof(UInt32));
(*Array)->dimSize=ArraySize;
for (i = 0; i < ArraySize; i++)
(*Array)->Numeric[i] = i*10;
return noErr;
}


you need to have extcode.h and labview.lib for this. Hope this helps, For more details description consult the Code interface reference manual.


A Rafiq
National Instruments
0 Kudos
Message 2 of 4
(3,194 Views)
Hi !

Ok, this is a DLL, so I thought I wasn't supposed to use the CIN()'s with DLLs? Is that true?

Anyway, I tried this;

NumericArrayResize(uL, (int32)1, (UHandle *)&Array, (int32)(counter - 2));

..and it seems to work. But I still get crashes when I try to write the array value to (*Array)->Numeric[]. I tried using MoveBlock, but that crashes too.

Here's the "real" problem..I am writing the DLL in CVI..but I can't figure out how to invoke the debugger when testing the DLL in Labviews..do I have to use printf's for debugging, or is there some way I can get the CVI debugger to "awaken" when I run the DLL from Labview ??

Kindest,
Warren
0 Kudos
Message 3 of 4
(3,194 Views)
Yes you still have to use the mem functions. I haven't use the move block. I have created DLLs in VC++ and i use the DSSetHandleSize function all the time.
here is an example of DLL function

// Dynamically resizes a 1-D array to size and fills with data
int32 Dynamic1DArrayResize(TD1Hdl in_array, int32 size)
{
MgErr error;
int32 i;

// The first 32 bits are used for size information, and then the array comes after the size
error = DSSetHandleSize(in_array, sizeof(int32) + size*sizeof(float64) );
if (error != mFullErr && error != mZoneErr)
{
(*in_array)->dimSize = size;

for (i=0;i < size;i++)
{
(*in_array)->arg1[i]=(float64)(i +.5);
}
return 0;
}
else return -1;
}
0 Kudos
Message 4 of 4
(3,194 Views)