LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How would this code look in LabVIEW?

Hello,

 

I am new to LabVIEW and I'm hoping that someone can tell me what the code would look like in LabVIEW if I want to do the following.....

I am using a C dll that has the "acq_get_board_count()" function and so far I am able to get that to work, however I'm having issues with passing the array of clusters from LabVIEW to the C dll

 

 

 

short count , code;

MyStruct_board_info *board_info_list;

count = acq_get_board_count();

if (count)

{

board_info_list = new MyStruct_board_info[count];

code = acq_get_board_info(count, board_info_list);

}

else

{

// no interface card installed

}

******************************************************************************* 

 

my C structure looks like the following:

struct MyStruct_board_info

{

char name[32]; 

short type;

char en_first_gain; 

long first_gain_min; 

char computer_ctrl;

char pad[3]; 

};

0 Kudos
Message 1 of 9
(3,004 Views)

I am assuming that the prototype for your called function looks something like this:

 

short acq_get_board_info(short count, MyStruct_board_info * MSBI);

 

DLL interfacing is a little complex and is not an exact science.  Some playing around to get it right will be needed.  I am going to guess that you will need to define a cluster that has the same data types as your struct and the same sizes (add them to the cluster in the same order as the struct definition).  I think short's will be 16-bit ints, char's are 8-bit ints.  The array (char name[32]) you will have to pre-dimension for each element in the array of clusters so that the array memory exists.

 

To pass this to the dll, use flatten to string (numeric...data manipulation).  Convert the string to an array of bytes (string...conversion...string to byte array) and pass an array pointer to your dll.  Unflatten on the receiving end to get the results.

 

-cb

Message 2 of 9
(2,983 Views)

Also have in mind problems due to different Endianness. This may apply to all values larger than a byte

http://en.wikipedia.org/wiki/Endianness

Message Edited by Coq rouge on 06-24-2009 08:14 AM


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 3 of 9
(2,956 Views)

hey cb,

 

Thanks for the feedback, also you are correct on the prototype for the called function.

 

I have a cluster setup with everything, for the array (char name[32]) I think I have it pre-dimensioned......I created a string and on the block diagram I attached a constant with 32 characters to the string...is this how I would do that?

 

I'm a little confused on what exactly to flatten to a string, should I just flatten the string (my char name[32]) or should I flatten the entire cluster?

 

 

Thanks again,

-ck

0 Kudos
Message 4 of 9
(2,911 Views)

I think the string thing you are talking about will work.  You might also try to represent the name[32] field as a byte array.  Look at the attached picture.  You may need to unbundle each item in each cluster (loop through the array), flatten them to strings, and concatinate to one string as you go.  I did not see a way around LabVIEW including the name[] array's size (4 bytes that would break your dll) when the entire cluster is flattened.  As I said before, this dll stuff is not an exact science.  I will try a few things here and let you know if I find something different.

-cb

0 Kudos
Message 5 of 9
(2,895 Views)

You probably want to use typecast, not flatten to string.  However I'm not sure either of those are necessary.  See if using the Adapt to Type option works for you, as shown in the attached code.  Note that I added an extra byte of padding in the middle of the structure, before first_gain_min, in order to maintain alignment; I'm not completely certain if it's necessary.

MyStruct_board_info.PNG

0 Kudos
Message 6 of 9
(2,877 Views)
One edit to my previous message - before you try that code, reconfigure the call library node so that the parameter "MyStruct_board_info" has data format "Array Data Pointer" (I accidentally left it set to something else before uploading).
0 Kudos
Message 7 of 9
(2,852 Views)

One trick I found is to right-click the call library function node and select "create .c file" and examine what it will create.  I used the method that nathand used to generate the cluster using array to cluster to embed the array contents as values.  After you build the array of clusters, I think you will have to pass in element zero.  If you pass in the whole array and look at the c-code, it will still embed a 4-byte size field in the struct and this will whack your dll.

 

Use adapt to type in your call library function node.  The pictured code generates the following c-code:

 

/* Call Library source file */

#include "extcode.h"

/* Typedefs */

typedef struct {

double Array0;

double Array1;

double Array2;

double Array3;

double Array4;

double Array5;

double Array6;

double Array7;

double Array8;

double Array9;

double Array10;

double Array11;

double Array12;

double Array13;

double Array14;

double Array15;

double Array16;

double Array17;

double Array18;

double Array19;

double Array20;

double Array21;

double Array22;

double Array23;

double Array24;

double Array25;

double Array26;

double Array27;

double Array28;

double Array29;

double Array30;

double Array31;

} TD2;

typedef struct {

TD2 Array;

uint32_t Numeric;

} TD1;

void CIELChToDE94(TD1 *arg1);

0 Kudos
Message 8 of 9
(2,845 Views)

nathand,

 

I've tried doing it your way and believe that it might be working, I'm using a device simulator to try this VI out on and I don't get any of the values for the board, but I am getting an error code that is being returned from the dll. I am going to call the vendor tomorrow to see if there might be an issue with the simulator.

 

 

10Degree,

 I'm also still trying to accomplish this the way you mentioned, but I'm very new to labVIEW and I'm kind of confused on the flattening to string and converting the string to an array of bytes.....are you meaning that I should flatten the cluster to a string and then convert that to an array of bytes or just the char array name?

 

Thank you both for your help, I understand that the interfacing just takes some time to play with....but its not helping anything that I'm so new to the LabVIEW technology....thanks for the guidance.

 

-ck

0 Kudos
Message 9 of 9
(2,810 Views)