LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a "fopen" call in a DLL made with MatLab for Labview

Dear Sirs:

My name is Juan Crespo and I write you from Spain. I answer if you could help me with a Labview problem. This is the problem.

I want to write a DLL for being used in labview, and i want to use matlab for write this DLL. I have been searching in the web and reading the NI "using external code in labview" manual in order to know what I must do.

I know that if I want to use MatLab, I must build a "wrapper function" to avoid the different data type between MatLab and C. I have found on the web -Thanks to Alberto Sanchez- one example about how could a DLL could be written.

But it exist one diference: I want to read a plain text file that has the input data. so I must read the file, store
the data in an array and then pass this array to the "interface functions" but in a simple example this dont works

My question is ¿How could I open a text file in order to use it as input data in a DLL in Matlab?

Attached to this message is the code I use as "wrapper function". when I compile it there is no apparent errors, but when I try to use the DLL in a VI, an error appears.

If I change this code and the input is made "manually" (using the VI) there are no errors. So I think that problem is in the way that Labview consider "fopen" function when I build a DLL. The "num.txt" file, where the data input are, is on the same directory that dll file and VI file.

I hope that you can help me with this problem.

Thank you very much in advance and please sorry for my bad english

Best Regards


Juan Crespo
0 Kudos
Message 1 of 2
(2,974 Views)
Dear Juan Crespo,

normally I don't answer questions concerning Matlab because I have no experience with it. But your question was waiting a long time and had to do something with DLL I decided to look at it.

Your C code has a serious error. You are declaring a variabale named "in1" as "double *". You do not set this pointer to point to a variable. Then you use this uninitialized pointer in the fscanf function to read in from the file. The value is written somewhere in the address space at a place where "in1" is pointing randomly. This will cause an error or crash.

Declare "in1" as "double" like you have declared "out". You must change some other places where you have used "in1".

Waldemar writing from Germany
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 2
(2,974 Views)