source: MML/trunk/mml/links/ucode/getpvucode.c @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.6 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include "mex.h"
4#include "matrix.h"
5#include <nslsc.h>
6#include <ucode_def.h>
7#include <umacro_v2.h>
8#include <time.h>
9
10
11#define N_MAX 256
12
13
14/* Input Arguments */
15#define INPUT1  prhs[0]
16#define INPUT2  prhs[1]
17
18
19
20/* Output Arguments */
21#define OUTPUT1 plhs[0]
22#define OUTPUT2 plhs[1]
23#define OUTPUT3 plhs[2]
24
25
26int uget(int ndev, DEV_NAME devnames[], double setp[], double rdbk[])
27{
28  int       i, setp_cnts[N_MAX], rdbk_cnts[N_MAX], status;
29  float     gain[N_MAX], offset[N_MAX];
30
31  if (ndev < 1) {
32    printf("*** No of devices = %d\n", ndev); exit(0);
33  }
34  for(i = 0; i < ndev; i++) {
35    ugddr_getcalib_data(devnames[i], &gain[i], &offset[i]);
36  }
37
38  if (uidopen("Ctest")) {
39    ucdperror(); exit(1);
40  }
41  status = ureadsetp(ndev, devnames, setp_cnts) ||
42           ureadmag(ndev, devnames, rdbk_cnts);
43  if (status) {
44    fprintf(stderr, "*** ");
45    ucdperror();
46  } else {
47    for(i = 0; i < ndev; i++) {
48      setp[i] = (double) setp_cnts[i] * (double) gain[i]; 
49      rdbk[i] = (double) rdbk_cnts[i] * (double) gain[i];
50      /*mexPrintf("devnames:  |%s|\n", devnames[i]);*/
51   }
52  }
53  uclose();
54  return(status);
55}
56
57
58/*  MATLAB TO C-CALL LINKING FUNCTION  */
59void mexFunction( int nlhs, mxArray *plhs[],
60                  int nrhs, const mxArray *prhs[] )
61{
62        char *ChannelNames, Names[200][16];
63    int   i, j, buflen, status, UcodeStatus, Rows, Cols;
64    double *Setpoint, *ReadBack, *ErrorFlag;
65
66       
67        /* Check Inputs */
68        if (nrhs < 1 || nrhs > 1)
69                mexErrMsgTxt("requires 1 input argument.");
70
71
72        /* Input 1: Channel names (Matrix of strings) */
73        if (mxIsChar(INPUT1) != 1)
74            mexErrMsgTxt("ChannelName input must be a string");
75
76           
77        /* get the length of the input string */
78    buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
79
80   
81    /* allocate memory for input string */
82    ChannelNames = mxCalloc(buflen, sizeof(char));
83
84   
85        /* copy the string data from prhs[0] into a C string input_ buf.
86     * If the string array contains several rows, they are copied,
87     * one column at a time, into one long string array.
88     */
89    status = mxGetString(prhs[0], ChannelNames, buflen);
90    if(status != 0) 
91      mexWarnMsgTxt("Not enough space to read in the ChannelName string.  ChannelName is truncated.");
92
93    Rows = (int) mxGetM(prhs[0]);
94    Cols = (int) mxGetN(prhs[0]);
95
96
97        /* Input 2 */
98        /*if (nrhs >= 5) {
99                nrowst = (int) mxGetM(INPUT5);
100                ncolst = (int) mxGetN(INPUT5);
101                if (!mxIsNumeric(INPUT5) || mxIsComplex(INPUT5) ||
102                         !mxIsDouble(INPUT5) ||
103                        (nrowst != 1))
104                        mexErrMsgTxt("INPUT5 (t) must be a row vector!");
105                t = mxGetPr(INPUT5);
106        } else {
107                nrowst = 1;
108                ncolst = 1;
109                t = &t0;
110        }
111        */
112       
113
114        /* End input checking */
115
116
117        /* Create output vectors */
118        OUTPUT1 = mxCreateDoubleMatrix((unsigned int) Rows, (unsigned int) 1, mxREAL);
119        ReadBack = mxGetPr(OUTPUT1);
120
121        OUTPUT2 = mxCreateDoubleMatrix((unsigned int) Rows, (unsigned int) 1, mxREAL);
122        Setpoint = mxGetPr(OUTPUT2);
123       
124        OUTPUT3 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL);
125        ErrorFlag = mxGetPr(OUTPUT3);
126
127
128        /* Get ucode data */
129       
130        for (i=0; i<Rows; i++) { 
131            for (j=0; j<Cols; j++) { 
132                Names[i][j] = ChannelNames[i + j*Rows];
133                /*mexPrintf("Names:  %c\n", ChannelNames[i + j*Rows]); */
134            }
135            Names[i][Cols] = '\0';
136            /*mexPrintf("Names:  |%s|\n", Names[i]);*/
137        }
138
139        /*mexPrintf(" Rows = %d   Cols = %d\n",  Rows, Cols);*/
140        UcodeStatus = uget(Rows, Names, Setpoint, ReadBack);
141        *ErrorFlag = UcodeStatus;
142
143       
144        /* for (i=0; i<ncolst; i++) { */
145                /* VecGetAM(Family, SectorNum, DeviceNum, &(AM[i*nrowsDeviceNum]), nrowsDeviceNum, NumberOfAverages, ErrStr);
146        }
147        */
148
149
150        if (UcodeStatus != 0)
151        mexPrintf("WARNING: getpvucode() problem\n");
152   
153
154 }
155
Note: See TracBrowser for help on using the repository browser.