LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

unbundle c structure

Solved!
Go to solution

Hi,

I am currently trying to unbundle a C structure.

The normal create a cluster witht he same items as the struc works, but the sturcture might be subjected to changes and that would brake my programm.

is there a way to call the elements by name?

0 Kudos
Message 1 of 7
(3,514 Views)

You have a cluster in LabVIEW now?  Look at Unbundle by Name to pull things out of that cluster by name.

0 Kudos
Message 2 of 7
(3,503 Views)

i did think of that but it didnt work

0 Kudos
Message 3 of 7
(3,500 Views)
No. The C data is just a series of bytes in memory; there's no way for LabVIEW to know anything more about the structure automatically. The same is true between two C programs (or a program and a DLL) - if a data structure changes in one, you need to update the other to match (maybe just a recompile).
0 Kudos
Message 4 of 7
(3,471 Views)
Solution
Accepted by topic author Eumel2

You're calling a C function and that returns a struct, correct?

 

You think that the struct could change and you will need to handle that, correct?

 

 

The obvious answer is to update the code. Make the cluster a typedef and modify it manually when you get a new DLL which has the new version of the struct.

 

If for some reason that is not possible, you can also pass in an array of bytes (1D U8) of the correct size, let the C function fill up the values of those bytes and then read the relevant bytes from the array and convert them to the specific data you want. This will require you to understand both how LV stores data, how C stores data, how alignment works and be familar with the data conversion option in LV, like type casting and byte swapping. It will also be more brittle, so I would suggest going with the first option.


___________________
Try to take over the world!
Message 5 of 7
(3,467 Views)

Not the answer i had hoped to hear but thank you guys

0 Kudos
Message 6 of 7
(3,422 Views)
If you expect the structure to change frequently, and you have the ability to modify the C program, you could pass the data as a XML or JSON string. This will be allowed to parse, but would allow you to find a particular item by name.
0 Kudos
Message 7 of 7
(3,396 Views)