Rev 185 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 185 | Rev 256 | ||
---|---|---|---|
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 "K617.h" |
5 | #include "K617.h" |
5 | 6 | ||
6 | K617STATUS K617Stat; |
7 | K617STATUS K617Stat; |
- | 8 | static int K617_Interface,K617_Port,K617_Gdev; |
|
7 | static int |
9 | static int iret; |
8 | 10 | ||
9 | void GpibError(char *msg) { |
11 | void GpibError(char *msg) { |
10 | 12 | ||
11 | printf ("%s\n", msg); |
13 | printf ("%s\n", msg); |
12 | 14 | ||
13 | printf ("ibsta = &H%x <", ibsta); |
15 | printf ("ibsta = &H%x <", ibsta); |
14 | if (ibsta & ERR ) printf (" ERR"); |
16 | if (ibsta & ERR ) printf (" ERR"); |
15 | if (ibsta & TIMO) printf (" TIMO"); |
17 | if (ibsta & TIMO) printf (" TIMO"); |
16 | if (ibsta & END ) printf (" END"); |
18 | if (ibsta & END ) printf (" END"); |
17 | if (ibsta & SRQI) printf (" SRQI"); |
19 | if (ibsta & SRQI) printf (" SRQI"); |
18 | if (ibsta & RQS ) printf (" RQS"); |
20 | if (ibsta & RQS ) printf (" RQS"); |
19 | if (ibsta & CMPL) printf (" CMPL"); |
21 | if (ibsta & CMPL) printf (" CMPL"); |
20 | if (ibsta & LOK ) printf (" LOK"); |
22 | if (ibsta & LOK ) printf (" LOK"); |
21 | if (ibsta & REM ) printf (" REM"); |
23 | if (ibsta & REM ) printf (" REM"); |
22 | if (ibsta & CIC ) printf (" CIC"); |
24 | if (ibsta & CIC ) printf (" CIC"); |
23 | if (ibsta & ATN ) printf (" ATN"); |
25 | if (ibsta & ATN ) printf (" ATN"); |
24 | if (ibsta & TACS) printf (" TACS"); |
26 | if (ibsta & TACS) printf (" TACS"); |
25 | if (ibsta & LACS) printf (" LACS"); |
27 | if (ibsta & LACS) printf (" LACS"); |
26 | if (ibsta & DTAS) printf (" DTAS"); |
28 | if (ibsta & DTAS) printf (" DTAS"); |
27 | if (ibsta & DCAS) printf (" DCAS"); |
29 | if (ibsta & DCAS) printf (" DCAS"); |
28 | printf (" >\n"); |
30 | printf (" >\n"); |
29 | 31 | ||
30 | printf ("iberr = %d", iberr); |
32 | printf ("iberr = %d", iberr); |
31 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
33 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
32 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
34 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
33 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
35 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
34 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
36 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
35 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
37 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
36 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
38 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
37 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
39 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
38 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
40 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
39 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
41 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
40 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
42 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
41 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
43 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
42 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
44 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
43 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
45 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
44 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
46 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
45 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
47 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
46 | 48 | ||
47 | printf ("ibcntl = %ld\n", ibcntl); |
49 | printf ("ibcntl = %ld\n", ibcntl); |
48 | printf ("\n"); |
50 | printf ("\n"); |
49 | 51 | ||
50 | /* Call ibonl to take the device and interface offline */ |
52 | /* Call ibonl to take the device and interface offline */ |
51 | ibonl ( |
53 | ibonl (K617_Gdev,0); |
52 | 54 | ||
53 | exit(1); |
55 | exit(1); |
54 | } |
56 | } |
55 | 57 | ||
56 | void _VI_FUNC K617_open (int interface, int |
58 | void _VI_FUNC K617_open (int interface, int port, int primary_addr, |
57 | int timeout) |
59 | int secondary_addr, int timeout) |
58 | { |
60 | { |
- | 61 | char cmd[100]; |
|
59 | /* |
62 | /* |
60 | |
63 | K617_Gdev = OpenDev ("GPIB0", ""); |
61 | if (ibsta & ERR) GpibError("OpenDev Error"); |
- | |
62 | iret = ibpad (gdev, 0); |
- | |
63 | if (ibsta & ERR) GpibError("OpenDev Error"); |
64 | if (ibsta & ERR) GpibError("OpenDev Error"); |
64 | iret = ibsad (gdev, NO_SAD); |
- | |
65 | iret = ibtmo (gdev, T10s); |
- | |
66 | iret = ibeot (gdev, 1); |
- | |
67 | iret = |
65 | iret = ibpad (K617_Gdev, 0); |
68 | */ |
- | |
69 | gdev = ibdev(interface,primary_addr,secondary_addr,timeout,1,0); |
- | |
70 | if (ibsta & ERR) GpibError("OpenDev Error"); |
66 | if (ibsta & ERR) GpibError("OpenDev Error"); |
- | 67 | iret = ibsad (K617_Gdev, NO_SAD); |
|
- | 68 | iret = ibtmo (K617_Gdev, T10s); |
|
- | 69 | iret = ibeot (K617_Gdev, 1); |
|
- | 70 | iret = ibeos (K617_Gdev, 0); |
|
- | 71 | */ |
|
- | 72 | K617_Interface=interface; |
|
- | 73 | K617_Port=port; |
|
- | 74 | switch (K617_Interface){ |
|
- | 75 | case 1: |
|
- | 76 | PROLOGIX_Open (K617_Port); |
|
- | 77 | sprintf(cmd,"++addr %0d",primary_addr); |
|
- | 78 | PROLOGIX_Send (cmd); |
|
- | 79 | PROLOGIX_Send ("++auto 0"); |
|
- | 80 | PROLOGIX_Send ("++eoi 1"); |
|
- | 81 | PROLOGIX_Send ("++eot_enable 0"); |
|
- | 82 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
|
- | 83 | break; |
|
- | 84 | default: |
|
- | 85 | K617_Gdev = ibdev(K617_Port,primary_addr,secondary_addr,timeout,1,0); |
|
- | 86 | if (ibsta & ERR) GpibError("OpenDev Error"); |
|
- | 87 | } |
|
71 | Delay(GDELAY); |
88 | Delay(GDELAY); |
72 | return; |
89 | return; |
73 | } |
90 | } |
74 | 91 | ||
75 | void _VI_FUNC K617_clear (void) |
92 | void _VI_FUNC K617_clear (void) |
76 | { |
93 | { |
- | 94 | switch (K617_Interface){ |
|
- | 95 | case 1: |
|
- | 96 | PROLOGIX_Send("++clr"); |
|
- | 97 | break; |
|
- | 98 | default: |
|
77 | iret = |
99 | iret = ibclr (K617_Gdev); // Clear the device |
78 | if (ibsta & ERR) GpibError("OpenDev Error"); |
100 | if (ibsta & ERR) GpibError("OpenDev Error"); |
- | 101 | } |
|
79 |
|
102 | // Delay(GDELAY); |
- | 103 | Delay(2.); |
|
80 | return; |
104 | return; |
81 | - | ||
82 | } |
105 | } |
83 | 106 | ||
84 | void _VI_FUNC K617_send (char *cmd, int len) |
107 | void _VI_FUNC K617_send (char *cmd, int len) |
85 | { |
108 | { |
- | 109 | switch (K617_Interface){ |
|
- | 110 | case 1: |
|
- | 111 | PROLOGIX_Send(cmd); |
|
- | 112 | break; |
|
- | 113 | default: |
|
86 | iret = ibwrt ( |
114 | iret = ibwrt (K617_Gdev, cmd, len); |
87 | if (ibsta & ERR) GpibError("OpenDev Error"); |
115 | if (ibsta & ERR) GpibError("OpenDev Error"); |
- | 116 | } |
|
88 | Delay(GDELAY); |
117 | Delay(GDELAY); |
89 | return; |
118 | return; |
90 | } |
119 | } |
91 | 120 | ||
92 | int _VI_FUNC K617_receive (char *response, int maxbyt) |
121 | int _VI_FUNC K617_receive (char *response, int maxbyt) |
93 | { |
122 | { |
- | 123 | switch (K617_Interface){ |
|
- | 124 | case 1: |
|
- | 125 | PROLOGIX_Send("++read eoi"); |
|
- | 126 | return PROLOGIX_Receive (response,maxbyt); |
|
- | 127 | break; |
|
- | 128 | default: |
|
94 | iret = ibrd ( |
129 | iret = ibrd (K617_Gdev, response, maxbyt); |
95 | if (ibsta & ERR) GpibError("OpenDev Error"); |
130 | if (ibsta & ERR) GpibError("OpenDev Error"); |
96 | response[ibcntl]=0; |
131 | response[ibcntl]=0; |
97 | return ibcntl; |
132 | return ibcntl; |
- | 133 | } |
|
98 | } |
134 | } |
99 | 135 | ||
100 | void _VI_FUNC K617_status (void) |
136 | void _VI_FUNC K617_status (void) |
101 | { |
137 | { |
102 | int len; |
138 | int len; |
103 | char cres[100]; |
139 | char cres[100]; |
104 | 140 | ||
105 | K617_send ("U0X", 3); |
141 | K617_send ("U0X", 3); |
106 | len = K617_receive (cres, 90); |
142 | len = K617_receive (cres, 90); |
107 | 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", |
108 | &K617Stat.function,&K617Stat.range,&K617Stat.zero_check, |
144 | &K617Stat.function,&K617Stat.range,&K617Stat.zero_check, |
109 | &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger, |
145 | &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger, |
110 | &K617Stat.vsource_operate,&K617Stat.read_mode, |
146 | &K617Stat.vsource_operate,&K617Stat.read_mode, |
111 | &K617Stat.data_prefix,&K617Stat.display, |
147 | &K617Stat.data_prefix,&K617Stat.display, |
112 | &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator); |
148 | &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator); |
- | 149 | // printf("617FRRCZNTOBGDQMMKYY\n"); |
|
- | 150 | // printf("%s\n",cres); |
|
113 |
|
151 | // K617_send ("X", 1); |
114 | return; |
152 | return; |
115 | } |
153 | } |
116 | 154 | ||
117 | void _VI_FUNC K617_data_format (int mode) |
155 | void _VI_FUNC K617_data_format (int mode) |
118 | { |
156 | { |
119 | int len; |
157 | int len; |
120 | char cmd[100]; |
158 | char cmd[100]; |
121 | 159 | ||
122 | len=sprintf(cmd,"G%0dX",mode); |
160 | len=sprintf(cmd,"G%0dX",mode); |
123 | K617_send (cmd, len); |
161 | K617_send (cmd, len); |
124 | return; |
162 | return; |
125 | } |
163 | } |
126 | 164 | ||
127 | double _VI_FUNC K617_get (char *prefix, int *loc) |
165 | double _VI_FUNC K617_get (char *prefix, int *loc) |
128 | { |
166 | { |
129 | int len; |
167 | int len; |
130 | double value; |
168 | double value; |
131 | char cres[100]; |
169 | char cres[100]; |
132 | 170 | ||
133 | K617_send ("X", 1); |
171 | K617_send ("X", 1); |
134 | len = K617_receive (cres, 50); |
172 | len = K617_receive (cres, 50); |
135 | if (loc) { |
173 | if (loc) { |
136 | *loc=-1; |
174 | *loc=-1; |
137 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
175 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
138 | prefix[4]=0; |
176 | prefix[4]=0; |
139 | } else { |
177 | } else { |
140 | sscanf(cres,"%*4c%lg,%*d",&value); |
178 | sscanf(cres,"%*4c%lg,%*d",&value); |
141 | } |
179 | } |
142 | return value; |
180 | return value; |
143 | } |
181 | } |
144 | 182 | ||
145 | void _VI_FUNC K617_current_mode (int range) |
183 | void _VI_FUNC K617_current_mode (int range) |
146 | { |
184 | { |
147 | int len; |
185 | int len; |
148 | char cmd[100]; |
186 | char cmd[100]; |
149 | 187 | ||
150 | len=sprintf(cmd,"F1R%0dX",range); |
188 | len=sprintf(cmd,"F1R%0dX",range); |
151 | // printf("%d, %s\n",len,cmd); |
189 | // printf("%d, %s\n",len,cmd); |
152 | K617_send (cmd, len); |
190 | K617_send (cmd, len); |
153 | Delay(1); |
191 | Delay(1); |
154 | return; |
192 | return; |
155 | } |
193 | } |
156 | 194 | ||
157 | void _VI_FUNC K617_zero_correct (int zcorrect) |
195 | void _VI_FUNC K617_zero_correct (int zcorrect) |
158 | { |
196 | { |
159 | K617_send ("C0X", 3); |
197 | K617_send ("C0X", 3); |
160 | K617_send ("Z0X", 3); |
198 | K617_send ("Z0X", 3); |
161 | if (zcorrect) { |
199 | if (zcorrect) { |
162 | K617_send ("C1X", 3); |
200 | K617_send ("C1X", 3); |
163 | Delay(2); |
201 | Delay(2); |
164 | K617_send ("Z1X", 3); |
202 | K617_send ("Z1X", 3); |
165 | K617_send ("C0X", 3); |
203 | K617_send ("C0X", 3); |
166 | } |
204 | } |
167 | return; |
205 | return; |
168 | } |
206 | } |
169 | 207 | ||
170 | void _VI_FUNC K617_trigger_mode (int mode) |
208 | void _VI_FUNC K617_trigger_mode (int mode) |
171 | { |
209 | { |
172 | int len; |
210 | int len; |
173 | char cmd[100]; |
211 | char cmd[100]; |
174 | 212 | ||
175 | len=sprintf(cmd,"T%0dX",mode); |
213 | len=sprintf(cmd,"T%0dX",mode); |
176 | K617_send (cmd, len); |
214 | K617_send (cmd, len); |
177 | return; |
215 | return; |
178 | } |
216 | } |
179 | 217 | ||
180 | void _VI_FUNC K617_reading_mode (int mode) |
218 | void _VI_FUNC K617_reading_mode (int mode) |
181 | { |
219 | { |
182 | int len; |
220 | int len; |
183 | char cmd[100]; |
221 | char cmd[100]; |
184 | 222 | ||
185 | len=sprintf(cmd,"B%0dX",mode); |
223 | len=sprintf(cmd,"B%0dX",mode); |
186 | K617_send (cmd, len); |
224 | K617_send (cmd, len); |
187 | return; |
225 | return; |
188 | } |
226 | } |
189 | 227 | ||
190 | void _VI_FUNC K617_vsource_set (float value) |
228 | void _VI_FUNC K617_vsource_set (float value) |
191 | { |
229 | { |
192 | int len; |
230 | int len; |
193 | char cmd[100]; |
231 | char cmd[100]; |
194 | 232 | ||
195 | value=0.05*floor((value+0.025)/0.05); |
233 | value=0.05*floor((value+0.025)/0.05); |
196 | len=sprintf(cmd,"V%+0.2fX",value); |
234 | len=sprintf(cmd,"V%+0.2fX",value); |
197 | // printf("%d, %s\n",len,cmd); |
235 | // printf("%d, %s\n",len,cmd); |
198 | K617_send (cmd, len); |
236 | K617_send (cmd, len); |
199 | return; |
237 | return; |
200 | } |
238 | } |
201 | 239 | ||
202 | double _VI_FUNC K617_vsource_get (void) |
240 | double _VI_FUNC K617_vsource_get (void) |
203 | { |
241 | { |
204 | double value; |
242 | double value; |
205 | 243 | ||
206 | K617_reading_mode (4); |
244 | K617_reading_mode (4); |
207 | value = K617_get (NULL, NULL); |
245 | value = K617_get (NULL, NULL); |
208 | K617_reading_mode (0); |
246 | K617_reading_mode (0); |
209 | return value; |
247 | return value; |
210 | } |
248 | } |
211 | 249 | ||
212 | void _VI_FUNC K617_vsource_operate (int operate) |
250 | void _VI_FUNC K617_vsource_operate (int operate) |
213 | { |
251 | { |
214 | 252 | ||
215 | if (operate) |
253 | if (operate) |
216 | K617_send ("O1X", 3); |
254 | K617_send ("O1X", 3); |
217 | else |
255 | else |
218 | K617_send ("O0X", 3); |
256 | K617_send ("O0X", 3); |
219 | 257 | ||
220 | return; |
258 | return; |
221 | } |
259 | } |
222 | 260 | ||
223 | void _VI_FUNC K617_close (void) |
261 | void _VI_FUNC K617_close (void) |
224 | { |
262 | { |
225 | // iret = CloseDev ( |
263 | // iret = CloseDev (K617_Gdev); |
- | 264 | switch (K617_Interface){ |
|
- | 265 | case 1: |
|
- | 266 | PROLOGIX_Close(); |
|
- | 267 | break; |
|
- | 268 | default: |
|
226 |
|
269 | iret = ibonl(K617_Gdev, 0);// Take the device offline |
227 | if (ibsta & ERR) GpibError("OpenDev Error"); |
270 | if (ibsta & ERR) GpibError("OpenDev Error"); |
- | 271 | } |
|
228 | return; |
272 | return; |
229 | } |
273 | } |
230 | 274 | ||
231 | #ifdef K617_MAIN |
275 | #ifdef K617_MAIN |
232 | 276 | ||
233 | #include <cvirte.h> |
277 | #include <cvirte.h> |
234 | 278 | ||
235 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
279 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
236 | LPSTR lpszCmdLine, int nCmdShow) |
280 | LPSTR lpszCmdLine, int nCmdShow) |
237 | { |
281 | { |
238 | int i; |
282 | int i; |
239 | double value; |
283 | double value; |
240 | char cres[100]; |
284 | char cres[100]; |
241 | 285 | ||
242 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
286 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
243 | 287 | ||
244 | K617_open ( |
288 | K617_open (1,5,3,0,13); |
245 | /* |
- | |
246 | K617_clear (); |
289 | K617_clear (); |
247 | K617_current_mode (4); |
290 | K617_current_mode (4); |
248 | K617_zero_correct (1); |
291 | K617_zero_correct (1); |
249 | K617_data_format (0); |
292 | K617_data_format (0); |
250 |
|
293 | K617_trigger_mode (1); |
251 | K617_vsource_set (-100.); |
294 | K617_vsource_set (-100.); |
252 | K617_vsource_operate (1); |
295 | K617_vsource_operate (1); |
253 | */ |
- | |
254 | K617_status (); |
- | |
255 | 296 | ||
- | 297 | K617_status(); |
|
- | 298 | ||
256 | value=K617_get(cres, |
299 | value=K617_get(cres,&i); |
- | 300 | printf("%s, %lg, %d\n",cres,value,i); |
|
- | 301 | value=K617_vsource_get(); |
|
- | 302 | printf("%lg\n",value); |
|
- | 303 | value=K617_get(cres,&i); |
|
257 | printf("%s, %lg, %d\n",cres,value,i); |
304 | printf("%s, %lg, %d\n",cres,value,i); |
258 | - | ||
259 | value= |
305 | value=K617_get(cres,&i); |
260 | printf("%s, %lg, %d\n",cres,value,i); |
306 | printf("%s, %lg, %d\n",cres,value,i); |
261 | 307 | value=K617_get(cres,&i); |
|
- | 308 | printf("%s, %lg, %d\n",cres,value,i); |
|
262 | value=K617_get(cres, |
309 | value=K617_get(cres,&i); |
263 | printf("%s, %lg, %d\n",cres,value,i); |
310 | printf("%s, %lg, %d\n",cres,value,i); |
264 | - | ||
265 | Delay(5); |
311 | Delay(5); |
266 |
|
312 | K617_vsource_operate (0); |
267 | 313 | ||
268 | K617_close |
314 | K617_close(); |
269 | 315 | ||
270 | return 0; |
316 | return 0; |
271 | } |
317 | } |
272 | 318 | ||
273 | #endif |
319 | #endif |
274 | 320 |