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