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