orko Posted June 15, 2006 Report Share Posted June 15, 2006 Hello all, I'm familiar with passing simple integer and string values into CINs, but I'm just getting started with passing structures and would appreciate a helping hand. My dll has a structure as follows: typedef struct test { int num; unsigned char name[4]; int dnum[16]; unsigned char flet; char aname[16][256]; } Test; I'm trying to build a typedef'd cluster control that I can use to pass data in and out of a function in my DLL that uses the above. I had fairly good luck in doing this with another structure that held only integer returns (no arrays), but I haven't been able to get this one nailed down. I believe I have the first three controls set up correctly in the typedef cluster: Element1: I32 Element2: cluster of ( 1D array of U8 with field length set to min length=4, padded with zeros ) (can I just use a string here?) Element3: cluster of ( 1D array of I32 with field length set to min length=16, padded with zeros ) Element4: U8 If this is wrong, please correct me. I may be confusing the field length minimum setting with the maximum entries in the array(?) The fifth element being a 2D array of char is throwing me for a loop however. Since this is an array of char with each element having a max length of 256 and a max array size of 16 elements, I tried having 16 more elements in my typedef like the following: Element5: cluster of ( 1D array of U8 with field length set to min length=256, padded with zeros ) ... Element20: cluster of ( 1D array of U8 with field length set to min length=256, padded with zeros ) LabView has crashed on me every time I tried to use this however, so I must not have this set up correctly. I've attached my typedef (LV 8.0.1). Could someone point me in the right direction (help stamp out the obvious bugs)? Download File:post-3266-1150395023.ctl -- orko Quote Link to comment
bsvingen Posted June 15, 2006 Report Share Posted June 15, 2006 2D arrays in C are not "ordinary" 2D arrays, but an array of pointers to arrays (pointers to pointers to whatever). Labview stores 2D arrays as 1D contiguous block of memory, or as a 1D array. The only difference between 2D and 1D array in labview is an extra long int that hold the second dimension. Quote Link to comment
Rolf Kalbermatter Posted June 16, 2006 Report Share Posted June 16, 2006 Hello all,I'm familiar with passing simple integer and string values into CINs, but I'm just getting started with passing structures and would appreciate a helping hand. My dll has a structure as follows: typedef struct test { int num; unsigned char name[4]; int dnum[16]; unsigned char flet; char aname[16][256]; } Test; I'm trying to build a typedef'd cluster control that I can use to pass data in and out of a function in my DLL that uses the above. I had fairly good luck in doing this with another structure that held only integer returns (no arrays), but I haven't been able to get this one nailed down. You got quite a bit wrong here! First the arrays you have are all fixed size so they are inlined as such and represent nothing like a pointer. You would need a cluster with following setup: int32 num cluster of 4 uInt8 name cluster of 16 int32 dnum uInt8 flet cluster of 16 * 256 uInt8 aname Especially the last one is not very convinient to do and I personally would treat the entire structure as an array of unsigned bytes passed as a C array pointer and write VIs that insert an retrieve the according information from that byte stream. Rolf Kalbermatter Quote Link to comment
orko Posted June 19, 2006 Author Report Share Posted June 19, 2006 You got quite a bit wrong here! Yes, I realize it's all wrong. I have yet to wrap my brain around the differences between C and LabView data structures, so I decided to post what I had so far "kludged" together. Better in my mind than to post a generic, "can anyone give me my answer?" post. First the arrays you have are all fixed size so they are inlined as such and represent nothing like a pointer. Okay, arrays won't work for passing data inside the clusters because LabVeiw handles array data differently, correct? But I could use an array to build the data in LabView, then pass it to "Array to Cluster.vi" to build up the cluster you define below? I am unfamiliar with what you mean by "inlined". Could you expound on that? You would need a cluster with following setup:int32 num cluster of 4 uInt8 name cluster of 16 int32 dnum uInt8 flet cluster of 16 * 256 uInt8 aname Especially the last one is not very convinient to do and I personally would treat the entire structure as an array of unsigned bytes passed as a C array pointer and write VIs that insert an retrieve the according information from that byte stream. I wouild really like to understand the last element, since it gave me the most trouble. I may re-write the dll's handling of data like you suggest, but foresee having to be able to interface with pre-defined dll's that I do not have the source to, so let me take a stab at your example setup: char aname[16][256]; // LabView: cluster of 16 * 256 uInt8 aname So you are saying I could define a single cluster with 16*256 = 4096 uInt8 numeric indicators? disregarding the size (which I can see would be *very* inconvenient) does this just have to do with how C stores 2-dimensional char array data? Basically a single block of 8 bit data values representing the 16x256 matrix then. How then would the data be indexed correctly for C? Is it as simple as the value of aname[0][0] as the first block, followed by aname[0][1]...[0][255], then aname[1][0]...[1][255]? How would char* arr[arrrSize] data (as in a list of pointers to strings) be handled? Would that just be a cluster of arrSize x u8Ints with "Pointer to value" as the "Pass" parameter in the CIN? I suppose I would have to add the NULL byte to the array, so it would actually be a cluster of (arrSize + 1) x u8Ints? Thanks again, I would really like to understand this correctly so I'm not guessing next time Another Question: Is this information covered completely in NI's LabWindows course? Or perhaps in the Intermediate or Advanced courses? I'm planning out my training for the year and am trying to prioritize. BTW, I just tried to create the typedef control with the 4096 indicator cluster and it broke the cluster display in the front panel ;-) Attached. Download File:post-3266-1150728048.ctl -- orko Quote Link to comment
Rolf Kalbermatter Posted June 26, 2006 Report Share Posted June 26, 2006 I am unfamiliar with what you mean by "inlined". Could you expound on that?I wouild really like to understand the last element, since it gave me the most trouble. I may re-write the dll's handling of data like you suggest, but foresee having to be able to interface with pre-defined dll's that I do not have the source to, so let me take a stab at your example setup: Inlined means that a C compiler will simply reserve the necessary amount of bytes for any fixed size data element in the structure itself. An example struct { int val1; int array[]; } will represent a structure with 8 bytes length first the val1 integer and then a 32 bit pointer struct { int val1; int array[100]; } will represent a structure with 404 bytes length, again the val1 integer and the 100 array elements directly following. Similarily an array int arr[10][10] inside a structure will represent a memory area of 400 bytes (10 * 10 * 4 bytes) directly in the structure. In LabVIEW you would create a cluster of 100 integer elements for this. An array int arr[][] would really mean a pointer to an array of pointers instead. In C multidimensional arrays are a little bit strange if not to say inconsistent. As you can see fixed size arrays look in the organization similar to what the data area of a LabVIEW array does (but a LabVIEW array is always a handle to the data) while non-fixed size multi-dimensional arrays are really hard to deal with. Element1: I32 Element2: cluster of ( 1D array of U8 with field length set to min length=4, padded with zeros ) (can I just use a string here?) [\quote] No a LabVIEW string is always variable sized (except in some embedded development environments) and therefore a handle, so creating a cluster with a string inside will always create a C structure that no normal C code will be compatible with. You could teach your C code to deal with LabVIEW data types directly but that usually requires a good understanding of the LabVIEW datatypes (generally you should have read the External Code Reference Manual from the cover page to the last page ;-) and understand most of it too) Rolf Kalbermatter Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.