01-26-2010 12:24 PM
Ok so now the cluster is able to identify multiple data types. What if there we're two structures inside of a main structure, would the main cluster have two sub clusters in labview with different data types?
i.e.
typedef struct
{
double dD1;
double dD2;
int I1;
} Cluster_1;
typedef struct
{
int D;
int E;
int F;
} Cluster_2;
struct ParentStructure
{
Cluster_1 *pCluster_1;
Cluster_2 *pCluster_2;
};
01-26-2010 02:29 PM
I was able to get the two structures to display the variables using two clusters. Now the question is if i have an array in one of the structures, how do i get that to work in Labview?
typedef struct
{
double dD1[10];
double dD2;
int I1;
} Cluster_1;
typedef struct
{
int D;
int E;
int F;
} Cluster_2;
struct ParentStructure
{
Cluster_1 pCluster_1;
Cluster_2 pCluster_2;
};
_declspec(dllexport) int _cdecl AOS_GetData_George(void *dataCluster)
{
parentStructure = (ParentStructure *) dataCluster;
parentStructure->pCluster_1.dD1[0] = 1.0;
//parentStructure->pCluster_1.dD1[1] = 1.1;
//parentStructure->pCluster_1.dD1[3] = 1.3;
//parentStructure->pCluster_1.dD1[5] = 1.5;
//parentStructure->pCluster_1.dD1[7] = 1.7;
parentStructure->pCluster_1.dD2 = 2.2;
parentStructure->pCluster_1.I1 = 3;
parentStructure->pCluster_2.D = 4;
parentStructure->pCluster_2.E = 5;
parentStructure->pCluster_2.F = 6;
return 1;
}
01-26-2010 03:13 PM
01-28-2010 01:33 PM
01-28-2010 01:55 PM
01-28-2010 03:43 PM - edited 01-28-2010 03:45 PM
ghatz85 wrote:
I was able to get one array of any data type to work inside the cluster. Do you know of any ways to get multiple arrays with different data types to work inside a cluster?
You need to distinguish between fixed size arrays inside a structure and variable sized arrays. Fixed size arrays have a fixed dimensional size specified such as
struct {
.....
type name[10];
.....
} StructName;
and are inlined into the structure. In LabVIEW you can represent such arrays by creating a cluster which contains the specified number of elements (obviously only practical for arrays and strings which are not to long as you do not want to create clusters containing 100ds of elements).
However variable sized arrays and strings are put into a structure by the C compiler only as a pointer and look like this:
struct {
.....
type *name;
.....
} StructName;
These arrays (pointers) can not be easily represented by LabVIEW since LabVIEW does not really know anything equivalent to C pointers on diagram level. And LabVIEW arrays and strings are completely different than C arrays (or strings which are really just special arrays). So there is no way to easily embed variable sized arrays or strings into a structure on the LabVIEW diagram level to pass to a Call Library Function.
01-28-2010 04:14 PM
For right now, i'm working with fixed sized arrays.
typedef struct
{
double T1;
float T3[3];
int T2[3];
} Test_array;
struct MainTestArray
{
Test_array pTest_array;
};
_declspec(dllexport) int _cdecl AOS_GetData_Array_GH(void *testArray)
{
maintestArray = (MainTestArray *) testArray;
maintestArray->pTest_array.T1 = 1.11;
maintestArray->pTest_array.T3[0] = 2.5;
maintestArray->pTest_array.T3[1] = 2.6;
maintestArray->pTest_array.T2[0]=36;
maintestArray->pTest_array.T2[1]=2;
return 1;
}
I'm not too sure I completely understand your explanation of how to get multiple arrays to work. Right now I have a cluster with a numeric indicator (double), an array with three numeric indicators (sgl) and array with five numeric indicators (I32). The double and the floats show up but then the array of ints show up as zeros. Am I missing something?
Sorry like I said, I'm still new with Labview.
The main file that I'm working with is under: GH Test DLL Folder\Read-Write DLL\GH Test DLL modified.vi
01-29-2010 10:14 AM
ghatz85 wrote:I'm not too sure I completely understand your explanation of how to get multiple arrays to work. Right now I have a cluster with a numeric indicator (double), an array with three numeric indicators (sgl) and array with five numeric indicators (I32). The double and the floats show up but then the array of ints show up as zeros. Am I missing something?
Rolf's comments were more generic. In your case you have fixed-size arrays, so you can use clusters as shown in the "Call DLL" example. What's basically being done is that the data stored in the arrays is being "repackaged" so that it would be located in memory in the same way that C expects it to be. Because an Array to Cluster function is being used, this means there's a limit to this method. The Array to Cluster function is limited to 256 elements. Thus, you cannot deal with fixed-sized arrays larger than that. If you're dealing with variable-sized arrays you can't use that method in the first place because LabVIEW does not store arrays in memory the same way as C.
As to your code: I believe you are referring to the Array Test VI, since that's the one that calls the AOS_GetData_Array_GH function. You are not following what the "Call DLL" example does. I have no idea why you're interleaving the floats and the integers. The Reshape Array function is first used to make sure you have an array that's the same size as the fixed-size array in the target structure. Thus, in your case both arrays would be "reshaped" to 3 since that's the size as defined in the structure. This is then converted to a cluster. This is the "repackaging" part. Each element of the cluster is then bundled into a new cluster. This makes sure that the bytes are in the expected order. This new cluster is what the DLL will receive. Please look at the "Call DLL" example in more detail.
01-29-2010 10:34 AM
smercurio_fc wrote:The Reshape Array function is first used to make sure you have an array that's the same size as the fixed-size array in the target structure. Thus, in your case both arrays would be "reshaped" to 3 since that's the size as defined in the structure. This is then converted to a cluster. This is the "repackaging" part.
Haven't looked at the code but I don't think reshape Array is necessary. The Array To Cluster node has a right click popup dialog that defines the element size of the clusterindependant of the actual size of the incoming array.
01-29-2010 10:51 AM
Guys,
Thanks for the help again. It finally works. I attached a jpeg with the solution that works. The key was to specify how many elements were in each array which is done by right clicking on the array to cluster function (thanks Rolf).