LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fortran Dll in Labview

Hello, I'm new to LabVIEW and relatively new to Fortran as well.  I'm currently attempting to use the "Call Library Function Node" to use a Fortran .dll that I have written.  I'm passing several values into the library node and would like to see them updated by the subroutine I've selected so that they will come out the other side of the node with new values.

 

Currently, when running the VI, I receive an error "Error 1097 occurred at Call Library Function Node in MyDllTest.vi".  I've tried selecting both types of calling conventions, but it doesn't seem to make a difference.  Also, the values that I input into the dll block simply come out the other side untouched.  I am able to pick my subroutine as an option when setting up the dll node, but I've had to add all of the variables manually.  I'm not sure if that's correct behavior or not.

 

I have attached both my .vi and my Fortran code.

Download All
0 Kudos
Message 1 of 11
(4,203 Views)

Hi adams156, 

 

The error is saying that there is something wrong with your fortran code. I would check your data types. I don't know if fortran considers a logical to be an integer. 

 

There is an example on this page you might find useful:  

http://forums.ni.com/t5/LabVIEW/Calling-compaq-visual-fortran-dll-from-labview/td-p/148244

 

Lastly, filling in the parameters yourself is expected for this type of dll. 

 

 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 2 of 11
(4,160 Views)

Thank you for your response.  That forum post is actually the guideline that I was going by when I started this project.  In order to check the fortran code, I went so far as to write a main function and compile it as an executable.  It compiled and ran succesfully. 

 

As far as the logical to integer conversion goes, I couldn't find a "Type" in the call library function parameter settings that corresponded to bool or logical or anything such as that.  Integer was the closest type I could find, and some other user recommended it as well.  Maybe that is where the problem lies though, and I may need to use some other data type to represent my logical.

0 Kudos
Message 3 of 11
(4,156 Views)

Hi adams,

 

Could you change the logical it to an integer in your fortran just to double check whether that is the problem? 

 

Also, you might try parsing down your subroutine to just a couple of values and work up from there.  

 

Let me know how it goes. 

 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 4 of 11
(4,154 Views)

I may try that, but for now, I actually tried passing the boolean as "Adapt to Type".  That has gotten rid of the error, though the code still doesn't function as intended.  I'll look at it for a while and let you know what I figure out.

0 Kudos
Message 5 of 11
(4,151 Views)

I've been working at this today, and I seem to have it working aside from the boolean.   I simply took the boolean out of the Fortran and the vi and everything worked fine.  Apparently, I've yet to find the appropriate way to designate a Fortran boolean variable in the call library function node.

0 Kudos
Message 6 of 11
(4,133 Views)

Good morning adams156, 

 

 

I think that how booleans are stored is specific to each language, you would have to track it down for your version of Fortran. It might be easier just to store it as an integer. The discussion below hits on this for c: 

http://lavag.org/topic/3433-return-boolean-from-c-dll-to-call-library-function-node/

 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 7 of 11
(4,131 Views)

I think I finally have it!  I start off with a boolean in the .vi which I then type cast to a 4 byte signed integer (turns out that's what a default fortran logical is), and feed that into the call library node, which is expecting a 4 byte signed integer.  Everything seems to be working great now.  Thanks for your help.

0 Kudos
Message 8 of 11
(4,121 Views)

Good to hear!

 

Would you mind posting your working example so other people who come across this thread can use it? 

 

 

Take care

Jesse Dennis
Engineer
INTP
0 Kudos
Message 9 of 11
(4,113 Views)

This should do it.  The Source1.txt was an .f90 file but I couldn't use the attachment system to put it up here with that extention.

Download All
0 Kudos
Message 10 of 11
(4,086 Views)