Rev 308 | Rev 312 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 308 | Rev 310 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | #include "K2231A-ctrl.h" |
2 | #include "K2231A-ctrl.h" |
3 | #include <stdlib.h> |
3 | #include <stdlib.h> |
4 | #include <stdio.h> |
4 | #include <stdio.h> |
5 | #include <windows.h> |
5 | #include <windows.h> |
6 | #include <visa.h> |
6 | #include <visa.h> |
7 | //#include <K2231A.h> |
- | |
8 | - | ||
9 | 7 | ||
- | 8 | static int debug = 0; |
|
10 | static ViStatus istat; |
9 | static ViStatus istat; |
11 | static ViSession |
10 | static ViSession DeviceHandle,RMHandle; |
- | 11 | ||
- | 12 | ||
12 |
|
13 | char response[0xFF]= {0}; |
13 | 14 | ||
- | 15 | ||
14 | 16 | ||
- | 17 | int K2231A_Write(const char *format, ... ) |
|
- | 18 | { |
|
- | 19 | char cmd[0xFF]; |
|
- | 20 | va_list aptr; |
|
- | 21 | va_start(aptr, format); |
|
- | 22 | vsprintf(cmd, format, aptr); |
|
- | 23 | va_end(aptr); |
|
15 | 24 | ||
- | 25 | char str[0xFF]; |
|
- | 26 | sprintf(str, "%s\r\n",cmd); |
|
- | 27 | int istat = viPrintf (DeviceHandle, str); |
|
- | 28 | if (debug) printf("K2231A_Write %s\n", cmd); |
|
- | 29 | return istat; |
|
- | 30 | } |
|
- | 31 | ||
- | 32 | const char * K2231A_Read(const char *format, ... ) |
|
- | 33 | { |
|
- | 34 | ||
- | 35 | char cmd[0xFF]; |
|
- | 36 | va_list aptr; |
|
- | 37 | va_start(aptr, format); |
|
- | 38 | vsprintf(cmd, format, aptr); |
|
- | 39 | va_end(aptr); |
|
- | 40 | ||
- | 41 | char str[0xFF]; |
|
- | 42 | int istat=0; |
|
- | 43 | ||
- | 44 | sprintf(str, "%s\n",cmd); |
|
- | 45 | istat = viPrintf (DeviceHandle, str); |
|
- | 46 | ||
- | 47 | int nb=0; |
|
- | 48 | istat = viRead (DeviceHandle, response, 0xFF, &nb); |
|
- | 49 | ||
- | 50 | if (nb>0) response[nb-1]=0; |
|
- | 51 | if (debug) printf("K2231A_Read %s : %s\n", cmd, response); |
|
- | 52 | if (istat) return NULL; |
|
- | 53 | ||
- | 54 | return response; |
|
- | 55 | } |
|
- | 56 | ||
- | 57 | int K2231A_QueryInt(const char *format, ... ) |
|
- | 58 | { |
|
- | 59 | char cmd[0xFF]; |
|
- | 60 | va_list aptr; |
|
- | 61 | va_start(aptr, format); |
|
- | 62 | vsprintf(cmd, format, aptr); |
|
- | 63 | va_end(aptr); |
|
- | 64 | return atoi(K2231A_Read(cmd )); |
|
- | 65 | } |
|
- | 66 | ||
- | 67 | ||
16 | 68 | ||
- | 69 | double K2231A_QueryDouble(const char *format, ...) { |
|
- | 70 | char cmd[0xFF]; |
|
- | 71 | va_list aptr; |
|
- | 72 | va_start(aptr, format); |
|
- | 73 | vsprintf(cmd, format, aptr); |
|
- | 74 | va_end(aptr); |
|
- | 75 | return atof(K2231A_Read(cmd )); |
|
- | 76 | } |
|
17 | 77 | ||
18 | int K2231A_Initialize() |
78 | int K2231A_Initialize() |
19 | { |
79 | { |
- | 80 | ||
- | 81 | istat = viOpenDefaultRM (&RMHandle); |
|
- | 82 | if (RMHandle) istat = viOpen (RMHandle, "ASRL5::INSTR", VI_NULL, VI_NULL, &DeviceHandle); |
|
- | 83 | if (DeviceHandle) |
|
20 | 84 | { |
|
- | 85 | ||
- | 86 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR, '\n'); |
|
- | 87 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE); |
|
- | 88 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TMO_VALUE, 5000); |
|
- | 89 | ||
- | 90 | ||
- | 91 | printf("\n"); |
|
- | 92 | } |
|
- | 93 | else |
|
- | 94 | { |
|
- | 95 | MessagePopup("Error","Cannot open handle"); |
|
- | 96 | } |
|
- | 97 | ||
- | 98 | ||
21 | return 0; |
99 | return 0; |
22 | } |
100 | } |
- | 101 | ||
23 | 102 | ||
24 | 103 | ||
- | 104 | ||
25 | int K2231A_Test() |
105 | int K2231A_Test() |
26 | { |
106 | { |
27 | char |
107 | char response[0xFF]= {0}; |
- | 108 | int i; |
|
- | 109 | for ( i=0; i<255; i++) response[i]=0; |
|
- | 110 | ||
- | 111 | K2231A_Read("*IDN?"); |
|
28 |
|
112 | K2231A_Read("SYSTem:VERSion?"); |
- | 113 | K2231A_Read("VOLT?"); |
|
- | 114 | K2231A_Read("CURR?"); |
|
- | 115 | K2231A_Read("MEAS:VOLT?"); |
|
- | 116 | K2231A_Read("MEAS:CURR?"); |
|
- | 117 | K2231A_Read("FETC:VOLT?"); |
|
- | 118 | K2231A_Read("FETC:CURR?"); |
|
- | 119 | K2231A_Write("SYSTem:BEEPer"); |
|
29 | return TRUE; |
120 | return TRUE; |
30 | } |
121 | } |
31 | 122 | ||
32 | int K2231A_Close() |
123 | int K2231A_Close() |
33 | { |
124 | { |
34 | - | ||
35 | - | ||
- | 125 | K2231A_Write("syst:loc"); |
|
36 | return 0; |
126 | return 0; |
37 | } |
127 | } |
38 | 128 | ||
39 | int K2231A_Open() |
129 | int K2231A_Open() |
40 | { |
130 | { |
41 | K2231A_Initialize(); |
131 | K2231A_Initialize(); |
- | 132 | K2231A_Write("syst:rem"); |
|
42 | return TRUE; |
133 | return TRUE; |
43 | } |
134 | } |
44 | 135 | ||
45 | int |
136 | int K2231A_RecallFromMemory(int preset){ |
- | 137 | return K2231A_Write("*rcl %d",preset); |
|
- | 138 | } |
|
- | 139 | ||
- | 140 | double K2231A_GetSetCurrent(){ |
|
- | 141 | return K2231A_QueryDouble("CURR?"); |
|
- | 142 | } |
|
- | 143 | ||
- | 144 | double K2231A_GetSetVoltage(){ |
|
- | 145 | return K2231A_QueryDouble("VOLT?"); |
|
- | 146 | } |
|
- | 147 | ||
- | 148 | double K2231A_SetCurrent(double x){ |
|
- | 149 | return K2231A_QueryDouble("CURR %f", x); |
|
- | 150 | } |
|
- | 151 | ||
- | 152 | double K2231A_SetVoltage(double x){ |
|
- | 153 | return K2231A_QueryDouble("VOLT %f", x); |
|
- | 154 | } |
|
- | 155 | ||
- | 156 | double K2231A_GetCurrentMonitor(){ |
|
- | 157 | return K2231A_QueryDouble("MEAS:CURR?"); |
|
- | 158 | } |
|
- | 159 | ||
- | 160 | double K2231A_GetVoltageMonitor(){ |
|
- | 161 | return K2231A_QueryDouble("MEAS:VOLT?"); |
|
- | 162 | } |
|
- | 163 | ||
- | 164 | ||
- | 165 | int K2231A_SelectChannel(int ch){ |
|
- | 166 | return K2231A_Write( "INST CH%d",ch); |
|
- | 167 | } |
|
- | 168 | ||
- | 169 | ||
- | 170 | int K2231A_GetOperationMode(){ |
|
- | 171 | /* |
|
- | 172 | //cv_cc = K2231A_QueryInt("Stat:ques:inst?"); |
|
- | 173 | sprintf(cmd, "Stat:ques:inst:isum%d?",ch+1); |
|
46 | 174 | */ |
|
- | 175 | return K2231A_QueryInt("Stat:ques:inst?"); |
|
- | 176 | } |
|
- | 177 | ||
- | 178 | ||
47 |
|
179 | int K2231A_SetSwitch(int state){ |
- | 180 | K2231A_Write("Outp:enab %d",state); |
|
- | 181 | K2231A_Write("Outp %d",state); |
|
- | 182 | return 0; |
|
- | 183 | } |
|
48 |
|
184 | int K2231A_GetSwitch(){ |
- | 185 | return K2231A_QueryInt("CHAN:OUTP?"); |
|
49 | } |
186 | } |
50 | 187 | ||
51 | 188 | ||
52 | 189 | ||
- | 190 | void K2231A_ReadMonitorValues(double * I , double * V, unsigned char * mode, unsigned char *onoff) |
|
- | 191 | { |
|
- | 192 | int iRet; |
|
- | 193 | char ch=0; |
|
- | 194 | double Voltage; |
|
- | 195 | double Current; |
|
- | 196 | char cv_cc; |
|
- | 197 | ||
- | 198 | for (ch=0; ch<3; ch++) |
|
- | 199 | { |
|
53 | 200 | ||
- | 201 | ||
- | 202 | K2231A_SelectChannel(ch+1); |
|
- | 203 | cv_cc = K2231A_GetOperationMode(); |
|
- | 204 | I[ch]= K2231A_GetCurrentMonitor(); |
|
- | 205 | V[ch]= K2231A_GetVoltageMonitor(); |
|
- | 206 | int onoff=K2231A_QueryInt("OUTP?"); |
|
54 |
|
207 | if (debug) printf("[%d] %g V %g A CVCC %d ONOFF %d\t",ch, V[ch], I[ch], cv_cc, onoff ); |
- | 208 | ||
- | 209 | ||
- | 210 | ||
- | 211 | } |
|
- | 212 | ||
- | 213 | ||
- | 214 | ||
- | 215 | return; |
|
- | 216 | ||
- | 217 | ||
- | 218 | } |
|
55 | 219 | ||
56 | void |
220 | void K2231A_ReadSetValues(double * I , double * V, unsigned char *onoff) |
- | 221 | { |
|
57 |
|
222 | int iRet; |
58 |
|
223 | char ch=0; |
59 |
|
224 | double Voltage; |
60 | double Current; |
225 | double Current; |
61 |
|
226 | char cv_cc; |
62 | 227 | ||
63 | 228 | for (ch=0; ch<3; ch++) |
|
- | 229 | { |
|
- | 230 | ||
- | 231 | ||
- | 232 | K2231A_SelectChannel(ch+1); |
|
64 |
|
233 | cv_cc = K2231A_GetOperationMode(); |
65 |
|
234 | I[ch]= K2231A_GetSetCurrent(); |
- | 235 | V[ch]= K2231A_GetSetVoltage(); |
|
- | 236 | int onoff=K2231A_GetSwitch(); |
|
- | 237 | if (debug) printf("[%d] %g V %g A CVCC %d ONOFF %d\t",ch, V[ch], I[ch], cv_cc, onoff ); |
|
- | 238 | ||
- | 239 | } |
|
66 | 240 | ||
67 | - | ||
68 | //iRet = K2231A_MainOutput(K2231A_DeviceId, Output); |
- | |
69 | //iRet = K2231A_MainOutputQ(K2231A_DeviceId, &Output); |
- | |
70 | for (ch=0;ch<3;ch++){ |
- | |
71 | - | ||
72 | - | ||
73 | //iRet = K2231A_MoniDataQ(K2231A_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
- | |
74 | //if (debug) printf("[%d] %g V %g A CVCC %d\t",ch, Voltage, Current, cv_cc ); |
- | |
75 | I[ch]= Current; //s tem definiras kaj sta I in V. |
- | |
76 | V[ch]= Voltage; |
- | |
77 | - | ||
78 | - | ||
79 | } |
- | |
80 | //if (debug) printf("\n"); |
- | |
81 | - | ||
82 | - | ||
83 | return; |
241 | return; |
84 | - | ||
85 | - | ||
86 | } |
242 | } |
87 | 243 | ||
88 | 244 | ||
89 | #ifdef MAIN |
245 | #ifdef MAIN |
90 | 246 | ||
91 | #include <ansi_c.h> |
247 | #include <ansi_c.h> |
92 | #include <utility.h> |
248 | #include <utility.h> |
93 | 249 | ||
94 | 250 | ||
95 | #define RSTREG(a,x) (a&=(~(x))) |
251 | #define RSTREG(a,x) (a&=(~(x))) |
96 | #define SETREG(a,x) (a|=x) |
252 | #define SETREG(a,x) (a|=x) |
97 | 253 | ||
98 | int gLogToFile; |
254 | int gLogToFile; |
99 | int vmon[3]={P1_VMON_1,P1_VMON_2,P1_VMON_3 }; |
255 | int vmon[3]= {P1_VMON_1,P1_VMON_2,P1_VMON_3 }; |
100 | int imon[3]={P1_IMON_1,P1_IMON_2,P1_IMON_3 }; |
256 | int imon[3]= {P1_IMON_1,P1_IMON_2,P1_IMON_3 }; |
101 | int vset[3]={P1_U_1,P1_U_2,P1_U_3 }; |
257 | int vset[3]= {P1_U_1,P1_U_2,P1_U_3 }; |
102 | int iset[3]={P1_I_1,P1_I_2,P1_I_3 }; |
258 | int iset[3]= {P1_I_1,P1_I_2,P1_I_3 }; |
103 | int radiob[3]={P1_BOX_1,P1_BOX_2,P1_BOX_3 }; |
259 | int radiob[3]= {P1_BOX_1,P1_BOX_2,P1_BOX_3 }; |
- | 260 | ||
- | 261 | int cvcc[3]= {P1_CVCC_1,P1_CVCC_2,P1_CVCC_3 }; |
|
104 | 262 | ||
105 | int cvcc[3]={P1_CVCC_1,P1_CVCC_2,P1_CVCC_3 }; |
- | |
106 | - | ||
107 | int gMask=0xF; |
263 | int gMask=0xF; |
108 | 264 | ||
109 | int pnl; |
265 | int pnl; |
110 | FILE *gFp; |
266 | FILE *gFp; |
111 | int main (int argc, char *argv[]) |
267 | int main (int argc, char *argv[]) |
112 | { |
268 | { |
113 | int DeviceId=0; |
269 | int DeviceId=0; |
114 | unsigned char MainOutput, |
270 | unsigned char MainOutput=0, preset=0; |
115 | double |
271 | double Voltage=0, Current=0, tinterval=1; |
116 | char str[0xFF]; |
272 | char str[0xFF]; |
- | 273 | int i=0; |
|
- | 274 | char response[0xFF]; |
|
117 | if (InitCVIRTE (0, argv, 0) == 0) |
275 | if (InitCVIRTE (0, argv, 0) == 0) |
118 | return -1; /* out of memory */ |
276 | return -1; /* out of memory */ |
119 | SetStdioPort (CVI_STDIO_WINDOW); |
277 | SetStdioPort (CVI_STDIO_WINDOW); |
120 | SetStdioWindowOptions (1000, |
278 | SetStdioWindowOptions (1000, 1, 0); |
121 | SetStdioWindowSize (150, 600); |
279 | SetStdioWindowSize (150, 600); |
122 | SetStdioWindowPosition (825, 20); |
280 | SetStdioWindowPosition (825, 20); |
123 | - | ||
124 | istat = viOpenDefaultRM (&RMHandle); |
- | |
125 | if (RMHandle) istat = viOpen (RMHandle, "TCPIP0::178.172.43.91::5000::SOCKET", VI_NULL, VI_NULL, &RedPHandle); |
- | |
126 | if (RedPHandle){ |
- | |
127 | istat = viSetAttribute (RedPHandle, VI_ATTR_TCPIP_KEEPALIVE, VI_TRUE); |
- | |
128 | istat = viSetAttribute (RedPHandle, VI_ATTR_TCPIP_NODELAY, VI_TRUE); |
- | |
129 | istat = viSetAttribute (RedPHandle, VI_ATTR_TERMCHAR, '\n'); |
- | |
130 | istat = viSetAttribute (RedPHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE); |
- | |
131 | istat = viSetAttribute (RedPHandle, VI_ATTR_TMO_VALUE, 1000); |
- | |
132 | } |
- | |
133 | - | ||
134 | - | ||
135 | - | ||
136 | - | ||
137 | if ((pnl = LoadPanel (0, "K2231A-ctrl.uir", P1)) < 0) return -1; |
- | |
138 | 281 | ||
- | 282 | ||
- | 283 | if ((pnl = LoadPanel (0, "K2231A-ctrl.uir", P1)) < 0) return -1; |
|
- | 284 | ||
139 | if |
285 | if (K2231A_Open()== 0) MessagePopup("Error","Cannot open USB device"); |
140 | //DeviceId = K2231A_OpenHandle ("PW-A","USB:1:1"); |
- | |
- | 286 | ||
141 | if (K2231A_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
287 | if (K2231A_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
142 | if (DeviceId < 0) MessagePopup("Error","Not Connected"); |
- | |
143 | printf("TMI device ID %d\n",K2231A_DeviceId); |
- | |
144 | 288 | ||
145 | //K2231A_MainOutputQ(K2231A_DeviceId, &MainOutput); |
- | |
- | 289 | ||
- | 290 | ||
146 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
291 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
147 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
292 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
148 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
293 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
149 | //K2231A_PresetQ(K2231A_DeviceId, &preset); |
- | |
- | 294 | ||
150 | SetCtrlVal(pnl, P1_PRESET, preset); |
295 | SetCtrlVal(pnl, P1_PRESET, preset); |
151 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
296 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
152 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
297 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
153 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
298 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
154 | 299 | ||
155 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
300 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
156 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
301 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
157 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
302 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
- | 303 | int ison; |
|
158 | for (unsigned |
304 | for (unsigned char ch=0; ch<3; ch++) |
- | 305 | { |
|
- | 306 | ||
159 |
|
307 | K2231A_SelectChannel(ch+1); |
- | 308 | ||
160 |
|
309 | Voltage =K2231A_GetSetVoltage(); |
161 |
|
310 | Current =K2231A_GetSetCurrent(); |
- | 311 | ison =K2231A_GetSwitch(); |
|
- | 312 | ||
- | 313 | ||
- | 314 | ||
162 | SetCtrlVal(pnl, vset[ch], Voltage); |
315 | SetCtrlVal(pnl, vset[ch], Voltage); |
163 | SetCtrlVal(pnl, iset[ch], Current); |
316 | SetCtrlVal(pnl, iset[ch], Current); |
164 |
|
317 | SetCtrlVal(pnl, radiob[ch], ison); |
165 | if |
318 | if (ison) SETREG(gMask,(1<<ch)); |
- | 319 | else RSTREG(gMask,(1<<ch)); |
|
166 | } |
320 | } |
167 | 321 | ||
168 | DisplayPanel (pnl); |
322 | DisplayPanel (pnl); |
169 | RunUserInterface (); |
323 | RunUserInterface (); |
170 | DiscardPanel (pnl); |
324 | DiscardPanel (pnl); |
171 | K2231A_Close(); |
325 | K2231A_Close(); |
172 | 326 | ||
173 | if (gFp) fclose(gFp); |
327 | if (gFp) fclose(gFp); |
174 | return 0; |
328 | return 0; |
175 | } |
329 | } |
176 | 330 | ||
177 | 331 | ||
178 | 332 | ||
179 | 333 | ||
180 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
334 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
181 | void *callbackData, int eventData1, int eventData2) |
335 | void *callbackData, int eventData1, int eventData2) |
182 | { |
336 | { |
183 | unsigned char state; |
337 | unsigned char state; |
184 | switch (event) |
338 | switch (event) |
185 | { |
339 | { |
186 | case EVENT_COMMIT: |
340 | case EVENT_COMMIT: |
187 | GetCtrlVal(panel, control, &state); |
341 | GetCtrlVal(panel, control, &state); |
- | 342 | ||
- | 343 | ||
188 |
|
344 | K2231A_SetSwitch(state); |
- | 345 | ||
189 | break; |
346 | break; |
190 | } |
347 | } |
191 | return 0; |
348 | return 0; |
192 | } |
349 | } |
193 | 350 | ||
194 | int CVICALLBACK SetCB (int panel, int control, int event, |
351 | int CVICALLBACK SetCB (int panel, int control, int event, |
195 | void *callbackData, int eventData1, int eventData2) |
352 | void *callbackData, int eventData1, int eventData2) |
196 | { |
353 | { |
197 | 354 | ||
198 | 355 | ||
199 | switch (event) |
356 | switch (event) |
200 | { |
357 | { |
201 | case EVENT_COMMIT: |
358 | case EVENT_COMMIT: |
- | 359 | { |
|
202 | unsigned char preset; |
360 | unsigned char preset=0; |
203 | //K2231A_PresetQ(K2231A_DeviceId, &preset); |
- | |
- | 361 | ||
204 | SetCtrlVal(pnl |
362 | SetCtrlVal(pnl, P1_PRESET, preset); |
205 | for (unsigned char |
363 | for (unsigned char ch = 0; ch<3; ch++) |
- | 364 | { |
|
206 | //printf("ch %d %x\n", ch, gMask); |
365 | //printf("ch %d %x\n", ch, gMask); |
207 | if |
366 | if (gMask & (1<<ch)) |
- | 367 | { |
|
208 | double Voltage; |
368 | double Voltage; |
209 | double Current; |
369 | double Current; |
- | 370 | ||
- | 371 | GetCtrlVal(panel, vset[ch], &Voltage); |
|
- | 372 | GetCtrlVal(panel, iset[ch], &Current); |
|
- | 373 | ||
- | 374 | ||
- | 375 | char cmd[0xFF]; |
|
210 | 376 | ||
211 | GetCtrlVal(panel, vset[ch], &Voltage); |
- | |
212 |
|
377 | K2231A_SelectChannel(ch+1); |
213 | //printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
- | |
- | 378 | ||
214 |
|
379 | Voltage =K2231A_GetVoltageMonitor(); |
215 | //K2231A_VoltageQ(K2231A_DeviceId, ch+1, preset, &Voltage); |
- | |
216 | //K2231A_Current(K2231A_DeviceId, ch+1, preset, Current); |
- | |
217 |
|
380 | Current =K2231A_GetCurrentMonitor(); |
- | 381 | ||
- | 382 | ||
218 |
|
383 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
219 | 384 | ||
220 | } |
385 | } |
221 | } |
386 | } |
222 | } |
387 | } |
223 | break; |
388 | break; |
224 | } |
389 | } |
225 | return 0; |
390 | return 0; |
226 | } |
391 | } |
227 | 392 | ||
228 | int CVICALLBACK ReadCB (int panel, int control, int event, |
393 | int CVICALLBACK ReadCB (int panel, int control, int event, |
229 | void *callbackData, int eventData1, int eventData2) |
394 | void *callbackData, int eventData1, int eventData2) |
230 | { |
395 | { |
231 | 396 | ||
232 | int iRet; |
397 | int iRet; |
233 |
|
398 | char ch=0; |
234 |
|
399 | double Voltage=0; |
235 | double |
400 | double Current=0; |
236 |
|
401 | char cv_cc=0; |
237 | switch (event) |
402 | switch (event) |
238 | { |
403 | { |
239 | case EVENT_COMMIT: |
404 | case EVENT_COMMIT: |
- | 405 | ||
240 | for |
406 | for (ch = 0; ch<3; ch++) |
- | 407 | { |
|
241 | if |
408 | if (gMask & (1<<ch)) |
- | 409 | { |
|
- | 410 | K2231A_SelectChannel(ch+1); |
|
- | 411 | ||
242 |
|
412 | Voltage =K2231A_GetVoltageMonitor(); |
243 |
|
413 | Current =K2231A_GetCurrentMonitor(); |
- | 414 | ||
244 |
|
415 | cv_cc = K2231A_GetOperationMode(); |
- | 416 | ||
245 |
|
417 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
246 | SetCtrlVal(panel, vmon[ch], Voltage); |
418 | SetCtrlVal(panel, vmon[ch], Voltage); |
247 | SetCtrlVal(panel, imon[ch], Current); |
419 | SetCtrlVal(panel, imon[ch], Current); |
248 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
420 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
249 | } |
421 | } |
250 | } |
422 | } |
251 | break; |
423 | break; |
252 | } |
424 | } |
253 | return 0; |
425 | return 0; |
254 | } |
426 | } |
255 | 427 | ||
256 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
428 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
257 | void |
429 | void *callbackData, int eventData1, int eventData2) |
- | 430 | { |
|
258 | double tinterval; |
431 | double tinterval; |
259 | switch |
432 | switch (event) |
- | 433 | { |
|
260 | case EVENT_COMMIT: |
434 | case EVENT_COMMIT: |
261 | GetCtrlVal(panel, control, &tinterval); |
435 | GetCtrlVal(panel, control, &tinterval); |
262 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
436 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
263 | break; |
437 | break; |
264 | } |
438 | } |
265 | return 0; |
439 | return 0; |
266 | } |
440 | } |
267 | 441 | ||
268 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
442 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
269 | void *callbackData, int eventData1, int eventData2) |
443 | void *callbackData, int eventData1, int eventData2) |
270 | { |
444 | { |
271 | int state; |
445 | int state; |
272 | switch (event) |
446 | switch (event) |
273 | { |
447 | { |
274 | case EVENT_COMMIT: |
448 | case EVENT_COMMIT: |
275 | GetCtrlVal(panel, control, &state); |
449 | GetCtrlVal(panel, control, &state); |
276 | if |
450 | if (state) |
- | 451 | { |
|
- | 452 | SetCtrlAttribute (panel, P1_TIMER, ATTR_ENABLED, 1); |
|
277 | ResumeTimerCallbacks(); |
453 | ResumeTimerCallbacks(); |
- | 454 | } |
|
278 |
|
455 | else |
- | 456 | { |
|
279 | SuspendTimerCallbacks (); |
457 | SuspendTimerCallbacks (); |
280 | printf ("Disabling timer....\n"); |
458 | printf ("Disabling timer....\n"); |
281 | } |
459 | } |
282 | break; |
460 | break; |
283 | } |
461 | } |
284 | return 0; |
462 | return 0; |
285 | } |
463 | } |
286 | 464 | ||
287 | int CVICALLBACK ExitCB (int panel, int control, int event, |
465 | int CVICALLBACK ExitCB (int panel, int control, int event, |
288 | void *callbackData, int eventData1, int eventData2) |
466 | void *callbackData, int eventData1, int eventData2) |
289 | { |
- | |
290 | switch (event) |
- | |
291 | { |
- | |
292 | case EVENT_COMMIT: |
- | |
293 | QuitUserInterface(0); |
- | |
294 | break; |
- | |
295 | } |
- | |
296 | return 0; |
- | |
297 | } |
- | |
298 | - | ||
299 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
- | |
300 | void *callbackData, int eventData1, int eventData2) |
- | |
301 | { int ison; |
- | |
302 | switch (event) |
- | |
303 | { |
- | |
304 | int i=0; |
- | |
305 | case EVENT_COMMIT: |
- | |
306 | GetCtrlVal(panel, control, &ison); |
- | |
307 | for (i=0;i<3;i++) if (control == radiob[i]) break; |
- | |
308 | if (ison) SETREG(gMask,(1<<i)); else RSTREG(gMask,(1<<i)); |
- | |
309 | break; |
- | |
310 | } |
- | |
311 | return 0; |
- | |
312 | } |
- | |
313 | - | ||
314 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
- | |
315 | void *callbackData, int eventData1, int eventData2) |
- | |
316 | { |
467 | { |
- | 468 | switch (event) |
|
317 | 469 | { |
|
- | 470 | case EVENT_COMMIT: |
|
- | 471 | QuitUserInterface(0); |
|
- | 472 | break; |
|
- | 473 | } |
|
- | 474 | return 0; |
|
- | 475 | } |
|
- | 476 | ||
- | 477 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
|
- | 478 | void *callbackData, int eventData1, int eventData2) |
|
- | 479 | { |
|
- | 480 | int ison; |
|
- | 481 | switch (event) |
|
- | 482 | { |
|
- | 483 | int i=0; |
|
- | 484 | case EVENT_COMMIT: |
|
- | 485 | GetCtrlVal(panel, control, &ison); |
|
- | 486 | for (i=0; i<3; i++) if (control == radiob[i]) break; |
|
- | 487 | if (ison) SETREG(gMask,(1<<i)); |
|
- | 488 | else RSTREG(gMask,(1<<i)); |
|
- | 489 | break; |
|
- | 490 | } |
|
- | 491 | return 0; |
|
- | 492 | } |
|
- | 493 | ||
- | 494 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
|
- | 495 | void *callbackData, int eventData1, int eventData2) |
|
- | 496 | { |
|
- | 497 | ||
318 | switch (event) |
498 | switch (event) |
319 | { |
499 | { |
320 | case EVENT_COMMIT: |
500 | case EVENT_COMMIT: |
321 | GetCtrlVal(panel, control, &gLogToFile); |
501 | GetCtrlVal(panel, control, &gLogToFile); |
322 | 502 | ||
323 | break; |
503 | break; |
324 | } |
504 | } |
325 | return 0; |
505 | return 0; |
326 | } |
506 | } |
327 | 507 | ||
328 | int CVICALLBACK TimerCB (int panel, int control, int event, |
508 | int CVICALLBACK TimerCB (int panel, int control, int event, |
329 | void *callbackData, int eventData1, int eventData2) |
509 | void *callbackData, int eventData1, int eventData2) |
330 | { |
510 | { |
331 | switch (event) |
511 | switch (event) |
332 | { |
512 | { |
333 | 513 | ||
334 | unsigned char ch; |
514 | unsigned char ch; |
335 | double |
515 | double current[3]= {0,0,0}; |
336 | double |
516 | double voltage[3]= {0,0,0}; |
337 | char |
517 | char cv_cc=0; |
338 | case EVENT_TIMER_TICK: |
518 | case EVENT_TIMER_TICK: |
339 | for |
519 | for (ch = 0; ch<3; ch++) |
- | 520 | { |
|
340 | if |
521 | if (gMask & (1<<ch)) |
- | 522 | { |
|
- | 523 | ||
341 |
|
524 | K2231A_SelectChannel(ch+1); |
- | 525 | ||
342 |
|
526 | voltage[ch] =K2231A_GetVoltageMonitor(); |
343 |
|
527 | current[ch] =K2231A_GetCurrentMonitor(); |
- | 528 | cv_cc = K2231A_GetOperationMode(); |
|
- | 529 | int onoff=K2231A_GetSwitch(); |
|
- | 530 | ||
- | 531 | ||
- | 532 | ||
344 | SetCtrlVal(panel, vmon[ch], voltage[ch]); |
533 | SetCtrlVal(panel, vmon[ch], voltage[ch]); |
345 | SetCtrlVal(panel, imon[ch], current[ch]); |
534 | SetCtrlVal(panel, imon[ch], current[ch]); |
346 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
535 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
- | 536 | SetCtrlVal(panel, P1_ONOFFLED, onoff); |
|
347 | if |
537 | if (gLogToFile) |
- | 538 | { |
|
348 | if |
539 | if (!gFp) |
- | 540 | { |
|
349 | gFp= fopen("pw18-1.8aq.log","w"); |
541 | gFp= fopen("pw18-1.8aq.log","w"); |
350 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
542 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
351 | } |
543 | } |
352 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage[ch], current[ch], cv_cc); |
544 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage[ch], current[ch], cv_cc); |
353 | } |
545 | } |
354 | } |
546 | } |
355 | } |
547 | } |
356 | PlotStripChart (panel, P1_GRAPH_IMON, current, 3, 0, 0, VAL_DOUBLE); |
548 | PlotStripChart (panel, P1_GRAPH_IMON, current, 3, 0, 0, VAL_DOUBLE); |
357 | PlotStripChart (panel, P1_GRAPH_VMON, voltage, 3, 0, 0, VAL_DOUBLE); |
549 | PlotStripChart (panel, P1_GRAPH_VMON, voltage, 3, 0, 0, VAL_DOUBLE); |
358 | break; |
550 | break; |
359 | } |
551 | } |
360 | return 0; |
552 | return 0; |
361 | } |
553 | } |
362 | - | ||
363 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
- | |
364 | void *callbackData, int eventData1, int eventData2) { |
- | |
365 | 554 | ||
- | 555 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
|
- | 556 | void *callbackData, int eventData1, int eventData2) |
|
- | 557 | { |
|
- | 558 | char cmd[0xFF]; |
|
366 | switch (event) |
559 | switch (event) |
- | 560 | { |
|
367 | case EVENT_COMMIT: |
561 | case EVENT_COMMIT: |
- | 562 | { |
|
368 | unsigned char preset; |
563 | unsigned char preset; |
369 | double Voltage, Current; |
564 | double Voltage, Current; |
370 | GetCtrlVal(panel, control, &preset); |
565 | GetCtrlVal(panel, control, &preset); |
371 | //K2231A_Preset(K2231A_DeviceId, preset); |
- | |
372 | 566 | ||
- | 567 | K2231A_RecallFromMemory(preset); |
|
373 | for (unsigned char ch=0;ch<3;ch++) |
568 | for (unsigned char ch=0; ch<3; ch++) |
- | 569 | { |
|
374 | int ison; |
570 | int ison; |
- | 571 | K2231A_SelectChannel(ch+1); |
|
375 |
|
572 | Voltage =K2231A_GetSetVoltage(); |
376 |
|
573 | Current =K2231A_GetSetCurrent(); |
- | 574 | ison =K2231A_GetSwitch(); |
|
- | 575 | ||
377 | SetCtrlVal(pnl, vset[ch], Voltage); |
576 | SetCtrlVal(pnl, vset[ch], Voltage); |
378 | SetCtrlVal(pnl, iset[ch], Current); |
577 | SetCtrlVal(pnl, iset[ch], Current); |
379 | GetCtrlVal(pnl, radiob[ch], &ison); |
578 | GetCtrlVal(pnl, radiob[ch], &ison); |
380 |
|
579 | if (ison) SETREG(gMask,(1<<ch)); |
- | 580 | else RSTREG(gMask,(1<<ch)); |
|
381 | } |
581 | } |
382 | break; |
582 | break; |
383 | } |
583 | } |
- | 584 | } |
|
- | 585 | return 0; |
|
- | 586 | } |
|
- | 587 | ||
- | 588 | int CVICALLBACK DebugCB (int panel, int control, int event, |
|
- | 589 | void *callbackData, int eventData1, int eventData2) |
|
- | 590 | { |
|
- | 591 | switch (event) |
|
- | 592 | { |
|
- | 593 | case EVENT_COMMIT: |
|
- | 594 | GetCtrlVal(panel, control, &debug); |
|
- | 595 | break; |
|
384 | } |
596 | } |
385 | return 0; |
597 | return 0; |
386 | } |
598 | } |
387 | 599 | ||
388 | 600 | ||
389 | #endif MAIN |
601 | #endif MAIN |
390 | 602 |