Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
280 | f9daq | 1 | #include <userint.h> |
2 | #include "pw18-1.8aq-ctrl.h" |
||
3 | #include <stdlib.h> |
||
4 | #include <stdio.h> |
||
5 | #include <windows.h> |
||
6 | #include <pw18-1.8aq.h> |
||
7 | |||
8 | int TMI_DeviceId=0; |
||
9 | |||
10 | |||
11 | |||
12 | |||
13 | |||
14 | int TMI_Initialize() |
||
15 | { |
||
16 | |||
17 | TMI_HandleOpen = NULL; |
||
18 | TMI_HandleClose = NULL; |
||
19 | TMI_TimeOut = NULL; |
||
20 | TMI_Refresh = NULL; |
||
21 | TMI_ModelNameQ = NULL; |
||
22 | TMI_Voltage = NULL; |
||
23 | TMI_VoltageQ = NULL; |
||
24 | TMI_Current = NULL; |
||
25 | TMI_CurrentQ = NULL; |
||
26 | TMI_MainOutput = NULL; |
||
27 | TMI_MainOutputQ = NULL; |
||
28 | TMI_Delay = NULL; |
||
29 | TMI_DelayQ = NULL; |
||
30 | TMI_OutputSel = NULL; |
||
31 | TMI_OutputSelQ = NULL; |
||
32 | TMI_TrackingOnOff = NULL; |
||
33 | TMI_TrackingOnOffQ = NULL; |
||
34 | TMI_TrackingMode = NULL; |
||
35 | TMI_TrackingModeQ = NULL; |
||
36 | TMI_TrackingGroup = NULL; |
||
37 | TMI_TrackingGroupQ = NULL; |
||
38 | TMI_TrackingData = NULL; |
||
39 | TMI_TrackingDataQ = NULL; |
||
40 | TMI_DelayTime = NULL; |
||
41 | TMI_DelayTimeQ = NULL; |
||
42 | TMI_Display = NULL; |
||
43 | TMI_DisplayQ = NULL; |
||
44 | TMI_Preset = NULL; |
||
45 | TMI_PresetQ = NULL; |
||
46 | TMI_MoniDataQ = NULL; |
||
47 | TMI_AdrQ = NULL; |
||
48 | TMI_RemoteLocal = NULL; |
||
49 | TMI_LocalLockOut = NULL; |
||
50 | TMI_DataBackUp = NULL; |
||
51 | TMI_SRQEnable = NULL; |
||
52 | TMI_AllPresetQ = NULL; |
||
53 | TMI_AllPresetQS = NULL; |
||
54 | TMI_Out = NULL; |
||
55 | TMI_In = NULL; |
||
56 | return 0; |
||
57 | } |
||
58 | |||
59 | |||
60 | int TMI_Test() |
||
61 | { |
||
62 | char str[0xFF]; |
||
63 | if (TMI_HandleOpen == NULL ) return FALSE; |
||
64 | if (TMI_HandleClose == NULL ) return FALSE; |
||
65 | if (TMI_TimeOut == NULL ) return FALSE; |
||
66 | if (TMI_Refresh == NULL ) return FALSE; |
||
67 | if (TMI_ModelNameQ == NULL ) return FALSE; |
||
68 | if (TMI_Voltage == NULL ) return FALSE; |
||
69 | if (TMI_VoltageQ == NULL ) return FALSE; |
||
70 | if (TMI_Current == NULL ) return FALSE; |
||
71 | if (TMI_CurrentQ == NULL ) return FALSE; |
||
72 | if (TMI_MainOutput == NULL ) return FALSE; |
||
73 | if (TMI_MainOutputQ == NULL ) return FALSE; |
||
74 | if (TMI_Delay == NULL ) return FALSE; |
||
75 | if (TMI_DelayQ == NULL ) return FALSE; |
||
76 | if (TMI_OutputSel == NULL ) return FALSE; |
||
77 | if (TMI_OutputSelQ == NULL ) return FALSE; |
||
78 | if (TMI_TrackingOnOff == NULL ) return FALSE; |
||
79 | if (TMI_TrackingOnOffQ == NULL ) return FALSE; |
||
80 | if (TMI_TrackingMode == NULL ) return FALSE; |
||
81 | if (TMI_TrackingModeQ == NULL ) return FALSE; |
||
82 | if (TMI_TrackingGroup == NULL ) return FALSE; |
||
83 | if (TMI_TrackingGroupQ == NULL ) return FALSE; |
||
84 | if (TMI_TrackingData == NULL ) return FALSE; |
||
85 | if (TMI_TrackingDataQ == NULL ) return FALSE; |
||
86 | if (TMI_DelayTime == NULL ) return FALSE; |
||
87 | if (TMI_DelayTimeQ == NULL ) return FALSE; |
||
88 | if (TMI_Display == NULL ) return FALSE; |
||
89 | if (TMI_DisplayQ == NULL ) return FALSE; |
||
90 | if (TMI_Preset == NULL ) return FALSE; |
||
91 | if (TMI_PresetQ == NULL ) return FALSE; |
||
92 | if (TMI_MoniDataQ == NULL ) return FALSE; |
||
93 | if (TMI_AdrQ == NULL ) return FALSE; |
||
94 | if (TMI_RemoteLocal == NULL ) return FALSE; |
||
95 | if (TMI_LocalLockOut == NULL ) return FALSE; |
||
96 | if (TMI_DataBackUp == NULL ) return FALSE; |
||
97 | if (TMI_SRQEnable == NULL ) return FALSE; |
||
98 | if (TMI_AllPresetQ == NULL ) return FALSE; |
||
99 | if (TMI_AllPresetQS == NULL ) return FALSE; |
||
100 | if (TMI_Out == NULL ) return FALSE; |
||
101 | if (TMI_In == NULL ) return FALSE; |
||
102 | TMI_ModelNameQ(TMI_DeviceId, str); |
||
103 | printf("TMI_ModelNameQ %s\n",str); |
||
104 | return TRUE; |
||
105 | } |
||
106 | |||
107 | int TMI_Close() |
||
108 | { |
||
109 | |||
110 | |||
111 | if(TMI_APIDll != NULL) { |
||
112 | if (TMI_DeviceId){ |
||
113 | |||
114 | TMI_RemoteLocal(TMI_DeviceId); |
||
115 | TMI_HandleClose(TMI_DeviceId); |
||
116 | TMI_DeviceId = 0; |
||
117 | } |
||
118 | FreeLibrary(TMI_APIDll); |
||
119 | } |
||
120 | return 0; |
||
121 | } |
||
122 | |||
123 | int TMI_Open() |
||
124 | { |
||
125 | TMI_Initialize(); |
||
126 | printf("FALSE =%d TRUE=%d\n", FALSE, TRUE); |
||
127 | TMI_APIDll=LoadLibrary((LPCSTR)"TMI_API.dll"); |
||
128 | if( TMI_APIDll == NULL ) |
||
129 | return FALSE; |
||
130 | |||
131 | TMI_HandleOpen = (int ( __stdcall* )( char * , char * )) GetProcAddress(TMI_APIDll , "TMI_HandleOpen"); |
||
132 | if( TMI_HandleOpen == NULL ) |
||
133 | return FALSE; |
||
134 | |||
135 | TMI_TimeOut = (int ( __stdcall* )( int , int )) GetProcAddress(TMI_APIDll , "TMI_TimeOut"); |
||
136 | if( TMI_TimeOut == NULL ) |
||
137 | return FALSE; |
||
138 | |||
139 | TMI_Refresh = (int ( __stdcall* )( int )) GetProcAddress(TMI_APIDll , "TMI_Refresh"); |
||
140 | if( TMI_Refresh == NULL ) |
||
141 | return FALSE; |
||
142 | |||
143 | TMI_ModelNameQ = (int ( __stdcall* )( int , char * )) GetProcAddress(TMI_APIDll , "TMI_ModelNameQ"); |
||
144 | if( TMI_ModelNameQ == NULL ) |
||
145 | return FALSE; |
||
146 | |||
147 | TMI_Voltage = (int ( __stdcall* )( int , unsigned char , unsigned char , double )) GetProcAddress(TMI_APIDll , "TMI_Voltage"); |
||
148 | if( TMI_Voltage == NULL ) |
||
149 | return FALSE; |
||
150 | |||
151 | TMI_VoltageQ = (int ( __stdcall* )( int , unsigned char , unsigned char , double * )) GetProcAddress(TMI_APIDll , "TMI_VoltageQ"); |
||
152 | if( TMI_VoltageQ == NULL ) |
||
153 | return FALSE; |
||
154 | |||
155 | TMI_Current = (int ( __stdcall* )(int , unsigned char , unsigned char , double )) GetProcAddress(TMI_APIDll , "TMI_Current"); |
||
156 | if( TMI_Current == NULL ) |
||
157 | return FALSE; |
||
158 | |||
159 | TMI_CurrentQ = (int ( __stdcall* )(int , unsigned char , unsigned char , double * )) GetProcAddress(TMI_APIDll , "TMI_CurrentQ"); |
||
160 | if( TMI_CurrentQ == NULL ) |
||
161 | return FALSE; |
||
162 | |||
163 | TMI_MainOutput = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_MainOutput"); |
||
164 | if( TMI_MainOutput == NULL ) |
||
165 | return FALSE; |
||
166 | |||
167 | TMI_MainOutputQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_MainOutputQ"); |
||
168 | if( TMI_MainOutputQ == NULL ) |
||
169 | return FALSE; |
||
170 | |||
171 | TMI_Delay = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_Delay"); |
||
172 | if( TMI_Delay == NULL ) |
||
173 | return FALSE; |
||
174 | |||
175 | TMI_DelayQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_DelayQ"); |
||
176 | if( TMI_DelayQ == NULL ) |
||
177 | return FALSE; |
||
178 | |||
179 | TMI_OutputSel = (int ( __stdcall* )(int , unsigned char , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_OutputSel"); |
||
180 | if( TMI_OutputSel == NULL ) |
||
181 | return FALSE; |
||
182 | |||
183 | TMI_OutputSelQ = (int ( __stdcall* )(int , unsigned char , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_OutputSelQ"); |
||
184 | if( TMI_OutputSelQ == NULL ) |
||
185 | return FALSE; |
||
186 | |||
187 | TMI_TrackingOnOff = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_TrackingOnOff"); |
||
188 | if( TMI_TrackingOnOff == NULL ) |
||
189 | return FALSE; |
||
190 | |||
191 | TMI_TrackingOnOffQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_TrackingOnOffQ"); |
||
192 | if( TMI_TrackingOnOffQ == NULL ) |
||
193 | return FALSE; |
||
194 | |||
195 | TMI_TrackingMode = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_TrackingMode"); |
||
196 | if( TMI_TrackingMode == NULL ) |
||
197 | return FALSE; |
||
198 | |||
199 | TMI_TrackingModeQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_TrackingModeQ"); |
||
200 | if( TMI_TrackingModeQ == NULL ) |
||
201 | return FALSE; |
||
202 | |||
203 | TMI_TrackingGroup = (int ( __stdcall* )(int , unsigned char , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_TrackingGroup"); |
||
204 | if( TMI_TrackingGroup == NULL ) |
||
205 | return FALSE; |
||
206 | |||
207 | TMI_TrackingGroupQ = (int ( __stdcall* )(int , unsigned char , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_TrackingGroupQ"); |
||
208 | if( TMI_TrackingGroupQ == NULL ) |
||
209 | return FALSE; |
||
210 | |||
211 | TMI_TrackingData = (int ( __stdcall* )(int , unsigned char , unsigned char , double )) GetProcAddress(TMI_APIDll , "TMI_TrackingData"); |
||
212 | if( TMI_TrackingData == NULL ) |
||
213 | return FALSE; |
||
214 | |||
215 | TMI_TrackingDataQ = (int ( __stdcall* )(int , unsigned char , unsigned char , double * )) GetProcAddress(TMI_APIDll , "TMI_TrackingDataQ"); |
||
216 | if( TMI_TrackingDataQ == NULL ) |
||
217 | return FALSE; |
||
218 | |||
219 | TMI_DelayTime = (int ( __stdcall* )(int , unsigned char , double )) GetProcAddress(TMI_APIDll , "TMI_DelayTime"); |
||
220 | if( TMI_DelayTime == NULL ) |
||
221 | return FALSE; |
||
222 | |||
223 | TMI_DelayTimeQ = (int ( __stdcall* )(int , unsigned char , double * )) GetProcAddress(TMI_APIDll , "TMI_DelayTimeQ"); |
||
224 | if( TMI_DelayTimeQ == NULL ) |
||
225 | return FALSE; |
||
226 | |||
227 | TMI_Display = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_Display"); |
||
228 | if( TMI_Display == NULL ) |
||
229 | return FALSE; |
||
230 | |||
231 | TMI_DisplayQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_DisplayQ"); |
||
232 | if( TMI_DisplayQ == NULL ) |
||
233 | return FALSE; |
||
234 | |||
235 | TMI_Preset = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_Preset"); |
||
236 | if( TMI_Preset == NULL ) |
||
237 | return FALSE; |
||
238 | |||
239 | TMI_PresetQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_PresetQ"); |
||
240 | if( TMI_PresetQ == NULL ) |
||
241 | return FALSE; |
||
242 | |||
243 | TMI_MoniDataQ = (int ( __stdcall* )(int , char , double * , double * , char * )) GetProcAddress(TMI_APIDll , "TMI_MoniDataQ"); |
||
244 | if( TMI_MoniDataQ == NULL ) |
||
245 | return FALSE; |
||
246 | |||
247 | TMI_AdrQ = (int ( __stdcall* )(int , unsigned char * )) GetProcAddress(TMI_APIDll , "TMI_AdrQ"); |
||
248 | if( TMI_AdrQ == NULL ) |
||
249 | return FALSE; |
||
250 | |||
251 | TMI_RemoteLocal = (int ( __stdcall* )(int )) GetProcAddress(TMI_APIDll , "TMI_RemoteLocal"); |
||
252 | if( TMI_RemoteLocal == NULL ) |
||
253 | return FALSE; |
||
254 | |||
255 | TMI_LocalLockOut = (int ( __stdcall* )(int )) GetProcAddress(TMI_APIDll , "TMI_LocalLockOut"); |
||
256 | if( TMI_LocalLockOut == NULL ) |
||
257 | return FALSE; |
||
258 | |||
259 | TMI_DataBackUp = (int ( __stdcall* )(int )) GetProcAddress(TMI_APIDll , "TMI_DataBackUp"); |
||
260 | if( TMI_DataBackUp == NULL ) |
||
261 | return FALSE; |
||
262 | |||
263 | TMI_SRQEnable = (int ( __stdcall* )(int , unsigned char )) GetProcAddress(TMI_APIDll , "TMI_SRQEnable"); |
||
264 | if( TMI_SRQEnable == NULL ) |
||
265 | return FALSE; |
||
266 | |||
267 | TMI_AllPresetQ = (int ( __stdcall* )(int , double * )) GetProcAddress(TMI_APIDll , "TMI_AllPresetQ"); |
||
268 | if( TMI_AllPresetQ == NULL ) |
||
269 | return FALSE; |
||
270 | |||
271 | TMI_AllPresetQS = (int ( __stdcall* )(int , char * )) GetProcAddress(TMI_APIDll , "TMI_AllPresetQS"); |
||
272 | if( TMI_AllPresetQS == NULL ) |
||
273 | return FALSE; |
||
274 | |||
275 | TMI_Out = (int ( __stdcall* )(int , char * )) GetProcAddress(TMI_APIDll , "TMI_Out"); |
||
276 | if( TMI_Out == NULL ) |
||
277 | return FALSE; |
||
278 | |||
279 | TMI_In = (int ( __stdcall* )(int , char * )) GetProcAddress(TMI_APIDll , "TMI_In"); |
||
280 | if( TMI_In == NULL ) |
||
281 | return FALSE; |
||
282 | |||
283 | TMI_HandleClose = (int ( __stdcall* )( int )) GetProcAddress(TMI_APIDll , "TMI_HandleClose"); |
||
284 | if( TMI_HandleClose == NULL ) |
||
285 | return FALSE; |
||
286 | |||
287 | printf("TMI_In loaded.\n"); |
||
288 | return TRUE; |
||
289 | } |
||
290 | |||
291 | int TMI_OpenHandle(char * dev, char * usb ){ |
||
292 | |||
293 | TMI_DeviceId = TMI_HandleOpen(dev, usb); |
||
294 | return TMI_DeviceId; |
||
295 | } |
||
296 | |||
297 | |||
298 | |||
299 | |||
300 | /****************TOKOVI (potek, kako se spreminjajo tokovi s casom)****************/ |
||
301 | |||
302 | void TMI_ReadCurrent(double * I , double * V, unsigned char * mode, unsigned char *onoff){ |
||
303 | int iRet; |
||
304 | char ch=0; |
||
305 | double Voltage; |
||
306 | double Current; |
||
307 | char cv_cc; |
||
308 | |||
309 | |||
310 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
||
311 | iRet = TMI_Refresh(TMI_DeviceId); |
||
312 | |||
313 | |||
314 | //iRet = TMI_MainOutput(TMI_DeviceId, Output); |
||
315 | //iRet = TMI_MainOutputQ(TMI_DeviceId, &Output); |
||
316 | for (ch=0;ch<4;ch++){ |
||
317 | |||
318 | |||
319 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
||
320 | //if (debug) printf("[%d] %g V %g A CVCC %d\t",ch, Voltage, Current, cv_cc ); |
||
321 | I[ch]= Current; //s tem definiras kaj sta I in V. |
||
322 | V[ch]= Voltage; |
||
323 | |||
324 | |||
325 | } |
||
326 | //if (debug) printf("\n"); |
||
327 | |||
328 | |||
329 | return; |
||
330 | |||
331 | |||
332 | } |
||
333 | |||
334 | |||
335 | #ifdef MAIN |
||
336 | |||
337 | #include <ansi_c.h> |
||
338 | #include <utility.h> |
||
339 | #include "pw18-1.8aq-ctrl.h" |
||
340 | |||
341 | #define RSTREG(a,x) (a&=(~(x))) |
||
342 | #define SETREG(a,x) (a|=x) |
||
343 | |||
344 | int gLogToFile; |
||
345 | int vmon[4]={P1_VMON_1,P1_VMON_2,P1_VMON_3,P1_VMON_4 }; |
||
346 | int imon[4]={P1_IMON_1,P1_IMON_2,P1_IMON_3,P1_IMON_4 }; |
||
347 | int vset[4]={P1_U_1,P1_U_2,P1_U_3,P1_U_4 }; |
||
348 | int iset[4]={P1_I_1,P1_I_2,P1_I_3,P1_I_4 }; |
||
349 | int radiob[4]={P1_BOX_1,P1_BOX_2,P1_BOX_3,P1_BOX_4 }; |
||
350 | |||
351 | int cvcc[4]={P1_CVCC_1,P1_CVCC_2,P1_CVCC_3,P1_CVCC_4 }; |
||
352 | const unsigned char Pre_1 = 1; |
||
353 | int gMask=0xF; |
||
354 | |||
355 | int pnl; |
||
356 | FILE *gFp; |
||
357 | int main (int argc, char *argv[]) |
||
358 | { |
||
359 | int DeviceId=0; |
||
360 | unsigned char MainOutput; |
||
361 | double Voltage, Current, tinterval; |
||
362 | char str[0xFF]; |
||
363 | if (InitCVIRTE (0, argv, 0) == 0) |
||
364 | return -1; /* out of memory */ |
||
365 | SetStdioPort (CVI_STDIO_WINDOW); |
||
366 | if ((pnl = LoadPanel (0, "pw18-1.8aq-ctrl.uir", P1)) < 0) return -1; |
||
367 | |||
368 | if (TMI_Open()== 0) MessagePopup("Error","Cannot open USB device"); |
||
369 | DeviceId = TMI_OpenHandle ("PW-A","USB:1:1"); |
||
370 | if (TMI_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
||
371 | if (DeviceId < 0) MessagePopup("Error","Not Connected"); |
||
372 | printf("TMI device ID %d\n",TMI_DeviceId); |
||
373 | |||
374 | TMI_MainOutputQ(TMI_DeviceId, &MainOutput); |
||
375 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
||
376 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
||
377 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
378 | |||
379 | for (unsigned char ch=0;ch<4;ch++){ |
||
380 | int ison; |
||
381 | TMI_VoltageQ(TMI_DeviceId, ch+1, Pre_1, &Voltage); |
||
382 | TMI_CurrentQ(TMI_DeviceId, ch+1, Pre_1, &Current); |
||
383 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
384 | SetCtrlVal(pnl, iset[ch], Current); |
||
385 | GetCtrlVal(pnl, radiob[ch], &ison); |
||
386 | if (ison) SETREG(gMask,(1<<ch)); else RSTREG(gMask,(1<<ch)); |
||
387 | } |
||
388 | |||
389 | DisplayPanel (pnl); |
||
390 | RunUserInterface (); |
||
391 | DiscardPanel (pnl); |
||
392 | TMI_Close(); |
||
393 | |||
394 | if (gFp) fclose(gFp); |
||
395 | return 0; |
||
396 | } |
||
397 | |||
398 | |||
399 | |||
400 | |||
401 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
||
402 | void *callbackData, int eventData1, int eventData2) |
||
403 | { |
||
404 | unsigned char state; |
||
405 | switch (event) |
||
406 | { |
||
407 | case EVENT_COMMIT: |
||
408 | GetCtrlVal(panel, control, &state); |
||
409 | TMI_MainOutput(TMI_DeviceId, state); |
||
410 | break; |
||
411 | } |
||
412 | return 0; |
||
413 | } |
||
414 | |||
415 | int CVICALLBACK SetCB (int panel, int control, int event, |
||
416 | void *callbackData, int eventData1, int eventData2) |
||
417 | { |
||
418 | |||
419 | |||
420 | switch (event) |
||
421 | { |
||
422 | case EVENT_COMMIT: |
||
423 | |||
424 | for (unsigned char ch = 0; ch<4;ch++){ |
||
425 | //printf("ch %d %x\n", ch, gMask); |
||
426 | if (gMask & (1<<ch)){ |
||
427 | double Voltage; |
||
428 | double Current; |
||
429 | GetCtrlVal(panel, vset[ch], &Voltage); |
||
430 | GetCtrlVal(panel, iset[ch], &Current); |
||
431 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
432 | TMI_Voltage(TMI_DeviceId, ch+1, Pre_1, Voltage); |
||
433 | TMI_VoltageQ(TMI_DeviceId, ch+1, Pre_1, &Voltage); |
||
434 | TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
||
435 | TMI_CurrentQ(TMI_DeviceId, ch+1, Pre_1, &Current); |
||
436 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
437 | |||
438 | } |
||
439 | } |
||
440 | break; |
||
441 | } |
||
442 | return 0; |
||
443 | } |
||
444 | |||
445 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
446 | void *callbackData, int eventData1, int eventData2) |
||
447 | { |
||
448 | |||
449 | int iRet; |
||
450 | char ch=0; |
||
451 | double Voltage; |
||
452 | double Current; |
||
453 | char cv_cc; |
||
454 | switch (event) |
||
455 | { |
||
456 | case EVENT_COMMIT: |
||
457 | for (ch = 0; ch<4;ch++){ |
||
458 | if (gMask & (1<<ch)){ |
||
459 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
||
460 | iRet = TMI_Refresh(TMI_DeviceId); |
||
461 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
||
462 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
463 | SetCtrlVal(panel, vmon[ch], Voltage); |
||
464 | SetCtrlVal(panel, imon[ch], Current); |
||
465 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
466 | } |
||
467 | } |
||
468 | break; |
||
469 | } |
||
470 | return 0; |
||
471 | } |
||
472 | |||
473 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
474 | void *callbackData, int eventData1, int eventData2) { |
||
475 | double tinterval; |
||
476 | switch (event) { |
||
477 | case EVENT_COMMIT: |
||
478 | GetCtrlVal(panel, control, &tinterval); |
||
479 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
480 | break; |
||
481 | } |
||
482 | return 0; |
||
483 | } |
||
484 | |||
485 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
||
486 | void *callbackData, int eventData1, int eventData2) |
||
487 | { |
||
488 | int state; |
||
489 | switch (event) |
||
490 | { |
||
491 | case EVENT_COMMIT: |
||
492 | GetCtrlVal(panel, control, &state); |
||
493 | if (state){ |
||
494 | ResumeTimerCallbacks(); |
||
495 | } else { |
||
496 | SuspendTimerCallbacks (); |
||
497 | printf ("Disabling timer....\n"); |
||
498 | } |
||
499 | break; |
||
500 | } |
||
501 | return 0; |
||
502 | } |
||
503 | |||
504 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
505 | void *callbackData, int eventData1, int eventData2) |
||
506 | { |
||
507 | switch (event) |
||
508 | { |
||
509 | case EVENT_COMMIT: |
||
510 | QuitUserInterface(0); |
||
511 | break; |
||
512 | } |
||
513 | return 0; |
||
514 | } |
||
515 | |||
516 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
||
517 | void *callbackData, int eventData1, int eventData2) |
||
518 | { int ison; |
||
519 | switch (event) |
||
520 | { |
||
521 | case EVENT_COMMIT: |
||
522 | GetCtrlVal(panel, control, &ison); |
||
523 | for (int i=0;i<4;i++) if (control == radiob[i]) break; |
||
524 | if (ison) SETREG(gMask,(1<<i)); else RSTREG(gMask,(1<<i)); |
||
525 | break; |
||
526 | } |
||
527 | return 0; |
||
528 | } |
||
529 | |||
530 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
||
531 | void *callbackData, int eventData1, int eventData2) |
||
532 | { |
||
533 | |||
534 | switch (event) |
||
535 | { |
||
536 | case EVENT_COMMIT: |
||
537 | GetCtrlVal(panel, control, &gLogToFile); |
||
538 | |||
539 | break; |
||
540 | } |
||
541 | return 0; |
||
542 | } |
||
543 | |||
544 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
545 | void *callbackData, int eventData1, int eventData2) |
||
546 | { |
||
547 | switch (event) |
||
548 | { |
||
549 | |||
550 | unsigned char ch; |
||
551 | double current[4]; |
||
552 | double voltage; |
||
553 | char cv_cc; |
||
554 | case EVENT_TIMER_TICK: |
||
555 | for (ch = 0; ch<4;ch++){ |
||
556 | if (gMask & (1<<ch)){ |
||
557 | TMI_TimeOut(TMI_DeviceId, 1); |
||
558 | TMI_Refresh(TMI_DeviceId); |
||
559 | TMI_MoniDataQ(TMI_DeviceId, ch+1, &voltage, ¤t[ch], &cv_cc); |
||
560 | SetCtrlVal(panel, vmon[ch], voltage); |
||
561 | SetCtrlVal(panel, imon[ch], current[ch]); |
||
562 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
563 | if (gLogToFile){ |
||
564 | if (!gFp) { |
||
565 | gFp= fopen("pw18-1.8aq.log","w"); |
||
566 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
||
567 | } |
||
568 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
||
569 | } |
||
570 | } |
||
571 | } |
||
572 | PlotStripChart (panel, P1_GRAPH, current, 4, 0, 0, VAL_DOUBLE); |
||
573 | break; |
||
574 | } |
||
575 | return 0; |
||
576 | } |
||
577 | #endif MAIN |
||
578 |