Rev 256 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 256 | Rev 279 | ||
---|---|---|---|
1 | #include <ansi_c.h> |
1 | #include <ansi_c.h> |
2 | #include <utility.h> |
2 | #include <utility.h> |
3 | #include <gpib.h> |
3 | #include <gpib.h> |
4 | #include "prologix.h" |
4 | #include "prologix.h" |
5 | #include "K617.h" |
5 | #include "K617.h" |
6 | 6 | ||
7 | K617STATUS K617Stat; |
7 | K617STATUS K617Stat; |
8 | static int K617_Interface,K617_Port,K617_Gdev; |
8 | static int K617_Interface,K617_Port,K617_Gdev; |
9 | static int iret; |
9 | static int iret; |
10 | 10 | ||
11 | void GpibError(char *msg) { |
11 | void GpibError(char *msg) { |
12 | 12 | ||
13 | printf ("%s\n", msg); |
13 | printf ("%s\n", msg); |
14 | 14 | ||
15 | printf ("ibsta = &H%x <", ibsta); |
15 | printf ("ibsta = &H%x <", ibsta); |
16 | if (ibsta & ERR ) printf (" ERR"); |
16 | if (ibsta & ERR ) printf (" ERR"); |
17 | if (ibsta & TIMO) printf (" TIMO"); |
17 | if (ibsta & TIMO) printf (" TIMO"); |
18 | if (ibsta & END ) printf (" END"); |
18 | if (ibsta & END ) printf (" END"); |
19 | if (ibsta & SRQI) printf (" SRQI"); |
19 | if (ibsta & SRQI) printf (" SRQI"); |
20 | if (ibsta & RQS ) printf (" RQS"); |
20 | if (ibsta & RQS ) printf (" RQS"); |
21 | if (ibsta & CMPL) printf (" CMPL"); |
21 | if (ibsta & CMPL) printf (" CMPL"); |
22 | if (ibsta & LOK ) printf (" LOK"); |
22 | if (ibsta & LOK ) printf (" LOK"); |
23 | if (ibsta & REM ) printf (" REM"); |
23 | if (ibsta & REM ) printf (" REM"); |
24 | if (ibsta & CIC ) printf (" CIC"); |
24 | if (ibsta & CIC ) printf (" CIC"); |
25 | if (ibsta & ATN ) printf (" ATN"); |
25 | if (ibsta & ATN ) printf (" ATN"); |
26 | if (ibsta & TACS) printf (" TACS"); |
26 | if (ibsta & TACS) printf (" TACS"); |
27 | if (ibsta & LACS) printf (" LACS"); |
27 | if (ibsta & LACS) printf (" LACS"); |
28 | if (ibsta & DTAS) printf (" DTAS"); |
28 | if (ibsta & DTAS) printf (" DTAS"); |
29 | if (ibsta & DCAS) printf (" DCAS"); |
29 | if (ibsta & DCAS) printf (" DCAS"); |
30 | printf (" >\n"); |
30 | printf (" >\n"); |
31 | 31 | ||
32 | printf ("iberr = %d", iberr); |
32 | printf ("iberr = %d", iberr); |
33 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
33 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
34 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
34 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
35 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
35 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
36 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
36 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
37 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
37 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
38 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
38 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
39 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
39 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
40 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
40 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
41 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
41 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
42 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
42 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
43 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
43 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
44 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
44 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
45 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
45 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
46 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
46 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
47 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
47 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
48 | 48 | ||
49 | printf ("ibcntl = %ld\n", ibcntl); |
49 | printf ("ibcntl = %ld\n", ibcntl); |
50 | printf ("\n"); |
50 | printf ("\n"); |
51 | 51 | ||
52 | /* Call ibonl to take the device and interface offline */ |
52 | /* Call ibonl to take the device and interface offline */ |
53 | ibonl (K617_Gdev,0); |
53 | ibonl (K617_Gdev,0); |
54 | 54 | ||
55 | exit(1); |
55 | exit(1); |
56 | } |
56 | } |
57 | 57 | ||
58 | void _VI_FUNC K617_open (int interface, int port, int primary_addr, |
58 | void _VI_FUNC K617_open (int interface, int port, int primary_addr, |
59 | int secondary_addr, int timeout) |
59 | int secondary_addr, int timeout) |
60 | { |
60 | { |
61 | char cmd[100]; |
61 | char cmd[100]; |
62 | /* |
62 | /* |
63 | K617_Gdev = OpenDev ("GPIB0", ""); |
63 | K617_Gdev = OpenDev ("GPIB0", ""); |
64 | if (ibsta & ERR) GpibError("OpenDev Error"); |
64 | if (ibsta & ERR) GpibError("OpenDev Error"); |
65 | iret = ibpad (K617_Gdev, 0); |
65 | iret = ibpad (K617_Gdev, 0); |
66 | if (ibsta & ERR) GpibError("OpenDev Error"); |
66 | if (ibsta & ERR) GpibError("OpenDev Error"); |
67 | iret = ibsad (K617_Gdev, NO_SAD); |
67 | iret = ibsad (K617_Gdev, NO_SAD); |
68 | iret = ibtmo (K617_Gdev, T10s); |
68 | iret = ibtmo (K617_Gdev, T10s); |
69 | iret = ibeot (K617_Gdev, 1); |
69 | iret = ibeot (K617_Gdev, 1); |
70 | iret = ibeos (K617_Gdev, 0); |
70 | iret = ibeos (K617_Gdev, 0); |
71 | */ |
71 | */ |
72 | K617_Interface=interface; |
72 | K617_Interface=interface; |
73 | K617_Port=port; |
73 | K617_Port=port; |
74 | switch (K617_Interface){ |
74 | switch (K617_Interface){ |
75 | case 1: |
75 | case 1: |
76 | PROLOGIX_Open (K617_Port); |
76 | PROLOGIX_Open (K617_Port); |
77 | sprintf(cmd,"++addr %0d",primary_addr); |
77 | sprintf(cmd,"++addr %0d",primary_addr); |
78 | PROLOGIX_Send (cmd); |
78 | PROLOGIX_Send (cmd); |
79 | PROLOGIX_Send ("++auto 0"); |
79 | PROLOGIX_Send ("++auto 0"); |
80 | PROLOGIX_Send ("++eoi 1"); |
80 | PROLOGIX_Send ("++eoi 1"); |
81 | PROLOGIX_Send ("++eot_enable 0"); |
81 | PROLOGIX_Send ("++eot_enable 0"); |
82 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
82 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
83 | break; |
83 | break; |
84 | default: |
84 | default: |
85 | K617_Gdev = ibdev(K617_Port,primary_addr,secondary_addr,timeout,1,0); |
85 | K617_Gdev = ibdev(K617_Port,primary_addr,secondary_addr,timeout,1,0); |
86 | if (ibsta & ERR) GpibError("OpenDev Error"); |
86 | if (ibsta & ERR) GpibError("OpenDev Error"); |
87 | } |
87 | } |
88 | Delay(GDELAY); |
88 | Delay(GDELAY); |
89 | return; |
89 | return; |
90 | } |
90 | } |
91 | 91 | ||
92 | void _VI_FUNC K617_clear (void) |
92 | void _VI_FUNC K617_clear (void) |
93 | { |
93 | { |
94 | switch (K617_Interface){ |
94 | switch (K617_Interface){ |
95 | case 1: |
95 | case 1: |
96 | PROLOGIX_Send("++clr"); |
96 | PROLOGIX_Send("++clr"); |
97 | break; |
97 | break; |
98 | default: |
98 | default: |
99 | iret = ibclr (K617_Gdev); // Clear the device |
99 | iret = ibclr (K617_Gdev); // Clear the device |
100 | if (ibsta & ERR) GpibError("OpenDev Error"); |
100 | if (ibsta & ERR) GpibError("OpenDev Error"); |
101 | } |
101 | } |
102 | // Delay(GDELAY); |
102 | // Delay(GDELAY); |
103 | Delay(2.); |
103 | Delay(2.); |
104 | return; |
104 | return; |
105 | } |
105 | } |
106 | 106 | ||
107 | void _VI_FUNC K617_send (char *cmd, int len) |
107 | void _VI_FUNC K617_send (char *cmd, int len) |
108 | { |
108 | { |
109 | switch (K617_Interface){ |
109 | switch (K617_Interface){ |
110 | case 1: |
110 | case 1: |
111 | PROLOGIX_Send(cmd); |
111 | PROLOGIX_Send(cmd); |
112 | break; |
112 | break; |
113 | default: |
113 | default: |
114 | iret = ibwrt (K617_Gdev, cmd, len); |
114 | iret = ibwrt (K617_Gdev, cmd, len); |
115 | if (ibsta & ERR) GpibError("OpenDev Error"); |
115 | if (ibsta & ERR) GpibError("OpenDev Error"); |
116 | } |
116 | } |
117 | Delay(GDELAY); |
117 | Delay(GDELAY); |
118 | return; |
118 | return; |
119 | } |
119 | } |
120 | 120 | ||
121 | int _VI_FUNC K617_receive (char *response, int maxbyt) |
121 | int _VI_FUNC K617_receive (char *response, int maxbyt) |
122 | { |
122 | { |
123 | switch (K617_Interface){ |
123 | switch (K617_Interface){ |
124 | case 1: |
124 | case 1: |
125 | PROLOGIX_Send("++read eoi"); |
125 | PROLOGIX_Send("++read eoi"); |
126 | return PROLOGIX_Receive (response,maxbyt); |
126 | return PROLOGIX_Receive (response,maxbyt); |
127 | break; |
127 | break; |
128 | default: |
128 | default: |
129 | iret = ibrd (K617_Gdev, response, maxbyt); |
129 | iret = ibrd (K617_Gdev, response, maxbyt); |
130 | if (ibsta & ERR) GpibError("OpenDev Error"); |
130 | if (ibsta & ERR) GpibError("OpenDev Error"); |
131 | response[ibcntl]=0; |
131 | response[ibcntl]=0; |
132 | return ibcntl; |
132 | return ibcntl; |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | void _VI_FUNC K617_status (void) |
136 | void _VI_FUNC K617_status (void) |
137 | { |
137 | { |
138 | int len; |
138 | int len; |
139 | char cres[100]; |
139 | char cres[100]; |
140 | 140 | ||
141 | K617_send ("U0X", 3); |
141 | K617_send ("U0X", 3); |
142 | len = K617_receive (cres, 90); |
142 | len = K617_receive (cres, 90); |
143 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
143 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
144 | &K617Stat.function,&K617Stat.range,&K617Stat.zero_check, |
144 | &K617Stat.function,&K617Stat.range,&K617Stat.zero_check, |
145 | &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger, |
145 | &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger, |
146 | &K617Stat.vsource_operate,&K617Stat.read_mode, |
146 | &K617Stat.vsource_operate,&K617Stat.read_mode, |
147 | &K617Stat.data_prefix,&K617Stat.display, |
147 | &K617Stat.data_prefix,&K617Stat.display, |
148 | &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator); |
148 | &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator); |
149 | // printf("617FRRCZNTOBGDQMMKYY\n"); |
149 | // printf("617FRRCZNTOBGDQMMKYY\n"); |
150 | // printf("%s\n",cres); |
150 | // printf("%s\n",cres); |
151 | // K617_send ("X", 1); |
151 | // K617_send ("X", 1); |
152 | return; |
152 | return; |
153 | } |
153 | } |
154 | 154 | ||
155 | void _VI_FUNC K617_data_format (int mode) |
155 | void _VI_FUNC K617_data_format (int mode) |
156 | { |
156 | { |
157 | int len; |
157 | int len; |
158 | char cmd[100]; |
158 | char cmd[100]; |
159 | 159 | ||
160 | len=sprintf(cmd,"G%0dX",mode); |
160 | len=sprintf(cmd,"G%0dX",mode); |
161 | K617_send (cmd, len); |
161 | K617_send (cmd, len); |
162 | return; |
162 | return; |
163 | } |
163 | } |
164 | 164 | ||
165 | double _VI_FUNC K617_get (char *prefix, int *loc) |
165 | double _VI_FUNC K617_get (char *prefix, int *loc) |
166 | { |
166 | { |
167 | int len; |
167 | int len; |
168 | double value; |
168 | double value; |
169 | char cres[100]; |
169 | char cres[100]; |
170 | 170 | ||
171 | K617_send ("X", 1); |
171 | K617_send ("X", 1); |
172 | len = K617_receive (cres, 50); |
172 | len = K617_receive (cres, 50); |
173 | if (loc) { |
173 | if (loc) { |
174 | *loc=-1; |
174 | *loc=-1; |
175 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
175 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
176 | prefix[4]=0; |
176 | prefix[4]=0; |
177 | } else { |
177 | } else { |
178 | sscanf(cres,"%*4c%lg,%*d",&value); |
178 | sscanf(cres,"%*4c%lg,%*d",&value); |
179 | } |
179 | } |
180 | return value; |
180 | return value; |
181 | } |
181 | } |
182 | 182 | ||
183 | void _VI_FUNC K617_current_mode (int range) |
183 | void _VI_FUNC K617_current_mode (int range) |
184 | { |
184 | { |
185 | int len; |
185 | int len; |
186 | char cmd[100]; |
186 | char cmd[100]; |
187 | 187 | ||
188 | len=sprintf(cmd,"F1R%0dX",range); |
188 | len=sprintf(cmd,"F1R%0dX",range); |
189 | // printf("%d, %s\n",len,cmd); |
189 | // printf("%d, %s\n",len,cmd); |
190 | K617_send (cmd, len); |
190 | K617_send (cmd, len); |
191 | Delay(1); |
191 | Delay(1); |
192 | return; |
192 | return; |
193 | } |
193 | } |
194 | 194 | ||
195 | void _VI_FUNC K617_zero_correct (int zcorrect) |
195 | void _VI_FUNC K617_zero_correct (int zcorrect) |
196 | { |
196 | { |
197 | K617_send ("C0X", 3); |
197 | K617_send ("C0X", 3); |
198 | K617_send ("Z0X", 3); |
198 | K617_send ("Z0X", 3); |
199 | if (zcorrect) { |
199 | if (zcorrect) { |
200 | K617_send ("C1X", 3); |
200 | K617_send ("C1X", 3); |
201 | Delay(2); |
201 | Delay(2); |
202 | K617_send ("Z1X", 3); |
202 | K617_send ("Z1X", 3); |
203 | K617_send ("C0X", 3); |
203 | K617_send ("C0X", 3); |
204 | } |
204 | } |
205 | return; |
205 | return; |
206 | } |
206 | } |
207 | 207 | ||
208 | void _VI_FUNC K617_trigger_mode (int mode) |
208 | void _VI_FUNC K617_trigger_mode (int mode) |
209 | { |
209 | { |
210 | int len; |
210 | int len; |
211 | char cmd[100]; |
211 | char cmd[100]; |
212 | 212 | ||
213 | len=sprintf(cmd,"T%0dX",mode); |
213 | len=sprintf(cmd,"T%0dX",mode); |
214 | K617_send (cmd, len); |
214 | K617_send (cmd, len); |
215 | return; |
215 | return; |
216 | } |
216 | } |
217 | 217 | ||
218 | void _VI_FUNC K617_reading_mode (int mode) |
218 | void _VI_FUNC K617_reading_mode (int mode) |
219 | { |
219 | { |
220 | int len; |
220 | int len; |
221 | char cmd[100]; |
221 | char cmd[100]; |
222 | 222 | ||
223 | len=sprintf(cmd,"B%0dX",mode); |
223 | len=sprintf(cmd,"B%0dX",mode); |
224 | K617_send (cmd, len); |
224 | K617_send (cmd, len); |
225 | return; |
225 | return; |
226 | } |
226 | } |
227 | 227 | ||
228 | void _VI_FUNC K617_vsource_set (float value) |
228 | void _VI_FUNC K617_vsource_set (float value) |
229 | { |
229 | { |
230 | int len; |
230 | int len; |
231 | char cmd[100]; |
231 | char cmd[100]; |
232 | 232 | ||
233 | value=0.05*floor((value+0.025)/0.05); |
233 | value=0.05*floor((value+0.025)/0.05); |
234 | len=sprintf(cmd,"V%+0.2fX",value); |
234 | len=sprintf(cmd,"V%+0.2fX",value); |
235 | // printf("%d, %s\n",len,cmd); |
235 | // printf("%d, %s\n",len,cmd); |
236 | K617_send (cmd, len); |
236 | K617_send (cmd, len); |
237 | return; |
237 | return; |
238 | } |
238 | } |
239 | 239 | ||
240 | double _VI_FUNC K617_vsource_get (void) |
240 | double _VI_FUNC K617_vsource_get (void) |
241 | { |
241 | { |
242 | double value; |
242 | double value; |
243 | 243 | ||
244 | K617_reading_mode (4); |
244 | K617_reading_mode (4); |
245 | value = K617_get (NULL, NULL); |
245 | value = K617_get (NULL, NULL); |
246 | K617_reading_mode (0); |
246 | K617_reading_mode (0); |
247 | return value; |
247 | return value; |
248 | } |
248 | } |
249 | 249 | ||
250 | void _VI_FUNC K617_vsource_operate (int operate) |
250 | void _VI_FUNC K617_vsource_operate (int operate) |
251 | { |
251 | { |
252 | 252 | ||
253 | if (operate) |
253 | if (operate) |
254 | K617_send ("O1X", 3); |
254 | K617_send ("O1X", 3); |
255 | else |
255 | else |
256 | K617_send ("O0X", 3); |
256 | K617_send ("O0X", 3); |
257 | 257 | ||
258 | return; |
258 | return; |
259 | } |
259 | } |
260 | 260 | ||
261 | void _VI_FUNC K617_close (void) |
261 | void _VI_FUNC K617_close (void) |
262 | { |
262 | { |
263 | // iret = CloseDev (K617_Gdev); |
263 | // iret = CloseDev (K617_Gdev); |
264 | switch (K617_Interface){ |
264 | switch (K617_Interface){ |
265 | case 1: |
265 | case 1: |
266 | PROLOGIX_Close(); |
266 | PROLOGIX_Close(); |
267 | break; |
267 | break; |
268 | default: |
268 | default: |
269 | iret = ibonl(K617_Gdev, 0);// Take the device offline |
269 | iret = ibonl(K617_Gdev, 0);// Take the device offline |
270 | if (ibsta & ERR) GpibError("OpenDev Error"); |
270 | if (ibsta & ERR) GpibError("OpenDev Error"); |
271 | } |
271 | } |
272 | return; |
272 | return; |
273 | } |
273 | } |
274 | 274 | ||
275 |
|
275 | void _VI_FUNC K617_test (void) |
276 | - | ||
277 | #include <cvirte.h> |
- | |
278 | - | ||
279 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
- | |
280 | LPSTR lpszCmdLine, int nCmdShow) |
- | |
281 | { |
276 | { |
282 | int i; |
277 | int i; |
283 | double value; |
278 | double value; |
284 | char cres[100]; |
279 | char cres[100]; |
285 | 280 | ||
286 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
- | |
287 | - | ||
288 | K617_open (1,5,3,0,13); |
- | |
289 | K617_clear (); |
281 | K617_clear (); |
290 | K617_current_mode (4); |
282 | K617_current_mode (4); |
291 | K617_zero_correct (1); |
283 | K617_zero_correct (1); |
292 | K617_data_format (0); |
284 | K617_data_format (0); |
293 | K617_trigger_mode (1); |
285 | K617_trigger_mode (1); |
294 | K617_vsource_set (-100.); |
286 | K617_vsource_set (-100.); |
295 | K617_vsource_operate (1); |
287 | K617_vsource_operate (1); |
296 | 288 | ||
297 | K617_status(); |
289 | K617_status(); |
298 | 290 | ||
299 | value=K617_get(cres,&i); |
291 | value=K617_get(cres,&i); |
300 | printf("%s, %lg, %d\n",cres,value,i); |
292 | printf("%s, %lg, %d\n",cres,value,i); |
301 | value=K617_vsource_get(); |
293 | value=K617_vsource_get(); |
302 | printf("%lg\n",value); |
294 | printf("%lg\n",value); |
303 | value=K617_get(cres,&i); |
295 | value=K617_get(cres,&i); |
304 | printf("%s, %lg, %d\n",cres,value,i); |
296 | printf("%s, %lg, %d\n",cres,value,i); |
305 | value=K617_get(cres,&i); |
297 | value=K617_get(cres,&i); |
306 | printf("%s, %lg, %d\n",cres,value,i); |
298 | printf("%s, %lg, %d\n",cres,value,i); |
307 | value=K617_get(cres,&i); |
299 | value=K617_get(cres,&i); |
308 | printf("%s, %lg, %d\n",cres,value,i); |
300 | printf("%s, %lg, %d\n",cres,value,i); |
309 | value=K617_get(cres,&i); |
301 | value=K617_get(cres,&i); |
310 | printf("%s, %lg, %d\n",cres,value,i); |
302 | printf("%s, %lg, %d\n",cres,value,i); |
311 | Delay(5); |
303 | Delay(5); |
312 | K617_vsource_operate (0); |
304 | K617_vsource_operate (0); |
313 | 305 | ||
- | 306 | ||
- | 307 | } |
|
- | 308 | ||
- | 309 | #ifdef K617_MAIN |
|
- | 310 | ||
- | 311 | #include <cvirte.h> |
|
- | 312 | #include <userint.h> |
|
- | 313 | #include "K617-ctrl.h" |
|
- | 314 | int pnl; int gLogToFile; |
|
- | 315 | int vmon[4]={P1_VMON_1}; |
|
- | 316 | int imon[4]={P1_IMON_1 }; |
|
- | 317 | int vset[4]={P1_U_1 }; |
|
- | 318 | int iset[4]={P1_I_1 }; |
|
- | 319 | int radiob[4]={P1_BOX_1 }; |
|
- | 320 | ||
- | 321 | int cvcc[4]={P1_CVCC_1 }; |
|
- | 322 | const unsigned char Pre_1 = 1; |
|
- | 323 | int gMask=0xF; |
|
- | 324 | ||
- | 325 | int pnl; |
|
- | 326 | FILE *gFp; |
|
- | 327 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
|
- | 328 | LPSTR lpszCmdLine, int nCmdShow) |
|
- | 329 | { |
|
- | 330 | char cres[100]; |
|
- | 331 | double Voltage, Current, tinterval; |
|
- | 332 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
|
- | 333 | SetStdioPort (CVI_STDIO_WINDOW); |
|
- | 334 | if ((pnl = LoadPanel (0, "K617-ctrl.uir", P1)) < 0) return -1; |
|
- | 335 | ||
- | 336 | K617_open (1,4,3,0,13); |
|
- | 337 | ||
- | 338 | ||
- | 339 | SetCtrlVal(pnl, P1_ONOFF, 0); |
|
- | 340 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
|
- | 341 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
|
- | 342 | ||
- | 343 | for (unsigned char ch=0;ch<1;ch++){ |
|
- | 344 | int ison,i; |
|
- | 345 | Voltage =K617_vsource_get(); |
|
- | 346 | Current =K617_get(cres,&i); |
|
- | 347 | SetCtrlVal(pnl, vset[ch], Voltage); |
|
- | 348 | SetCtrlVal(pnl, iset[ch], Current); |
|
- | 349 | GetCtrlVal(pnl, radiob[ch], &ison); |
|
- | 350 | gMask = ison; |
|
- | 351 | } |
|
- | 352 | ||
- | 353 | DisplayPanel (pnl); |
|
- | 354 | RunUserInterface (); |
|
- | 355 | DiscardPanel (pnl); |
|
314 | K617_close(); |
356 | K617_close(); |
- | 357 | ||
- | 358 | if (gFp) fclose(gFp); |
|
- | 359 | ||
- | 360 | ||
- | 361 | return 0; |
|
- | 362 | } |
|
- | 363 | ||
- | 364 | ||
- | 365 | ||
- | 366 | ||
- | 367 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
|
- | 368 | void *callbackData, int eventData1, int eventData2) |
|
- | 369 | { |
|
- | 370 | unsigned char state; |
|
- | 371 | switch (event) |
|
- | 372 | { |
|
- | 373 | case EVENT_COMMIT: |
|
- | 374 | GetCtrlVal(panel, control, &state); |
|
- | 375 | K617_vsource_operate (state); |
|
- | 376 | break; |
|
- | 377 | } |
|
- | 378 | return 0; |
|
- | 379 | } |
|
- | 380 | ||
- | 381 | int CVICALLBACK SetCB (int panel, int control, int event, |
|
- | 382 | void *callbackData, int eventData1, int eventData2) |
|
- | 383 | { |
|
- | 384 | ||
- | 385 | char cres[100]; |
|
- | 386 | int i; |
|
- | 387 | switch (event) |
|
- | 388 | { |
|
- | 389 | case EVENT_COMMIT: |
|
- | 390 | ||
- | 391 | for (unsigned char ch = 0; ch<1;ch++){ |
|
- | 392 | //printf("ch %d %x\n", ch, gMask); |
|
- | 393 | if (gMask){ |
|
- | 394 | double Voltage; |
|
- | 395 | double Current; |
|
- | 396 | GetCtrlVal(panel, vset[ch], &Voltage); |
|
- | 397 | GetCtrlVal(panel, iset[ch], &Current); |
|
- | 398 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 399 | ||
- | 400 | K617_vsource_set (Voltage); |
|
- | 401 | Voltage=K617_vsource_get(); |
|
- | 402 | ||
- | 403 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
|
- | 404 | Current=K617_get(cres,&i); |
|
- | 405 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 406 | ||
- | 407 | } |
|
- | 408 | } |
|
- | 409 | break; |
|
- | 410 | } |
|
- | 411 | return 0; |
|
- | 412 | } |
|
- | 413 | ||
- | 414 | int CVICALLBACK ReadCB (int panel, int control, int event, |
|
- | 415 | void *callbackData, int eventData1, int eventData2) |
|
- | 416 | { |
|
- | 417 | ||
- | 418 | int iRet; |
|
- | 419 | char ch=0; |
|
- | 420 | double Voltage; |
|
- | 421 | double Current; |
|
- | 422 | char cv_cc; |
|
- | 423 | char cres[100]; |
|
- | 424 | ||
- | 425 | switch (event) |
|
- | 426 | { |
|
- | 427 | case EVENT_COMMIT: |
|
- | 428 | for (ch = 0; ch<1;ch++){ |
|
- | 429 | if (gMask){ |
|
- | 430 | int ison,i; |
|
- | 431 | Voltage =K617_vsource_get(); |
|
- | 432 | Current =K617_get(cres,&i); |
|
- | 433 | cv_cc = 1; |
|
- | 434 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 435 | SetCtrlVal(panel, vmon[ch], Voltage); |
|
- | 436 | SetCtrlVal(panel, imon[ch], Current); |
|
- | 437 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
|
- | 438 | } |
|
- | 439 | } |
|
- | 440 | break; |
|
- | 441 | } |
|
- | 442 | return 0; |
|
- | 443 | } |
|
315 | 444 | ||
- | 445 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
|
- | 446 | void *callbackData, int eventData1, int eventData2) { |
|
- | 447 | double tinterval; |
|
- | 448 | switch (event) { |
|
- | 449 | case EVENT_COMMIT: |
|
- | 450 | GetCtrlVal(panel, control, &tinterval); |
|
- | 451 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
|
- | 452 | break; |
|
- | 453 | } |
|
- | 454 | return 0; |
|
- | 455 | } |
|
- | 456 | ||
- | 457 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
|
- | 458 | void *callbackData, int eventData1, int eventData2) |
|
- | 459 | { |
|
- | 460 | int state; |
|
- | 461 | switch (event) |
|
- | 462 | { |
|
- | 463 | case EVENT_COMMIT: |
|
- | 464 | GetCtrlVal(panel, control, &state); |
|
- | 465 | if (state){ |
|
- | 466 | ResumeTimerCallbacks(); |
|
- | 467 | } else { |
|
- | 468 | SuspendTimerCallbacks (); |
|
- | 469 | printf ("Disabling timer....\n"); |
|
- | 470 | } |
|
- | 471 | break; |
|
- | 472 | } |
|
- | 473 | return 0; |
|
- | 474 | } |
|
- | 475 | ||
- | 476 | int CVICALLBACK ExitCB (int panel, int control, int event, |
|
- | 477 | void *callbackData, int eventData1, int eventData2) |
|
- | 478 | { |
|
- | 479 | switch (event) |
|
- | 480 | { |
|
- | 481 | case EVENT_COMMIT: |
|
- | 482 | QuitUserInterface(0); |
|
- | 483 | break; |
|
- | 484 | } |
|
- | 485 | return 0; |
|
- | 486 | } |
|
- | 487 | ||
- | 488 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
|
- | 489 | void *callbackData, int eventData1, int eventData2) |
|
- | 490 | { int ison; |
|
- | 491 | switch (event) |
|
- | 492 | { |
|
- | 493 | case EVENT_COMMIT: |
|
- | 494 | GetCtrlVal(panel, control, &ison); |
|
- | 495 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
|
- | 496 | gMask = ison; |
|
- | 497 | break; |
|
- | 498 | } |
|
- | 499 | return 0; |
|
- | 500 | } |
|
- | 501 | ||
- | 502 | ||
- | 503 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
|
- | 504 | void *callbackData, int eventData1, int eventData2) |
|
- | 505 | { |
|
- | 506 | ||
- | 507 | switch (event) |
|
- | 508 | { |
|
- | 509 | case EVENT_COMMIT: |
|
- | 510 | GetCtrlVal(panel, control, &gLogToFile); |
|
- | 511 | ||
- | 512 | break; |
|
- | 513 | } |
|
- | 514 | return 0; |
|
- | 515 | } |
|
- | 516 | ||
- | 517 | int CVICALLBACK TimerCB (int panel, int control, int event, |
|
- | 518 | void *callbackData, int eventData1, int eventData2) |
|
- | 519 | { |
|
- | 520 | switch (event) |
|
- | 521 | { |
|
- | 522 | ||
- | 523 | unsigned char ch; |
|
- | 524 | double current[4]; |
|
- | 525 | double voltage; |
|
- | 526 | char cv_cc = 0; |
|
- | 527 | char cres[100]; |
|
- | 528 | int i=0; |
|
- | 529 | case EVENT_TIMER_TICK: |
|
- | 530 | for (ch = 0; ch<1;ch++){ |
|
- | 531 | if (gMask){ |
|
- | 532 | voltage =K617_vsource_get(); |
|
- | 533 | current[ch] =K617_get(cres,&i); |
|
- | 534 | ||
- | 535 | if (gLogToFile){ |
|
- | 536 | if (!gFp) { |
|
- | 537 | gFp= fopen("K617.log","w"); |
|
- | 538 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
|
- | 539 | } |
|
- | 540 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
|
- | 541 | } |
|
- | 542 | } |
|
- | 543 | } |
|
- | 544 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
|
- | 545 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
|
- | 546 | break; |
|
- | 547 | } |
|
316 | return 0; |
548 | return 0; |
317 | } |
549 | } |
318 | 550 | ||
- | 551 | int CVICALLBACK TestCB (int panel, int control, int event, |
|
- | 552 | void *callbackData, int eventData1, int eventData2) { |
|
- | 553 | switch (event) { |
|
- | 554 | case EVENT_COMMIT: |
|
- | 555 | K617_test(); |
|
- | 556 | break; |
|
- | 557 | } |
|
- | 558 | return 0; |
|
- | 559 | } |
|
- | 560 | ||
319 | #endif |
561 | #endif |
- | 562 | ||
320 | 563 |