LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementation of an Array of Clusters using CVI & Labview?

Hi,

I'm using CVI to make several DLL's to be used in Labview. I have an array of a cluster of three numeric
data types, in other words;

typedef struct
{
uInt32 Wavelength;
float64 Power;
float64 OSNR;
} Data;

typedef struct
{
int32 dimSize;
Data peakData[1];
} DataArray;
typedef DataArray **DataArrayHandle;

This is the first time I've worked with a struct within an array in CVI, and I'm a bit confused. I have read the tblsrch.c example in Labview and I am now thoroughly confused.

I understan
d having to resize the array, then setting the dimension size, then allocating memory for the new Data struct. But I can't seem to figure out how to write to the Data struct member data w/o having labview crash.

Can you provide an example of how to write to say, the Power Data member? I'm just flumoxed here.

Kindest,
Warren
0 Kudos
Message 1 of 2
(2,705 Views)
You do need to set the handle size prior to writing values to Data struct data members. If you write the values first, labview would notice that you are trying to write in its mem space without allocating space, and crash.
Steps are as follows

1)Set the handle size for TD1Hdl Data handle. For example, if you have array with 2 elements, then size for that handle would be

int ClusterSize=sizeof(uInt32)+2*sizeof(float64);
int ArrayDim=2;

int HDlsize=(sizeof(int)+ClusterSize)*ArrayDim;

2)Once you have the Handle size you allocate mem for it

DSSetHandleSize(Data,HDlsize);
(*Data)->dimSize=ArrayDim;

3)Then you write data

(*Data)->Cluster[0].Wavelength=10;
(*Data)->Cluster[0].Power=10.31;
(*Data)->Cluster[0].OSNR=10.32;

.........and so on.

Hope this would clear th
e confusion.

A Rafiq
National Instruments
Message 2 of 2
(2,705 Views)