Rev 207 | Rev 217 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 207 | Rev 210 | ||
|---|---|---|---|
| 1 | #include <formatio.h> |
1 | #include <formatio.h> |
| 2 | #include <utility.h> |
2 | #include <utility.h> |
| 3 | #include <ansi_c.h> |
3 | #include <ansi_c.h> |
| 4 | #include <cvirte.h> |
4 | #include <cvirte.h> |
| 5 | #include <userint.h> |
5 | #include <userint.h> |
| 6 | #include "drs4.h" |
6 | #include "drs4.h" |
| 7 | #include "drsread.h" |
7 | #include "drsread.h" |
| 8 | 8 | ||
| 9 | #define MIKRO |
9 | #define MIKRO |
| 10 | 10 | ||
| 11 | #ifdef MIKRO |
11 | #ifdef MIKRO |
| 12 | #include "MIKRO.h" |
12 | #include "MIKRO.h" |
| 13 | #endif |
13 | #endif |
| 14 | 14 | ||
| 15 | static int daq_on; |
15 | static int daq_on; |
| 16 | static int ph, p2,plothandle[4]= {0,0,0,0}; |
16 | static int ph, p2,plothandle[4]= {0,0,0,0}; |
| 17 | static int tfID; |
17 | static int tfID; |
| 18 | static int controlID; |
18 | static int controlID; |
| 19 | 19 | ||
| 20 | #define MAX_THREADS 10 |
20 | #define MAX_THREADS 10 |
| 21 | 21 | ||
| 22 | static CmtThreadPoolHandle poolHandle = 0; |
22 | static CmtThreadPoolHandle poolHandle = 0; |
| 23 | 23 | ||
| 24 | int main (int argc, char *argv[]) { |
24 | int main (int argc, char *argv[]) { |
| 25 | short port; |
25 | short port; |
| 26 | if (InitCVIRTE (0, argv, 0) == 0) |
26 | if (InitCVIRTE (0, argv, 0) == 0) |
| 27 | return -1; /* out of memory */ |
27 | return -1; /* out of memory */ |
| 28 | if ((ph = LoadPanel (0, "drs4.uir", PANEL)) < 0) |
28 | if ((ph = LoadPanel (0, "drs4.uir", PANEL)) < 0) |
| 29 | return -1; |
29 | return -1; |
| 30 | if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
30 | if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
| 31 | return -1; |
31 | return -1; |
| 32 | SetStdioPort (CVI_STDIO_WINDOW); |
32 | SetStdioPort (CVI_STDIO_WINDOW); |
| 33 | SetSleepPolicy(VAL_SLEEP_MORE); |
33 | SetSleepPolicy(VAL_SLEEP_MORE); |
| 34 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
34 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
| 35 | 35 | ||
| 36 | DisplayPanel (ph); |
36 | DisplayPanel (ph); |
| 37 | DisplayPanel (p2); |
37 | DisplayPanel (p2); |
| 38 | 38 | ||
| 39 | #ifdef MIKRO |
39 | #ifdef MIKRO |
| 40 | GetCtrlVal(p2, SCAN_PORT, &port); |
40 | GetCtrlVal(p2, SCAN_PORT, &port); |
| 41 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
41 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
| 42 | MIKRO_Init(1,0); |
42 | MIKRO_Init(1,0); |
| 43 | MIKRO_Init(2,0); |
43 | MIKRO_Init(2,0); |
| 44 | #endif |
44 | #endif |
| 45 | 45 | ||
| 46 | RunUserInterface (); |
46 | RunUserInterface (); |
| 47 | DiscardPanel (ph); |
47 | DiscardPanel (ph); |
| 48 | DiscardPanel (p2); |
48 | DiscardPanel (p2); |
| 49 | CmtDiscardThreadPool (poolHandle); |
49 | CmtDiscardThreadPool (poolHandle); |
| 50 | MIKRO_Close (); |
50 | MIKRO_Close (); |
| 51 | return 0; |
51 | return 0; |
| 52 | } |
52 | } |
| 53 | 53 | ||
| 54 | 54 | ||
| - | 55 | char strbuf[0xFF]; |
|
| - | 56 | ||
| - | 57 | int gLog=0; |
|
| - | 58 | ||
| - | 59 | int printf(const char *format, ...) { |
|
| - | 60 | va_list aptr; |
|
| - | 61 | int ret; |
|
| - | 62 | FILE *flog; |
|
| - | 63 | ||
| - | 64 | va_start(aptr, format); |
|
| - | 65 | ret = vsprintf(strbuf, format, aptr); |
|
| - | 66 | va_end(aptr); |
|
| - | 67 | SetCtrlVal(ph,PANEL_STDIO,strbuf); |
|
| - | 68 | ||
| - | 69 | if (gLog) { |
|
| - | 70 | flog = fopen ("stdio.log", "a"); |
|
| - | 71 | fprintf (flog, "%s", strbuf); |
|
| - | 72 | fclose (flog); |
|
| - | 73 | } |
|
| - | 74 | return(ret); |
|
| - | 75 | } |
|
| 55 | 76 | ||
| 56 | 77 | ||
| 57 | 78 | ||
| 58 | static void start_timer (double tout) { |
79 | static void start_timer (double tout) { |
| 59 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_INTERVAL, tout); |
80 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_INTERVAL, tout); |
| 60 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 1); |
81 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 1); |
| 61 | } |
82 | } |
| 62 | 83 | ||
| 63 | static void stop_timer ( void ) { |
84 | static void stop_timer ( void ) { |
| 64 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 0); |
85 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 0); |
| 65 | DRSSetTimeout(); |
86 | DRSSetTimeout(); |
| 66 | } |
87 | } |
| 67 | 88 | ||
| 68 | 89 | ||
| 69 | 90 | ||
| 70 | 91 | ||
| 71 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
92 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
| 72 | CmtThreadFunctionID functionID, unsigned int event, |
93 | CmtThreadFunctionID functionID, unsigned int event, |
| 73 | int value, void *callbackData ) { |
94 | int value, void *callbackData ) { |
| 74 | 95 | ||
| 75 | daq_on=0; |
96 | daq_on=0; |
| 76 | //SetDimming(0); |
97 | //SetDimming(0); |
| 77 | printf("End of Thread \n"); |
98 | printf("End of Thread \n"); |
| 78 | return ; |
99 | return ; |
| 79 | 100 | ||
| 80 | } |
101 | } |
| 81 | 102 | ||
| 82 | 103 | ||
| 83 | int CVICALLBACK daq(void *functionData) { |
104 | int CVICALLBACK daq(void *functionData) { |
| 84 | 105 | ||
| 85 | 106 | ||
| 86 | int neve; |
107 | int neve; |
| 87 | char filename[0xff]; |
108 | char filename[0xff]; |
| 88 | int imask[4]; |
109 | int imask[4]; |
| 89 | unsigned long mask; |
110 | unsigned long mask; |
| 90 | int frequency; |
111 | int frequency; |
| 91 | double trgdelay; |
112 | double trgdelay; |
| 92 | double trglevel; |
113 | double trglevel; |
| 93 | int trgtype; |
114 | int trgtype; |
| 94 | int trgchannel; |
115 | int trgchannel; |
| 95 | int trgpolarity; |
116 | int trgpolarity; |
| 96 | int verbose; |
117 | int verbose; |
| 97 | double range; |
118 | double range; |
| 98 | int pfreq; |
119 | int pfreq; |
| 99 | int enabledoutput; |
120 | int enabledoutput; |
| 100 | int neveold = 0; |
121 | int neveold = 0; |
| 101 | double rate; |
122 | double rate; |
| 102 | int *args = (int *) functionData; |
123 | int *args = (int *) functionData; |
| 103 | 124 | ||
| 104 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
125 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| 105 | GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
126 | GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
| 106 | GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
127 | GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
| 107 | GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
128 | GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
| 108 | GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
129 | GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
| 109 | mask = 0; |
130 | mask = 0; |
| 110 | for (int i=0; i<4; i++) { |
131 | for (int i=0; i<4; i++) { |
| 111 | if (imask[i]) mask |= (1<<i); |
132 | if (imask[i]) mask |= (1<<i); |
| 112 | } |
133 | } |
| 113 | 134 | ||
| 114 | GetCtrlVal(ph,PANEL_NEVE, &neve); |
135 | GetCtrlVal(ph,PANEL_NEVE, &neve); |
| 115 | GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
136 | GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
| 116 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
137 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
| 117 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
138 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
| 118 | 139 | ||
| 119 | GetCtrlVal(ph,PANEL_FREQUENCY, &frequency); |
140 | GetCtrlVal(ph,PANEL_FREQUENCY, &frequency); |
| 120 | GetCtrlVal(ph,PANEL_TRGDELAY, &trgdelay); |
141 | GetCtrlVal(ph,PANEL_TRGDELAY, &trgdelay); |
| 121 | GetCtrlVal(ph,PANEL_TRGCHANNEL, &trgchannel); |
142 | GetCtrlVal(ph,PANEL_TRGCHANNEL, &trgchannel); |
| 122 | 143 | ||
| 123 | GetCtrlVal(ph,PANEL_TRGTYPE, &trgtype); |
144 | GetCtrlVal(ph,PANEL_TRGTYPE, &trgtype); |
| 124 | GetCtrlVal(ph,PANEL_TRGLEVEL, &trglevel); |
145 | GetCtrlVal(ph,PANEL_TRGLEVEL, &trglevel); |
| 125 | GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
146 | GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
| 126 | GetCtrlVal(ph,PANEL_RANGE, &range); |
147 | GetCtrlVal(ph,PANEL_RANGE, &range); |
| 127 | 148 | ||
| 128 | 149 | ||
| 129 | //printf("mask=0x%x\n",mask); |
150 | //printf("mask=0x%x\n",mask); |
| 130 | 151 | ||
| 131 | DRSSetMask( (unsigned char)( mask & 0xF ) ); |
152 | DRSSetMask( (unsigned char)( mask & 0xF ) ); |
| 132 | 153 | ||
| 133 | DRSSetFrequency( frequency ); |
154 | DRSSetFrequency( frequency ); |
| 134 | DRSSetTriggerDelay(trgdelay ); |
155 | DRSSetTriggerDelay(trgdelay ); |
| 135 | DRSSetTriggerChannel(trgchannel ); |
156 | DRSSetTriggerChannel(trgchannel ); |
| 136 | DRSSetTriggerType( trgtype ); |
157 | DRSSetTriggerType( trgtype ); |
| 137 | DRSSetTriggerLevel(trglevel); |
158 | DRSSetTriggerLevel(trglevel); |
| 138 | DRSSetTriggerPolarity(trgpolarity); |
159 | DRSSetTriggerPolarity(trgpolarity); |
| 139 | 160 | ||
| 140 | DRSSetRange ( range ); |
161 | DRSSetRange ( range ); |
| 141 | 162 | ||
| 142 | 163 | ||
| 143 | 164 | ||
| 144 | FILE *fp= NULL; |
165 | FILE *fp= NULL; |
| 145 | 166 | ||
| 146 | if (enabledoutput) { |
167 | if (enabledoutput) { |
| 147 | if (args[0]) fp = fopen(filename,"wb"); |
168 | if (args[0]) fp = fopen(filename,"wb"); |
| 148 | else fp = fopen(filename,"ab"); |
169 | else fp = fopen(filename,"ab"); |
| 149 | } |
170 | } |
| 150 | 171 | ||
| 151 | static unsigned char *buffer; |
172 | static unsigned char *buffer; |
| 152 | 173 | ||
| 153 | int buffer_size = 0; |
174 | int buffer_size = 0; |
| 154 | const int nBoards=1; |
175 | const int nBoards=1; |
| 155 | const int waveDepth=1024; |
176 | const int waveDepth=1024; |
| 156 | 177 | ||
| 157 | if (buffer_size == 0) { |
178 | if (buffer_size == 0) { |
| 158 | buffer_size = 8; // file header + time header |
179 | buffer_size = 8; // file header + time header |
| 159 | buffer_size += nBoards * (4 + 4*(4+waveDepth*4)); // bin widths |
180 | buffer_size += nBoards * (4 + 4*(4+waveDepth*4)); // bin widths |
| 160 | buffer_size += 24 + nBoards * (8 + 4*(8+waveDepth*2)); |
181 | buffer_size += 24 + nBoards * (8 + 4*(8+waveDepth*2)); |
| 161 | buffer = (unsigned char *)malloc(buffer_size); |
182 | buffer = (unsigned char *)malloc(buffer_size); |
| 162 | } |
183 | } |
| 163 | 184 | ||
| 164 | time_t t=0,told=0, tstart=0; |
185 | time_t t=0,told=0, tstart=0; |
| 165 | 186 | ||
| 166 | if (!DRSInit()) { |
187 | if (!DRSInit()) { |
| 167 | time(&tstart); |
188 | time(&tstart); |
| 168 | told=tstart; |
189 | told=tstart; |
| 169 | int i=0; |
190 | int i=0; |
| 170 | for (i=0; i<neve; i++) { |
191 | for (i=0; i<neve; i++) { |
| 171 | start_timer(1);// 1 s timeout |
192 | start_timer(1);// 1 s timeout |
| 172 | int retval = DRSRead(0); |
193 | int retval = DRSRead(0); |
| 173 | stop_timer(); |
194 | stop_timer(); |
| 174 | int nb = ( retval == 0 && fp ) ? DRSToBuffer( buffer , i ) : 0; |
195 | int nb = ( retval == 0 && fp ) ? DRSToBuffer( buffer , i ) : 0; |
| 175 | SetCtrlVal(ph,PANEL_CEVE,i); |
196 | SetCtrlVal(ph,PANEL_CEVE,i); |
| 176 | if (retval) i--; |
197 | if (retval) i--; |
| 177 | if (!daq_on) break; |
198 | if (!daq_on) break; |
| 178 | time(&t); |
199 | time(&t); |
| 179 | if (t!=told ) { |
200 | if (t!=told ) { |
| 180 | rate = (i-neveold); |
201 | rate = (i-neveold); |
| 181 | printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t)); |
202 | printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t)); |
| 182 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
203 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
| 183 | neveold = i; |
204 | neveold = i; |
| 184 | } |
205 | } |
| 185 | told=t; |
206 | told=t; |
| 186 | // Save data |
207 | // Save data |
| 187 | if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
208 | if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
| 188 | // Plot Data |
209 | // Plot Data |
| 189 | if (i % pfreq == 0) for (int k=0; k<4; k++) { |
210 | if (i % pfreq == 0) for (int k=0; k<4; k++) { |
| 190 | if (! (mask & ( 0x1<<k )) ) continue; |
211 | if (! (mask & ( 0x1<<k )) ) continue; |
| 191 | float *t=DRSGetTime(k); |
212 | float *t=DRSGetTime(k); |
| 192 | float *x=DRSGetWave(k); |
213 | float *x=DRSGetWave(k); |
| 193 | 214 | ||
| 194 | const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
215 | const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
| 195 | if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
216 | if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
| 196 | plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, x, 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
217 | plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, x, 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
| 197 | 218 | ||
| 198 | for (int i=0 ; i<1024 ; i++) { |
219 | for (int i=0 ; i<1024 ; i++) { |
| 199 | if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[i], x[i] ); |
220 | if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[i], x[i] ); |
| 200 | //h[k]->Fill( t[i], x[i]*1e-3); |
221 | //h[k]->Fill( t[i], x[i]*1e-3); |
| 201 | } |
222 | } |
| 202 | } |
223 | } |
| 203 | 224 | ||
| 204 | 225 | ||
| 205 | } |
226 | } |
| 206 | time(&t); |
227 | time(&t); |
| 207 | printf("%d events in %2.2f min (%d s) %s",i+1, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
228 | printf("%d events in %2.2f min (%d s) %s",i+1, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
| 208 | DRSEnd(); |
229 | DRSEnd(); |
| 209 | } |
230 | } |
| 210 | 231 | ||
| 211 | if (fp) fclose(fp); |
232 | if (fp) fclose(fp); |
| 212 | 233 | ||
| 213 | free(buffer); |
234 | free(buffer); |
| 214 | 235 | ||
| 215 | return 0; |
236 | return 0; |
| 216 | 237 | ||
| 217 | } |
238 | } |
| 218 | 239 | ||
| 219 | 240 | ||
| 220 | 241 | ||
| 221 | int CVICALLBACK scan(void *functionData) { |
242 | int CVICALLBACK scan(void *functionData) { |
| 222 | 243 | ||
| 223 | int dx[3]={0,0,0}; |
244 | int dx[3]={0,0,0}; |
| 224 | int nx[3]={0,0,0}; |
245 | int nx[3]={0,0,0}; |
| 225 | int x0[3]={0,0,0}; |
246 | int x0[3]={0,0,0}; |
| 226 | int ix[3]={0,0,0}; |
247 | int ix[3]={0,0,0}; |
| 227 | int idx[3]={0,0,0}; |
248 | int idx[3]={0,0,0}; |
| 228 | int size; |
249 | int size; |
| 229 | char posrec[4]="POSR"; |
250 | char posrec[4]="POSR"; |
| 230 | char runbuf[4]="PRUN"; |
251 | char runbuf[4]="PRUN"; |
| 231 | 252 | ||
| 232 | int n[3]; |
253 | int n[3]; |
| 233 | char filename[0xFF]; |
254 | char filename[0xFF]; |
| 234 | int enabledoutput; |
255 | int enabledoutput; |
| 235 | 256 | ||
| 236 | FILE *fp; |
257 | FILE *fp; |
| 237 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
258 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| 238 | 259 | ||
| 239 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
260 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
| 240 | 261 | ||
| 241 | if ( GetFileInfo(filename,&size) ) { |
262 | if ( GetFileInfo(filename,&size) ) { |
| 242 | MessagePopup ("Warning", "File exist. Remove it first or choose another file"); |
263 | MessagePopup ("Warning", "File exist. Remove it first or choose another file"); |
| 243 | return 0; |
264 | return 0; |
| 244 | } |
265 | } |
| 245 | GetCtrlVal(p2, SCAN_STEPX, &dx[0]); |
266 | GetCtrlVal(p2, SCAN_STEPX, &dx[0]); |
| 246 | GetCtrlVal(p2, SCAN_STEPY, &dx[1]); |
267 | GetCtrlVal(p2, SCAN_STEPY, &dx[1]); |
| 247 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx[0]); |
268 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx[0]); |
| 248 | GetCtrlVal(p2, SCAN_NSTEPSY, &nx[1]); |
269 | GetCtrlVal(p2, SCAN_NSTEPSY, &nx[1]); |
| 249 | GetCtrlVal(p2, SCAN_STARTX, &x0[0]); |
270 | GetCtrlVal(p2, SCAN_STARTX, &x0[0]); |
| 250 | GetCtrlVal(p2, SCAN_STARTY, &x0[1]); |
271 | GetCtrlVal(p2, SCAN_STARTY, &x0[1]); |
| 251 | 272 | ||
| 252 | 273 | ||
| 253 | if (enabledoutput) { |
274 | if (enabledoutput) { |
| 254 | fp = fopen(filename,"ab"); |
275 | fp = fopen(filename,"ab"); |
| 255 | if (fp) { |
276 | if (fp) { |
| 256 | size=36; |
277 | size=36; |
| 257 | fwrite(runbuf, 1,4 ,fp); |
278 | fwrite(runbuf, 1,4 ,fp); |
| 258 | fwrite(&size , 1,4 ,fp); |
279 | fwrite(&size , 1,4 ,fp); |
| 259 | fwrite(x0 , 1,4*3 ,fp); |
280 | fwrite(x0 , 1,4*3 ,fp); |
| 260 | fwrite(dx , 1,4*3 ,fp); |
281 | fwrite(dx , 1,4*3 ,fp); |
| 261 | fwrite(nx , 1,4*3 ,fp); |
282 | fwrite(nx , 1,4*3 ,fp); |
| 262 | fclose(fp); |
283 | fclose(fp); |
| 263 | } |
284 | } |
| 264 | } |
285 | } |
| 265 | 286 | ||
| 266 | for (int i=0; i<nx[0]; i++) { |
287 | for (int i=0; i<nx[0]; i++) { |
| 267 | 288 | ||
| 268 | ix[0]= x0[0]+i*dx[0]; |
289 | ix[0]= x0[0]+i*dx[0]; |
| 269 | #ifdef MIKRO |
290 | #ifdef MIKRO |
| 270 | MIKRO_MoveTo(1,ix[0]); |
291 | MIKRO_MoveTo(1,ix[0]); |
| 271 | #endif |
292 | #endif |
| 272 | SetCtrlVal (p2, SCAN_IX, i); |
293 | SetCtrlVal (p2, SCAN_IX, i); |
| 273 | for (int j=0; j<nx[1]; j++) { |
294 | for (int j=0; j<nx[1]; j++) { |
| 274 | 295 | ||
| 275 | SetCtrlVal (p2, SCAN_IY, j); |
296 | SetCtrlVal (p2, SCAN_IY, j); |
| 276 | 297 | ||
| 277 | ix[1]= x0[1]+j*dx[1]; |
298 | ix[1]= x0[1]+j*dx[1]; |
| 278 | #ifdef MIKRO |
299 | #ifdef MIKRO |
| 279 | MIKRO_MoveTo(2,ix[1]); |
300 | MIKRO_MoveTo(2,ix[1]); |
| 280 | 301 | ||
| 281 | MIKRO_GetPosition(1,&n[0]); |
302 | MIKRO_GetPosition(1,&n[0]); |
| 282 | SetCtrlVal (p2, SCAN_XP, n[0]); |
303 | SetCtrlVal (p2, SCAN_XP, n[0]); |
| 283 | MIKRO_GetPosition(2,&n[1]); |
304 | MIKRO_GetPosition(2,&n[1]); |
| 284 | SetCtrlVal (p2, SCAN_YP, n[1]); |
305 | SetCtrlVal (p2, SCAN_YP, n[1]); |
| 285 | 306 | ||
| 286 | if (enabledoutput) { |
307 | if (enabledoutput) { |
| 287 | fp = fopen(filename,"ab"); |
308 | fp = fopen(filename,"ab"); |
| 288 | if (fp) { |
309 | if (fp) { |
| 289 | idx[0]=i; |
310 | idx[0]=i; |
| 290 | idx[1]=j; |
311 | idx[1]=j; |
| 291 | size=24; |
312 | size=24; |
| 292 | fwrite(posrec, 1,4 ,fp); |
313 | fwrite(posrec, 1,4 ,fp); |
| 293 | fwrite(&size , 1,4 ,fp); |
314 | fwrite(&size , 1,4 ,fp); |
| 294 | fwrite(n , 1,4*3 ,fp); |
315 | fwrite(n , 1,4*3 ,fp); |
| 295 | fwrite(idx , 1,4*3 ,fp); |
316 | fwrite(idx , 1,4*3 ,fp); |
| 296 | fclose(fp); |
317 | fclose(fp); |
| 297 | } |
318 | } |
| 298 | } |
319 | } |
| 299 | 320 | ||
| 300 | #endif |
321 | #endif |
| 301 | daq(functionData); |
322 | daq(functionData); |
| 302 | if (!daq_on) break; |
323 | if (!daq_on) break; |
| 303 | } |
324 | } |
| 304 | if (!daq_on) break; |
325 | if (!daq_on) break; |
| 305 | } |
326 | } |
| 306 | 327 | ||
| 307 | return 0; |
328 | return 0; |
| 308 | } |
329 | } |
| 309 | 330 | ||
| 310 | 331 | ||
| 311 | int CVICALLBACK StartCB (int panel, int control, int event, |
332 | int CVICALLBACK StartCB (int panel, int control, int event, |
| 312 | void *callbackData, int eventData1, int eventData2) { |
333 | void *callbackData, int eventData1, int eventData2) { |
| 313 | ThreadFunctionPtr mythread = NULL; |
334 | ThreadFunctionPtr mythread = NULL; |
| 314 | switch (event) { |
335 | switch (event) { |
| 315 | 336 | ||
| 316 | case EVENT_COMMIT: |
337 | case EVENT_COMMIT: |
| 317 | 338 | ||
| 318 | controlID=0; |
339 | controlID=0; |
| 319 | if (panel == ph && control == PANEL_START) { |
340 | if (panel == ph && control == PANEL_START) { |
| 320 | mythread = daq; |
341 | mythread = daq; |
| 321 | controlID= control; |
342 | controlID= control; |
| 322 | } |
343 | } |
| 323 | if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
344 | if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
| 324 | if (mythread!=NULL) { |
345 | if (mythread!=NULL) { |
| 325 | printf("New Thread panel=%d button=%d\n", panel, control); |
346 | printf("New Thread panel=%d button=%d\n", panel, control); |
| 326 | 347 | ||
| 327 | // SetDimming(1); |
348 | // SetDimming(1); |
| 328 | 349 | ||
| 329 | daq_on=1; |
350 | daq_on=1; |
| 330 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &controlID, |
351 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &controlID, |
| 331 | DEFAULT_THREAD_PRIORITY, |
352 | DEFAULT_THREAD_PRIORITY, |
| 332 | EndOfThread, |
353 | EndOfThread, |
| 333 | EVENT_TP_THREAD_FUNCTION_END, |
354 | EVENT_TP_THREAD_FUNCTION_END, |
| 334 | NULL, RUN_IN_SCHEDULED_THREAD, |
355 | NULL, RUN_IN_SCHEDULED_THREAD, |
| 335 | &tfID); |
356 | &tfID); |
| 336 | } |
357 | } |
| 337 | break; |
358 | break; |
| 338 | } |
359 | } |
| 339 | return 0; |
360 | return 0; |
| 340 | } |
361 | } |
| 341 | 362 | ||
| 342 | int CVICALLBACK StopCB (int panel, int control, int event, |
363 | int CVICALLBACK StopCB (int panel, int control, int event, |
| 343 | void *callbackData, int eventData1, int eventData2) { |
364 | void *callbackData, int eventData1, int eventData2) { |
| 344 | switch (event) { |
365 | switch (event) { |
| 345 | case EVENT_COMMIT: |
366 | case EVENT_COMMIT: |
| 346 | daq_on=0; |
367 | daq_on=0; |
| 347 | break; |
368 | break; |
| 348 | } |
369 | } |
| 349 | return 0; |
370 | return 0; |
| 350 | } |
371 | } |
| 351 | 372 | ||
| 352 | int CVICALLBACK ExitCB (int panel, int control, int event, |
373 | int CVICALLBACK ExitCB (int panel, int control, int event, |
| 353 | void *callbackData, int eventData1, int eventData2) { |
374 | void *callbackData, int eventData1, int eventData2) { |
| 354 | switch (event) { |
375 | switch (event) { |
| 355 | case EVENT_COMMIT: |
376 | case EVENT_COMMIT: |
| 356 | QuitUserInterface (0); |
377 | QuitUserInterface (0); |
| 357 | break; |
378 | break; |
| 358 | } |
379 | } |
| 359 | return 0; |
380 | return 0; |
| 360 | } |
381 | } |
| 361 | 382 | ||
| 362 | int CVICALLBACK MoveStageCB (int panel, int control, int event, |
383 | int CVICALLBACK MoveStageCB (int panel, int control, int event, |
| 363 | void *callbackData, int eventData1, int eventData2) { |
384 | void *callbackData, int eventData1, int eventData2) { |
| 364 | int axis=0, step=1000, direction=1, n; |
385 | int axis=0, step=1000, direction=1, n; |
| 365 | switch (event) { |
386 | switch (event) { |
| 366 | case EVENT_COMMIT: |
387 | case EVENT_COMMIT: |
| 367 | 388 | ||
| 368 | if (panel == p2) { |
389 | if (panel == p2) { |
| 369 | switch (control) { |
390 | switch (control) { |
| 370 | case SCAN_BR : |
391 | case SCAN_BR : |
| 371 | axis = 1; |
392 | axis = 1; |
| 372 | direction = 1; |
393 | direction = 1; |
| 373 | GetCtrlVal(p2, SCAN_STEPX, &step); |
394 | GetCtrlVal(p2, SCAN_STEPX, &step); |
| 374 | break; |
395 | break; |
| 375 | case SCAN_BL : |
396 | case SCAN_BL : |
| 376 | axis = 1; |
397 | axis = 1; |
| 377 | direction = -1; |
398 | direction = -1; |
| 378 | GetCtrlVal(p2, SCAN_STEPX, &step); |
399 | GetCtrlVal(p2, SCAN_STEPX, &step); |
| 379 | break; |
400 | break; |
| 380 | case SCAN_BU : |
401 | case SCAN_BU : |
| 381 | axis = 2; |
402 | axis = 2; |
| 382 | direction = 1; |
403 | direction = 1; |
| 383 | GetCtrlVal(p2, SCAN_STEPY, &step); |
404 | GetCtrlVal(p2, SCAN_STEPY, &step); |
| 384 | break; |
405 | break; |
| 385 | case SCAN_BD : |
406 | case SCAN_BD : |
| 386 | axis = 2; |
407 | axis = 2; |
| 387 | direction = -1; |
408 | direction = -1; |
| 388 | GetCtrlVal(p2, SCAN_STEPY, &step); |
409 | GetCtrlVal(p2, SCAN_STEPY, &step); |
| 389 | break; |
410 | break; |
| 390 | } |
411 | } |
| 391 | #ifdef MIKRO |
412 | #ifdef MIKRO |
| 392 | MIKRO_MoveFor(axis, direction*step ); |
413 | MIKRO_MoveFor(axis, direction*step ); |
| 393 | MIKRO_GetPosition(axis,&n); |
414 | MIKRO_GetPosition(axis,&n); |
| 394 | if (axis == 1) SetCtrlVal (p2, SCAN_XP, n); |
415 | if (axis == 1) SetCtrlVal (p2, SCAN_XP, n); |
| 395 | if (axis == 2) SetCtrlVal (p2, SCAN_YP, n); |
416 | if (axis == 2) SetCtrlVal (p2, SCAN_YP, n); |
| 396 | #endif // MIKRO |
417 | #endif // MIKRO |
| 397 | } |
418 | } |
| 398 | 419 | ||
| 399 | break; |
420 | break; |
| 400 | } |
421 | } |
| 401 | return 0; |
422 | return 0; |
| 402 | } |
423 | } |
| 403 | 424 | ||
| 404 | 425 | ||
| 405 | 426 | ||
| 406 | 427 | ||
| 407 | 428 | ||
| 408 | int CVICALLBACK GoXCB (int panel, int control, int event, |
429 | int CVICALLBACK GoXCB (int panel, int control, int event, |
| 409 | void *callbackData, int eventData1, int eventData2) { |
430 | void *callbackData, int eventData1, int eventData2) { |
| 410 | int n2; |
431 | int n2; |
| 411 | switch (event) { |
432 | switch (event) { |
| 412 | case EVENT_COMMIT: |
433 | case EVENT_COMMIT: |
| 413 | GetCtrlVal (p2, SCAN_XG, &n2); |
434 | GetCtrlVal (p2, SCAN_XG, &n2); |
| 414 | #ifdef MIKRO |
435 | #ifdef MIKRO |
| 415 | MIKRO_MoveTo(1,n2); |
436 | MIKRO_MoveTo(1,n2); |
| 416 | MIKRO_GetPosition(1,&n2); |
437 | MIKRO_GetPosition(1,&n2); |
| 417 | 438 | ||
| 418 | #endif |
439 | #endif |
| 419 | SetCtrlVal (p2, SCAN_XP, n2); |
440 | SetCtrlVal (p2, SCAN_XP, n2); |
| 420 | break; |
441 | break; |
| 421 | } |
442 | } |
| 422 | return 0; |
443 | return 0; |
| 423 | } |
444 | } |
| 424 | 445 | ||
| 425 | int CVICALLBACK GoYCB (int panel, int control, int event, |
446 | int CVICALLBACK GoYCB (int panel, int control, int event, |
| 426 | void *callbackData, int eventData1, int eventData2) { |
447 | void *callbackData, int eventData1, int eventData2) { |
| 427 | int n2; |
448 | int n2; |
| 428 | switch (event) { |
449 | switch (event) { |
| 429 | case EVENT_COMMIT: |
450 | case EVENT_COMMIT: |
| 430 | GetCtrlVal (p2, SCAN_YG, &n2); |
451 | GetCtrlVal (p2, SCAN_YG, &n2); |
| 431 | #ifdef MIKRO |
452 | #ifdef MIKRO |
| 432 | MIKRO_MoveTo(2,n2); |
453 | MIKRO_MoveTo(2,n2); |
| 433 | MIKRO_GetPosition(2,&n2); |
454 | MIKRO_GetPosition(2,&n2); |
| 434 | 455 | ||
| 435 | #endif |
456 | #endif |
| 436 | SetCtrlVal (p2, SCAN_YP, n2); |
457 | SetCtrlVal (p2, SCAN_YP, n2); |
| 437 | break; |
458 | break; |
| 438 | } |
459 | } |
| 439 | return 0; |
460 | return 0; |
| 440 | } |
461 | } |
| 441 | 462 | ||
| 442 | int CVICALLBACK GetCurrentPositionCB (int panel, int control, int event, |
463 | int CVICALLBACK GetCurrentPositionCB (int panel, int control, int event, |
| 443 | void *callbackData, int eventData1, int eventData2) { |
464 | void *callbackData, int eventData1, int eventData2) { |
| 444 | 465 | ||
| 445 | int n[2]; |
466 | int n[2]; |
| 446 | switch (event) { |
467 | switch (event) { |
| 447 | case EVENT_COMMIT: |
468 | case EVENT_COMMIT: |
| 448 | #ifdef MIKRO |
469 | #ifdef MIKRO |
| 449 | MIKRO_GetPosition(1,&n[0]); |
470 | MIKRO_GetPosition(1,&n[0]); |
| 450 | SetCtrlVal (p2, SCAN_XP, n[0]); |
471 | SetCtrlVal (p2, SCAN_XP, n[0]); |
| 451 | MIKRO_GetPosition(2,&n[1]); |
472 | MIKRO_GetPosition(2,&n[1]); |
| 452 | SetCtrlVal (p2, SCAN_YP, n[1]); |
473 | SetCtrlVal (p2, SCAN_YP, n[1]); |
| 453 | #endif |
474 | #endif |
| 454 | break; |
475 | break; |
| 455 | } |
476 | } |
| 456 | return 0; |
477 | return 0; |
| 457 | } |
478 | } |
| 458 | 479 | ||
| 459 | int CVICALLBACK HomeCB (int panel, int control, int event, |
480 | int CVICALLBACK HomeCB (int panel, int control, int event, |
| 460 | void *callbackData, int eventData1, int eventData2) { |
481 | void *callbackData, int eventData1, int eventData2) { |
| 461 | switch (event) { |
482 | switch (event) { |
| 462 | case EVENT_COMMIT: |
483 | case EVENT_COMMIT: |
| 463 | #ifdef MIKRO |
484 | #ifdef MIKRO |
| 464 | MIKRO_ReferenceMove(1); |
485 | MIKRO_ReferenceMove(1); |
| 465 | MIKRO_ReferenceMove(2); |
486 | MIKRO_ReferenceMove(2); |
| 466 | GetCurrentPositionCB(panel, control, event, NULL, 0, 0); |
487 | GetCurrentPositionCB(panel, control, event, NULL, 0, 0); |
| 467 | #endif |
488 | #endif |
| 468 | break; |
489 | break; |
| 469 | } |
490 | } |
| 470 | return 0; |
491 | return 0; |
| 471 | } |
492 | } |
| 472 | 493 | ||