--5515485.1076332199448.JavaMail.quiq.tekken
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
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 =BFHow 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
--5515485.1076332199448.JavaMail.quiq.tekken
Content-Type: application/octet-stream; name=foo_wrapper.c
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=foo_wrapper.c
Content-Description: This is the code that does nor work
/*
* MATLAB Compiler: 3.0
* This file foo_wrapper.c */
#include "matlab.h"
#include "foodll.h"
#include "matrix.h"
#include <stdio.h>
//main wrapper function definition
double wrapper_main (void){
//declare variable to deliver result
double out;
double *in1;
FILE *far;
//Create two pointers of mxArray type to store inputs and outputs
mxArray *in1_ptr, *out1_ptr;
//Allocate input pointer to a 1 by 1 double, real matrix
in1_ptr = mxCreateDoubleMatrix(1,1,mxREAL);
far = fopen ("num.txt","r");
fscanf (far,"%lf",in1);
fclose (far);
//Move the data from the input to the pointer
fill(mxGetPr(in1_ptr),in1,1);
//Initialise foo implementation
foolibInitialize();
//Pass values to mlfFoo and receive in mxArray type variable
out1_ptr = mlfFoo(in1_ptr);
//Terminate foo implementation
foolibTerminate();
//Move from mxArray type to double type
fill(&in1,mxGetPr(out1_ptr),1);
//move data to output variable
out = *in1;
//Return value
return(out);
}
void fill(double *out, double *in, int size){
//This function moves data from one type to another
int i;
for(i=0;i<size;i++)
out[i] = in[i];
}
--5515485.1076332199448.JavaMail.quiq.tekken--