LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

structure pointer from C to cluster

Solved!
Go to solution

I have a question and I earnestly request your help.

When calling the Dynamic Link Library generated by my C language, VI will be stuck without response when there is array-type data in the structure of C program.

I want to know how to pass data of array type pointed by structure pointer.

0 Kudos
Message 1 of 4
(2,239 Views)

LabVIEW arrays are NOT compatible with C array pointers! And to make matters more complex you have two types of arrays in C that can be part of a C structure, fixed size, which are fully inlined inside the structure, and variable sized, which only have the pointer itself in the structure.

Generally structures in API calls contain fixed size arrays, as array pointers are an extra memory management hassle for the programmer. But without seeing the declaration of your structure and the according API call it's impossible to make any statements about how to proceed.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 4
(2,208 Views)

Thank you very much for your reply!I want to know can I output the array "gpelist"  in the entire cluster "cplpara"?

 

typedef struct
{
	float tramp;
	float tpe;
	float gsdv;
	float gss;
	r rfpaulse;
	float view_size;
	float npe_size;
	float dw;
	float gro;
	float grdv;
	float gpelist[500];
	float tepad;
	float trpad;

}cplPara;
cplPara cplpara;
_declspec(dllexport) void PG(userPara *userpara, cplPara *cplpara);
_declspec(dllexport) void PG(userPara *userpara, cplPara *cplpara) { float gpe_delta, view_order[500];
int i; gpe_delta = -1.0 / GAMMA / (cplpara->tramp + cplpara->tpe) / MS_S / (userpara->fov_pe*MM_CM); for (i = 1; i <= int(cplpara->npe_size); i++) { view_order[i] = i - cplpara->npe_size / 2; cplpara->gpelist[i] = view_order[i] * gpe_delta; }
}

 

 

0 Kudos
Message 3 of 4
(2,194 Views)
Solution
Accepted by topic author anovice1

Please look at the pic you attached and tell me how in Gods name I should determine how the cluster looks that you created for this parameter? Yes LabVIEW is a graphical programming language but a pic is a 2D information while a LabVIEW VI contains lots of extra information such as how the cluster looks when opening the terminal, or the Call Library Node configuration itself! And when uploading a VI here please go through the trouble to backsave it at least two or three versions from the current version as not every body is able to use the latest LabVIEW version on his/her work computer.

Since you decided to attach a pic I decided to return the favor and instead of providing you a corrected version of your VI simply explain to you in prosa what you need to do. Your array is a fixed size array and therefore it is embedded inside the structure by a C compiler. In LabVIEW you create such a cluster with such an array by adding another cluster with the correct number of array elemenys inside and then use the Array to Cluster and Cluster to Array nodes to convert between the normal array and the fixed size array in the cluster and then back.

 

However the calculation you do is so simple that creating the array in LabVIEW instead would be a lot easier unless the C code you show is just a dummy function to test your approach before using the real DLL.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,178 Views)