LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Crash when passing a structure into a call library function node

Solved!
Go to solution

 

     I'm trying to use a Fortran type (which I think is similar to a struct) in a LabVIEW call library function node.  I've been reading a few recourses on it, but I'm not entirely sure if I need to add the name of the structure to the node's parameter list.  Right now, when I run my VI it just closes LabVIEW entirely with no message.  I've attached the VI, that I'm using and the fortran source code, that compiles into my .dll. 

 

Any help is appreciated.

Download All
0 Kudos
Message 1 of 7
(2,567 Views)

I know nothing about Fortran but have some experience calling DLLs from LabVIEW, and I think you need to pass each element of the arrays (VelocityVehicle, VelocityWind) as separate parameters.  LabVIEW passes arrays by pointer because in LabVIEW, arrays can have variable size.  In your Fortran code you declare them as fixed size, so they are stored inline with your structure.  The corresponding LabVIEW type for a fixed-size array is a cluster of identical elements, but since you are passing the cluster by value you need to pass each element individually.

 

If you were to change this to pass the cluster by reference, you would need to replace the LabVIEW arrays with clusters containing the right number of elements to match the fixed-size arrays in your Fortran code.

Message 2 of 7
(2,560 Views)

Thanks for the tip.  I'm going to try this.  Something I'm still not exactly sure about though is do I need to include the name of my structure in the library node parameter list?  Right now, I just have each element of the structure included in the list, but should I have the name of the structure included as well?  I haven't yet seen a good example of this when searching through boards.

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

I tried replacing the arrays with clusters and have attempted to pass each element by itself into my library node, but I still get the same behavior, with pretty much none of the values coming through correctly.  I've re-attached the .vi as it is now.

0 Kudos
Message 4 of 7
(2,539 Views)
Solution
Accepted by topic author adams156

Do you know if Fortran passes parameters by value, or by reference?  I've never used it.  A really quick internet search suggests that parameters should be passed by reference.  If this is the case, then you need to pass the entire cluster as a single parameter, similar to the Fortran declaration.  You also need to rearrange the cluster order to match the order in the Fortran declaration.  Try the attached VI.

Message 5 of 7
(2,532 Views)

I think that's got it, and it's much simpler than the way I was trying to do it!  As soon as I adjusted the order and the representation on the values in the program you attached, it worked just fine.  Thanks a lot for your help.  I was also going to ask real quick about kudos on this forum.  All of your posts in this thread have been relatively helpful, so would it be appropriate for me to put kudos on all of them, or just the one that I mark as a solution?

0 Kudos
Message 6 of 7
(2,514 Views)

I'll take all the kudos I can get! 🙂

I don't know if there's any definite etiquette, and I've never investigated what value Solutions have versus Kudos.  Certainly no one is going to call you out for your kudos habits, but marking solutions correctly is appreciated.

Message 7 of 7
(2,510 Views)