LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

structure datatype in c to cluster in labview

Hi
i attached my doubts regarding structures,i need relevant cluster to be taken out as output,is it only using wrapper function is only mean,if there any other example(except from ni website),it would be morehelpful

typedef struct MemBlockStruct {

                        unsigned long absaddr;

                        short  status;

                        unsigned short size;

                        unsigned short gp;

                        unsigned short condition;

                        struct MemBlockStruct *next,*prev;

                        unsigned short count; //msgcount

                        unsigned short blkstatus;

                        unsigned short timetag;

 

            } *MemBlockHandle, MemBlockType
 
Thanks and Regards
0 Kudos
Message 1 of 8
(6,152 Views)
Hi,
 
You can find an example in the labview examples call Call DLL.vi. In the NI Example Finder, use dlls for the search parameter.
 
For the Data Type look at Complex Cluster.
 
Hope this helps
Regards
Ray Farmer
Regards
Ray Farmer
Message 2 of 8
(6,140 Views)

Hi

i keep checking labview call dll example,but my issue is "i don't how to deal with winnt.h files HANDLE datatypes and calling  structure within same structure like that,if there is any other example.it would be more clear.

thanxs and regards 

0 Kudos
Message 3 of 8
(6,126 Views)
Handles are usually nothing but long integers (I32 or U32).  Since the C structure contains another structure as one of its memebers, this will be quite complex.  Your LV cluster must contain another cluster.  You need to unbudle your main cluster into its elements.  The inner cluster must also be unbundled.  All 1D arrays must be converted to clusters (Array to Cluster function).  Hope you don't have 2D arrays, they must be separated into 1D arrays and converted to clusters.  Strings must be type cast into U8 array and then converted to cluster.  After unbundling all and converting, rebundle in the same order.  Pass the final cluster into the DLL parameter and set for Adapt to Type.  Reverse the process to get the return value from the DLL.  This is a mess, but it works.
 

Message Edited by tbob on 11-30-2005 09:34 AM

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 8
(6,114 Views)
Hi tbob
i done as your told,now labview is not crashing ,but it through error as CLF  particular Node error, i attached my required structure format and all detail, For Handle and Handler definition is taken from windows header file winnt.h,i want clarify the error problem.
 
Thanks and regards
0 Kudos
Message 5 of 8
(6,081 Views)
Hi tbob
i tried as you told,but still problem exist as i mentioned in issues_CLF.doc,let me know where my cluster format get hit for the following structure format
typedef struct
{
 int NodeNumber;
 int NodeType;
 int CardNumber;
 int IsFree;
 HANDLE hDevice;
 int LogicalNode;
 unsigned long ISABaseAddr; 
 Handler isr;
}NodesInfo;

Message Edited by Anu RVK on 12-23-2005 05:59 AM

0 Kudos
Message 6 of 8
(6,009 Views)
Let me start by saying that you are off the path, over the guard rail and leaning over the cliff...this kind of calling from LV is very difficult to get right and you are much better off creating a wrapper DLL that exposes an API that is "friendlier" to LabVIEW and do the structure manipulation within the wrapper DLL. I've posted before about the dangers of the byte alignment, data types and pointers, but let me just focus on a couple things here.
 
First - to correct a misunderstanding about the original data structure - there is no cluster contained within a cluster. The MemBlockStruct does not contain another cluster, but instead has a pointer to clusters. This is not something that you can recreate in LabVIEW as there are no pointers. You can replace the pointer entries in the cluster with int32 values, but that is all. If you define a cluster within a cluster in LabVIEW, the memory is contiguous. That is not the case with MemBlockStruct. (Note this also means in the GetNodeInfo that you don't need to wrap the HANDLE integer in a cluster - it is just an integer.
 
Second - The example VI image you have shown uses dbl types as the elements of your cluster. The C structure calls for integers. This means that it expects the elements in the structure to be 32-bits long, and the LabVIEW structure is defining them to be 64-bits. This means that the data fields are not going to line up correctly.
 
I'm going to get quite a reputation on this board by always being so negative about cluster->structure mapping, but it is only because I'm looking out for you. If you do just the slightest thing wrong, and are lucky, then you end up with that error message. If you are not so lucky, then you end up with a memory corruption that might not show up for minutes, hours or days later. This is one of the reasons why people like LV over C/C++ - these kinds of memory errors can be nightmares...I know - I've been there.
 
So, I'll just sign off with a plea to go with a wrapper DLL if at all possible. I know that this is sometimes difficult due to needing to create some C code and building it into a DLL, but you'll save yourself a ton of heartache later.
 
 
Message 7 of 8
(5,978 Views)
Sorry to be responding so late.  I've been off for a week.
 
Your problem is that you are using the wrong data types in your cluster, as pointed out by Lycangeek.  The C structure is using "int" and your corresponding cluster element is "DBL".  You need to use the same data type.  Short Int or Int in C corresponds to I16 data type in Labview.  Long Int is I32.  Byte or char is I8.  Unsigned anything is U instead of I (Unsigned char is U8).  Handles are U32.  If you use the correct data types you should have no problems.  I'm surprised your system didn't crash.
 
I have noticed that in your first post, your structure had a pointer to another structure.  If this is the case, you would be wise to write a wrapper DLL as Lycangeek suggested in his post.  There is no way pass a cluster which contains pointers to other structures. 
 
My rule is that if the structure is simple enough (no pointers to other structures and no 2D arrays with large number of rows), I use the conversion technique that I posted.  If the structure is more complex, I would write a wrapper DLL or use a CIN.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 8
(5,930 Views)