LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrive array elements from the cluster using CLN

HI,
I have a structure with two arrays of each size 16 elements. I need to retrive the values into these arrays from the CLN through stdcall(WINAPI) along with the other inputs to the CLN. I'm facing problem only with this cluster of arrays.
 
struct {
unsigned char array1[16];
unsigned char array2[16];
} tagstruct;
 
I'm attaching the Front panel and Block dgm
Download All
0 Kudos
Message 1 of 6
(3,456 Views)


@Padmavathi.B wrote:
HI,
I have a structure with two arrays of each size 16 elements. I need to retrive the values into these arrays from the CLN through stdcall(WINAPI) along with the other inputs to the CLN. I'm facing problem only with this cluster of arrays.
 
struct {
unsigned char array1[16];
unsigned char array2[16];
} tagstruct;
 
I'm attaching the Front panel and Block dgm


These arrays are fixed size. So in fact this entire structure can also be treated as a pointer to a 32 byte character buffer. Just create a 32 byte character string (or a 32 byte unsigned Byte array) and configure the CLN parameter to be a string (or array of 8bit unsigned integers) and to be passed as C pointer.

Rolf Kalbermatter 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 6
(3,439 Views)
Hi,
I have used with array of unsigned char and configured the CLN as array of Unsigned char and put the array format as array data pointer
My system is getting restarted when i run my application .
 
using strings (as u have mentioned) i have not tried because i don't know how to limit the string control to 32 characters.Could u please tell me how to do that, sothat i can try like that in my application
0 Kudos
Message 3 of 6
(3,422 Views)


@Padmavathi.B wrote:
Hi,
I have used with array of unsigned char and configured the CLN as array of Unsigned char and put the array format as array data pointer
My system is getting restarted when i run my application .
 
using strings (as u have mentioned) i have not tried because i don't know how to limit the string control to 32 characters.Could u please tell me how to do that, sothat i can try like that in my application


When calling a C function that takes an array (or any pointer for that matter) the CALLER (yes the CALLER) is responsible to allocate the array or pointer to the size the function does expect to be able to read from or write too. And no, LabVIEW can not do that for you automagically as only you as programmer can and should know what your particular function expects.

So create an array with the Initialize Array function and make sure it contains at least 64 elements of unsigned 8bit integers. The next thing that can bite you is the calling convention and again only you as the programmer can possibly know that (usually from the documentation for your function or often you have to consult the header file that came with your DLL (and some basic C knowledge would be very helpful in that case).

Remember when you want to deal with the Call Library function in LabVIEW you will have to know a bit about C programming. Most DLLs are meant to be called from C mainly and often the DLL creator has done nothing to document it for anyone trying to use it otherwise.

Rolf Kalbermatter

Message Edited by rolfk on 01-12-2007 09:07 AM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 6
(3,413 Views)
Hi,
Tanq for ur help my application VI is working correctly.
A small clarification needed
If the structure consists of array elements then we can initialize the array and get the details from the CLN
but if the structure consists of both array elements and the controls then what is the procedure i.e
 
Struct {
unsigned char array1[8];
unsigned short numeric1;
unsigned char numeric2;
unsigned char array2[5];
}tagStruct;
 
How can i do this in labview sothat i can get the values into these structure members from the CLN
0 Kudos
Message 5 of 6
(3,405 Views)


@Padmavathi.B wrote:
Hi,
Tanq for ur help my application VI is working correctly.
A small clarification needed
If the structure consists of array elements then we can initialize the array and get the details from the CLN
but if the structure consists of both array elements and the controls then what is the procedure i.e
 
Struct {
unsigned char array1[8];
unsigned short numeric1;
unsigned char numeric2;
unsigned char array2[5];
}tagStruct;
 
How can i do this in labview sothat i can get the values into these structure members from the CLN


No difference really. As long as the array is fixed size it is embedded in the structure and the entire structure is just a single byte stream that can be represented as an array. The difficulty with your new example is to figure out the size of each sub part and account for possible padding.

The specific example you provide has no padding issues though so you will get a byte array of 8 + 2 + 1 + 5 = 16 bytes. The trouble is however to insert the data at the right place and in the right way into that byte array (Endianess can get into the picture here) using the right offset or retrieve it afterwards from it.

The issue is different if the array is not fixed sized such as in :

Struct {

unsigned short numeric1;
unsigned char numeric2;
unsigned char array[];
}tagStruct;
 
Here the array variable is just a pointer and LabVIEW has no direct way of supporting this since LabVIEW does not use pointers but handles instead for arrays and strings. The best solution for such cases is to create a wrapper shared library that translates between such structures and more LabVIEW friendly parameters, but then you really have to know C.
Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 6
(3,397 Views)