LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll struct to LabVIEW cluster

Solved!
Go to solution

Nathand> are there any white papers/articles on this as I am about to hit a similar problem. Thankfully i created the dll so have a bit more control over the data types I use

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 11 of 17
(2,646 Views)

Thank you, nathand, for your help. I will try to do this. Your explained way seems to be legit 🙂

0 Kudos
Message 12 of 17
(2,644 Views)

Nathand, here is the code, maybe you could show me, what do you mean by saying adding 3 bytes and 2 bytes. The thing is, that I am trying to connect to device and read the values of photodiode and use them with motor sync. But the main problem, is to read that struct.

0 Kudos
Message 13 of 17
(2,641 Views)

Also, my header file does not includes a #pragma pack() line.

0 Kudos
Message 14 of 17
(2,633 Views)

I fixed it! Everything is working perfectly, the problem was that short, char or int should be set to u32.

 

Thank you all for your help!

0 Kudos
Message 15 of 17
(2,620 Views)

@SimasLTU wrote:

I fixed it! Everything is working perfectly, the problem was that short, char or int should be set to u32.

 

Thank you all for your help!


Yes, this will have the same effect as adding padding because it will force all elements to be aligned as though they're long (4-byte values).  This won't always work, but in your case it does due to the way your struct is arranged.  You might find that some values aren't where you expect them to be, though (the short values might end up in the high 2 bytes instead of the low 2 bytes).  If the char and short parameters return values larger than those types can hold when you represent them as a U32, then you need to look at whether the data is in the correct byte.

Message 16 of 17
(2,615 Views)

@Akiel wrote:

Nathand> are there any white papers/articles on this as I am about to hit a similar problem. Thankfully i created the dll so have a bit more control over the data types I use


I don't know of any one white paper that covers everything, but there are certainly links available that will help.  Start with an understanding of struct packing and alignment; an internet search on the "#pragma pack" compiler directive will help (MSDN is usually a good source).  These two links on the NI site are useful: How LabVIEW Stores Data in Memory and Clusters in LabVIEW Do Not Line Up With Structures in Visual C++.  Also, RolfK has contributed many posts on this topic to this forum, which you may find by searching the forum for "dll alignment."  I find that I often get better results from a Google search for "site:forums.ni.com dll alignment" than I do with the forum's built-in search.

0 Kudos
Message 17 of 17
(2,608 Views)