Bonjour a tous !
Voila, actuellement je developpe des mex-Files dans le cadre de mon stage. J'ai un petit probleme pour passer un string de la fonction mex vers Matlab workspace. J'arrive a faire l'operation en convertissant le string en double puis passer un scalaire de mex vers Matlab.
Voici mon code:
Voila, mais ca ne marche pas ! En fait j'ai bien en retour de la fonction ReadSCReply le string BoardID mais quand je veux faire passer ce string vers Matlab dans la fonction mexFunction, ben j'ai un tableau contenant '0' dans Matlab.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 /* Les includes + declarations annexes */ void read_ID(int maxlen, char *boardID) { /* BoardID data */ char *BoardID; BoardID = (char *) malloc(maxlen * sizeof(char)); //create variables for your function ReadSCReply Read_SC = NULL; HINSTANCE lib = NULL; lib = LoadLibrary("BoardHandler.dll"); if (lib) { /* Receive Reply from SC */ /* Appel a une fonction de la librairie BoardHandler.dll */ Read_SC = (ReadSCReply) GetProcAddress(lib,"ReadSCReply"); Read_SC(0, replyLengthCommand, ReceiveBlock, &result); if (result == 0) { mexPrintf("Board ID: %s\n",BoardID); *boardID = *BoardID; /* Je veux faire passer le string BoardID vers Matlab */ /* BoardID vaut en retour de l'appel: */ /* BoardID = "0404100300" */ } } else mexPrintf("Library not loaded !\n"); } /* Matlab Mex Gateway Function */ void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { /* Check for proper number of arguments. */ if (nrhs != 0) { mexErrMsgTxt("No input required."); } else if (nlhs > 1) { mexErrMsgTxt("Too many output arguments"); } /* create a new char array*/ char *BoardID; int maxlen = 11; BoardID = (char *)mxCalloc(maxlen, sizeof(char)); /* Call the C subroutines */ read_ID(maxlen,BoardID); /* Send the string to Matlab */ plhs[0] = mxCreateString(BoardID); }
J'espere que je me suis fais comprendre ?
N'hesitez surtout pas a me demander plus de precisions.
En tout cas, j'attends avec impatience vos reponses les amis !!!!
Partager