Rev 304 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 304 | f9daq | 1 | #include <tcpsupp.h> |
| 281 | f9daq | 2 | #include <formatio.h> |
| 3 | #include <userint.h> |
||
| 4 | #include <ansi_c.h> |
||
| 5 | #include <utility.h> |
||
| 6 | #include <gpib.h> |
||
| 7 | #include "toolbox.h" |
||
| 8 | #include "prologix.h" |
||
| 9 | #include "K6517.h" |
||
| 10 | |||
| 11 | K6517STATUS K6517Stat; |
||
| 12 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
||
| 13 | static int iret; |
||
| 14 | static int stop; |
||
| 304 | f9daq | 15 | static int debugCode; |
| 281 | f9daq | 16 | int _VI_FUNC K6517_status_print (void); |
| 17 | void GpibError(char *msg) { |
||
| 18 | |||
| 19 | printf ("%s\n", msg); |
||
| 20 | |||
| 21 | printf ("ibsta = &H%x <", ibsta); |
||
| 22 | if (ibsta & ERR ) printf (" ERR"); |
||
| 23 | if (ibsta & TIMO) printf (" TIMO"); |
||
| 24 | if (ibsta & END ) printf (" END"); |
||
| 25 | if (ibsta & SRQI) printf (" SRQI"); |
||
| 26 | if (ibsta & RQS ) printf (" RQS"); |
||
| 27 | if (ibsta & CMPL) printf (" CMPL"); |
||
| 28 | if (ibsta & LOK ) printf (" LOK"); |
||
| 29 | if (ibsta & REM ) printf (" REM"); |
||
| 30 | if (ibsta & CIC ) printf (" CIC"); |
||
| 31 | if (ibsta & ATN ) printf (" ATN"); |
||
| 32 | if (ibsta & TACS) printf (" TACS"); |
||
| 33 | if (ibsta & LACS) printf (" LACS"); |
||
| 34 | if (ibsta & DTAS) printf (" DTAS"); |
||
| 35 | if (ibsta & DCAS) printf (" DCAS"); |
||
| 36 | printf (" >\n"); |
||
| 37 | |||
| 38 | printf ("iberr = %d", iberr); |
||
| 39 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
||
| 40 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
||
| 41 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
||
| 42 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
||
| 43 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
||
| 44 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
||
| 45 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
||
| 46 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
||
| 47 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
||
| 48 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
||
| 49 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
||
| 50 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
||
| 51 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
||
| 52 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
||
| 53 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
||
| 54 | |||
| 55 | printf ("ibcntl = %ld\n", ibcntl); |
||
| 56 | printf ("\n"); |
||
| 57 | |||
| 58 | /* Call ibonl to take the device and interface offline */ |
||
| 59 | ibonl (K6517_Gdev,0); |
||
| 60 | |||
| 61 | exit(1); |
||
| 62 | } |
||
| 63 | |||
| 64 | void _VI_FUNC K6517_open (int interface, int port, int primary_addr, |
||
| 65 | int secondary_addr, int timeout) |
||
| 66 | { |
||
| 67 | char cmd[100]; |
||
| 68 | int status; |
||
| 69 | /* |
||
| 70 | K6517_Gdev = OpenDev ("GPIB0", ""); |
||
| 71 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 72 | iret = ibpad (K6517_Gdev, 0); |
||
| 73 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 74 | iret = ibsad (K6517_Gdev, NO_SAD); |
||
| 75 | iret = ibtmo (K6517_Gdev, T10s); |
||
| 76 | iret = ibeot (K6517_Gdev, 1); |
||
| 77 | iret = ibeos (K6517_Gdev, 0); |
||
| 78 | */ |
||
| 79 | K6517_Interface=interface; |
||
| 80 | K6517_Port=port; |
||
| 81 | switch (K6517_Interface){ |
||
| 82 | case 1: |
||
| 83 | status = PROLOGIX_Open (K6517_Port); |
||
| 84 | printf("K6517_open %d\n", status); |
||
| 85 | sprintf(cmd,"++addr %0d",primary_addr); |
||
| 86 | PROLOGIX_Send (cmd); |
||
| 87 | PROLOGIX_Send ("++auto 0"); |
||
| 88 | PROLOGIX_Send ("++eoi 1"); |
||
| 89 | PROLOGIX_Send ("++eot_enable 0"); |
||
| 90 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
||
| 91 | break; |
||
| 92 | default: |
||
| 93 | K6517_Gdev = ibdev(K6517_Port,primary_addr,secondary_addr,timeout,1,0); |
||
| 94 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 95 | } |
||
| 96 | printf("Interface %d\n", interface); |
||
| 97 | K6517_send("*RST",0); |
||
| 98 | K6517_send("*IDN?", 5); |
||
| 99 | char cres[100]; |
||
| 100 | cres[0]= 0; |
||
| 101 | int len = K6517_receive (cres, 50); |
||
| 102 | printf("[%d] %s\n", len, cres); |
||
| 103 | |||
| 104 | Delay(GDELAY); |
||
| 105 | return; |
||
| 106 | } |
||
| 107 | |||
| 108 | void _VI_FUNC K6517_clear (void) |
||
| 109 | { |
||
| 110 | switch (K6517_Interface){ |
||
| 111 | case 1: |
||
| 112 | PROLOGIX_Send("++clr"); |
||
| 113 | break; |
||
| 114 | default: |
||
| 115 | iret = ibclr (K6517_Gdev); // Clear the device |
||
| 116 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 117 | } |
||
| 118 | // Delay(GDELAY); |
||
| 119 | Delay(2.); |
||
| 120 | return; |
||
| 121 | } |
||
| 122 | |||
| 123 | void _VI_FUNC K6517_send (char *cmd, int len) |
||
| 124 | { |
||
| 304 | f9daq | 125 | if (debugCode) printf("-> %s\n", cmd); |
| 281 | f9daq | 126 | if (!len) len = strlen(cmd); |
| 127 | switch (K6517_Interface){ |
||
| 128 | case 1: |
||
| 129 | PROLOGIX_Send(cmd); |
||
| 130 | break; |
||
| 131 | default: |
||
| 132 | iret = ibwrt (K6517_Gdev, cmd, len); |
||
| 133 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 134 | } |
||
| 135 | Delay(GDELAY); |
||
| 136 | return; |
||
| 137 | } |
||
| 138 | |||
| 139 | int _VI_FUNC K6517_receive (char *response, int maxbyt) |
||
| 140 | { |
||
| 141 | int ierr=0; |
||
| 142 | switch (K6517_Interface){ |
||
| 143 | case 1: |
||
| 144 | PROLOGIX_Send("++read eoi"); |
||
| 145 | ierr= PROLOGIX_Receive (response,maxbyt); |
||
| 304 | f9daq | 146 | if (debugCode) printf("<---Read [%d] %s\n", ierr, response); |
| 281 | f9daq | 147 | return ierr; |
| 148 | break; |
||
| 149 | default: |
||
| 150 | iret = ibrd (K6517_Gdev, response, maxbyt); |
||
| 151 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 152 | response[ibcntl]=0; |
||
| 153 | return ibcntl; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | void _VI_FUNC K6517_status (void) |
||
| 158 | { |
||
| 159 | int len; |
||
| 160 | char cres[100]; |
||
| 161 | |||
| 162 | K6517_send ("U0X", 3); |
||
| 163 | len = K6517_receive (cres, 90); |
||
| 164 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
||
| 165 | &K6517Stat.function,&K6517Stat.range,&K6517Stat.zero_check, |
||
| 166 | &K6517Stat.zero_correct,&K6517Stat.suppress,&K6517Stat.trigger, |
||
| 167 | &K6517Stat.vsource_operate,&K6517Stat.read_mode, |
||
| 168 | &K6517Stat.data_prefix,&K6517Stat.display, |
||
| 169 | &K6517Stat.data_store,&K6517Stat.srq,&K6517Stat.eoi,K6517Stat.terminator); |
||
| 170 | printf("617FRRCZNTOBGDQMMKYY\n"); |
||
| 171 | printf("%s\n",cres); |
||
| 172 | // K6517_send ("X", 1); |
||
| 173 | return; |
||
| 174 | } |
||
| 175 | |||
| 176 | void _VI_FUNC K6517_data_format (int mode) |
||
| 177 | { |
||
| 178 | int len; |
||
| 179 | char cmd[100]; |
||
| 180 | |||
| 181 | len=sprintf(cmd,"G%0dX",mode); |
||
| 182 | K6517_send (cmd, len); |
||
| 183 | return; |
||
| 184 | } |
||
| 185 | |||
| 313 | f9daq | 186 | int _VI_FUNC K6517_EventStatus () |
| 187 | { |
||
| 188 | K6517_send (":STATUS:MEAS:EVEN?",0); |
||
| 189 | char cres[100]; |
||
| 190 | cres[0]= 0; |
||
| 191 | int len = K6517_receive (cres, 50); |
||
| 192 | if (len>0) |
||
| 193 | return atoi(cres); |
||
| 194 | else |
||
| 195 | return -1; |
||
| 196 | } |
||
| 281 | f9daq | 197 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
| 198 | { |
||
| 199 | |||
| 200 | double value; |
||
| 201 | char cres[100]; |
||
| 202 | |||
| 203 | K6517_send ("SENS:FUNC 'curr'",0); |
||
| 204 | // K6517_send (":SENS:CURR:RANG:UPP 21e-3",0); |
||
| 205 | // K6517_send ("SYST:ZCH 0",0); |
||
| 206 | K6517_send ("READ?",0); |
||
| 207 | |||
| 208 | cres[0]= 0; |
||
| 209 | int len = K6517_receive (cres, 50); |
||
| 304 | f9daq | 210 | if (debugCode) printf("current >%d, %s\n",len,cres); |
| 281 | f9daq | 211 | |
| 212 | return atof(cres); |
||
| 213 | /* |
||
| 214 | K6517_send ("X", 1); |
||
| 215 | len = K6517_receive (cres, 50); |
||
| 216 | if (loc) { |
||
| 217 | *loc=-1; |
||
| 218 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
||
| 219 | prefix[4]=0; |
||
| 220 | } else { |
||
| 221 | sscanf(cres,"%*4c%lg,%*d",&value); |
||
| 222 | } |
||
| 223 | |||
| 224 | return value; |
||
| 225 | */ |
||
| 226 | |||
| 227 | } |
||
| 228 | |||
| 229 | void _VI_FUNC K6517_current_mode (double range) |
||
| 230 | { |
||
| 231 | int len; |
||
| 232 | char cmd[100]; |
||
| 233 | |||
| 234 | if (range > 0) { |
||
| 235 | len=sprintf(cmd,":SENS:CURR:RANG:AUTO OFF"); |
||
| 236 | len=sprintf(cmd,":SENS:CURR:RANG:UPP %g",range); |
||
| 237 | } |
||
| 238 | else len=sprintf(cmd,":SENS:CURR:RANG:AUTO ON"); |
||
| 239 | // printf("%d, %s\n",len,cmd); |
||
| 240 | K6517_send (cmd, len); |
||
| 241 | Delay(1); |
||
| 242 | K6517_send ("SYST:ZCH 0",0); |
||
| 243 | return; |
||
| 244 | } |
||
| 245 | |||
| 246 | void _VI_FUNC K6517_zero_correct (int zcorrect) |
||
| 247 | { |
||
| 248 | K6517_send ("C0X", 3); |
||
| 249 | K6517_send ("Z0X", 3); |
||
| 250 | if (zcorrect) { |
||
| 251 | K6517_send ("C1X", 3); |
||
| 252 | Delay(2); |
||
| 253 | K6517_send ("Z1X", 3); |
||
| 254 | K6517_send ("C0X", 3); |
||
| 255 | } |
||
| 256 | return; |
||
| 257 | } |
||
| 258 | |||
| 259 | void _VI_FUNC K6517_trigger_mode (int mode) |
||
| 260 | { |
||
| 261 | int len; |
||
| 262 | char cmd[100]; |
||
| 263 | |||
| 264 | //len=sprintf(cmd,"T%0dX",mode); |
||
| 265 | //K6517_send (cmd, len); |
||
| 266 | return; |
||
| 267 | } |
||
| 268 | |||
| 269 | void _VI_FUNC K6517_reading_mode (int mode) |
||
| 270 | { |
||
| 271 | int len; |
||
| 272 | char cmd[100]; |
||
| 273 | |||
| 274 | //len=sprintf(cmd,"B%0dX",mode); |
||
| 275 | //K6517_send (cmd, len); |
||
| 276 | return; |
||
| 277 | } |
||
| 278 | |||
| 279 | void _VI_FUNC K6517_vsource_set (float value) |
||
| 280 | { |
||
| 281 | int len; |
||
| 282 | char cmd[100]; |
||
| 283 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
||
| 284 | K6517_send (cmd, len); |
||
| 304 | f9daq | 285 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
| 286 | K6517_send (cmd, len); |
||
| 281 | f9daq | 287 | return; |
| 288 | } |
||
| 289 | |||
| 290 | double _VI_FUNC K6517_vsource_get (void) |
||
| 291 | { |
||
| 292 | double value; |
||
| 293 | |||
| 294 | /* |
||
| 295 | K6517_send ("SENS:FUNC 'volt'",0); |
||
| 296 | K6517_send ("SENS:VOLT:RANG:AUTO ON",0); |
||
| 297 | K6517_send ("SYST:ZCH 0",0); |
||
| 298 | K6517_send ("READ?",0); |
||
| 299 | */ |
||
| 300 | K6517_send (":MEASure:VOLTage?",0); |
||
| 301 | char cres[100]; |
||
| 302 | cres[0]= 0; |
||
| 303 | int len = K6517_receive (cres, 50); |
||
| 304 | |||
| 305 | |||
| 306 | return atof(cres); |
||
| 307 | } |
||
| 308 | |||
| 309 | void _VI_FUNC K6517_vsource_operate (int operate) |
||
| 310 | { |
||
| 311 | |||
| 312 | if (operate){ |
||
| 313 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0); |
||
| 314 | // K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0); |
||
| 315 | //K6517_send (":MCONNECT 1", 0); |
||
| 316 | K6517_send (":OUTP ON", 0); |
||
| 317 | |||
| 318 | // K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0); |
||
| 319 | // K6517_send (":SOURCE:VOLTAGE 22", 0); |
||
| 320 | } else { |
||
| 321 | //K6517_send (":SOURCE:VOLTAGE 0", 0); |
||
| 322 | // K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0); |
||
| 323 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0); |
||
| 324 | K6517_send (":OUTP OFF", 0); |
||
| 325 | //K6517_send (":MCONNECT 0", 0); |
||
| 326 | |||
| 327 | } |
||
| 328 | K6517_send (":STATUS:OPER?",0); |
||
| 329 | char cres[100]; |
||
| 330 | cres[0]= 0; |
||
| 331 | int len = K6517_receive (cres, 50); |
||
| 332 | |||
| 333 | |||
| 334 | // return atoi(cres); |
||
| 335 | } |
||
| 336 | |||
| 337 | void _VI_FUNC K6517_close (void) |
||
| 338 | { |
||
| 339 | // iret = CloseDev (K6517_Gdev); |
||
| 340 | switch (K6517_Interface){ |
||
| 341 | case 1: |
||
| 342 | PROLOGIX_Close(); |
||
| 343 | break; |
||
| 344 | default: |
||
| 345 | iret = ibonl(K6517_Gdev, 0);// Take the device offline |
||
| 346 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
| 347 | } |
||
| 348 | return; |
||
| 349 | } |
||
| 350 | |||
| 351 | void _VI_FUNC K6517_test (void) |
||
| 352 | { |
||
| 353 | int i; |
||
| 354 | double value; |
||
| 355 | char cres[100]; |
||
| 356 | |||
| 357 | K6517_clear (); |
||
| 358 | K6517_current_mode (0); |
||
| 359 | K6517_zero_correct (1); |
||
| 360 | K6517_data_format (0); |
||
| 361 | K6517_trigger_mode (1); |
||
| 362 | K6517_vsource_set (-100.); |
||
| 363 | K6517_vsource_operate (1); |
||
| 364 | |||
| 365 | K6517_status(); |
||
| 366 | |||
| 367 | value=K6517_get(cres,&i); |
||
| 368 | printf("%s, %lg, %d\n",cres,value,i); |
||
| 369 | value=K6517_vsource_get(); |
||
| 370 | printf("%lg\n",value); |
||
| 371 | value=K6517_get(cres,&i); |
||
| 372 | printf("%s, %lg, %d\n",cres,value,i); |
||
| 373 | value=K6517_get(cres,&i); |
||
| 374 | printf("%s, %lg, %d\n",cres,value,i); |
||
| 375 | value=K6517_get(cres,&i); |
||
| 376 | printf("%s, %lg, %d\n",cres,value,i); |
||
| 377 | value=K6517_get(cres,&i); |
||
| 378 | printf("%s, %lg, %d\n",cres,value,i); |
||
| 379 | Delay(5); |
||
| 380 | K6517_vsource_operate (0); |
||
| 381 | |||
| 382 | |||
| 383 | } |
||
| 384 | |||
| 385 | #ifdef K6517_MAIN |
||
| 386 | |||
| 387 | #include <cvirte.h> |
||
| 388 | #include <userint.h> |
||
| 389 | #include "K6517-ctrl.h" |
||
| 390 | int pnl; int gLogToFile; |
||
| 391 | int pn2; |
||
| 392 | int gLogToFile; |
||
| 393 | int vmon[4]={P1_VMON_1}; |
||
| 394 | int imon[4]={P1_IMON_1 }; |
||
| 395 | int vset[4]={P1_U_1 }; |
||
| 396 | int iset[4]={P1_I_1 }; |
||
| 397 | int radiob[4]={P1_BOX_1 }; |
||
| 398 | |||
| 399 | int cvcc[4]={P1_CVCC_1 }; |
||
| 400 | const unsigned char Pre_1 = 1; |
||
| 401 | int gMask=0xF; |
||
| 402 | |||
| 403 | int pnl; |
||
| 404 | FILE *gFp; |
||
| 405 | |||
| 304 | f9daq | 406 | static int tfID; |
| 407 | static int rID; |
||
| 408 | static CmtThreadPoolHandle poolHandle = 0; |
||
| 409 | #define MAX_THREADS 10 |
||
| 281 | f9daq | 410 | |
| 304 | f9daq | 411 | |
| 412 | |||
| 413 | /*---------------------------------------------------------------------------*/ |
||
| 414 | /* Macros */ |
||
| 415 | /*---------------------------------------------------------------------------*/ |
||
| 416 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError();} |
||
| 417 | |||
| 418 | |||
| 419 | /*---------------------------------------------------------------------------*/ |
||
| 420 | /* Internal function prototypes */ |
||
| 421 | /*---------------------------------------------------------------------------*/ |
||
| 422 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
||
| 423 | void *callbackData); |
||
| 424 | static void ReportTCPError (void); |
||
| 425 | |||
| 426 | /*---------------------------------------------------------------------------*/ |
||
| 427 | /* Module-globals */ |
||
| 428 | /*---------------------------------------------------------------------------*/ |
||
| 429 | static unsigned int g_hconversation; |
||
| 430 | static int g_hmainPanel; |
||
| 431 | static int g_connected = 0; |
||
| 432 | static int g_TCPError = 0; |
||
| 433 | |||
| 434 | /*---------------------------------------------------------------------------*/ |
||
| 435 | /* Report TCP Errors if any */ |
||
| 436 | /*---------------------------------------------------------------------------*/ |
||
| 437 | static void ReportTCPError(void) |
||
| 438 | { |
||
| 439 | if (g_TCPError < 0) |
||
| 440 | { |
||
| 441 | char messageBuffer[1024]; |
||
| 442 | sprintf(messageBuffer, |
||
| 443 | "TCP library error message: %s\nSystem error message: %s", |
||
| 444 | GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
||
| 445 | MessagePopup ("Error", messageBuffer); |
||
| 446 | g_TCPError = 0; |
||
| 447 | } |
||
| 448 | } |
||
| 449 | /*---------------------------------------------------------------------------*/ |
||
| 450 | |||
| 451 | |||
| 452 | int CVICALLBACK DisconnectCB (int panel, int control, int event, |
||
| 453 | void *callbackData, int eventData1, int eventData2) { |
||
| 454 | switch (event) { |
||
| 455 | case EVENT_COMMIT: |
||
| 456 | if (g_connected) |
||
| 457 | DisconnectFromTCPServer (g_hconversation); |
||
| 458 | g_hconversation = 0; |
||
| 459 | g_connected = 0; |
||
| 460 | break; |
||
| 461 | } |
||
| 462 | return 0; |
||
| 463 | } |
||
| 464 | |||
| 465 | int CVICALLBACK ConnectCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { |
||
| 466 | int portNum=10000; |
||
| 467 | char tempBuf[512]; |
||
| 468 | sprintf(tempBuf,"localhost"); |
||
| 469 | switch (event) { |
||
| 470 | case EVENT_COMMIT: |
||
| 313 | f9daq | 471 | if (g_connected) return 0; |
| 304 | f9daq | 472 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
| 473 | MessagePopup("TCP Client", "Connection to server failed !"); |
||
| 474 | else |
||
| 475 | { |
||
| 476 | SetWaitCursor (0); |
||
| 477 | g_connected = 1; |
||
| 478 | |||
| 479 | /* We are successfully connected -- gather info */ |
||
| 480 | |||
| 481 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
||
| 482 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
||
| 483 | |||
| 484 | tcpChk (GetTCPPeerAddr (g_hconversation, tempBuf, 256)); |
||
| 485 | printf("%s\n" ,tempBuf); |
||
| 486 | tcpChk (GetTCPPeerName (g_hconversation, tempBuf, 256)); |
||
| 487 | printf("%s\n" ,tempBuf); |
||
| 488 | } |
||
| 489 | break; |
||
| 490 | } |
||
| 491 | return 0; |
||
| 492 | } |
||
| 493 | |||
| 494 | |||
| 495 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, void *callbackData) |
||
| 496 | { |
||
| 497 | char receiveBuf[256] = {0}; |
||
| 498 | ssize_t dataSize = sizeof (receiveBuf) - 1; |
||
| 499 | |||
| 500 | switch (event) |
||
| 501 | { |
||
| 502 | case TCP_DATAREADY: |
||
| 503 | if ((dataSize = ClientTCPRead (g_hconversation, receiveBuf, |
||
| 504 | dataSize, 1000)) |
||
| 505 | < 0) |
||
| 506 | { |
||
| 507 | printf( "Receive Error\n"); |
||
| 508 | } |
||
| 509 | else |
||
| 510 | { |
||
| 511 | receiveBuf[dataSize] = '\0'; |
||
| 512 | //printf("%s", receiveBuf); |
||
| 513 | float temp = 0; |
||
| 514 | float humidity = 0; |
||
| 515 | float dt=0; |
||
| 516 | float tdiff=0; |
||
| 517 | int t0 = 0; |
||
| 518 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
||
| 519 | SetCtrlVal(pn2,P2_TMON, temp); |
||
| 520 | SetCtrlVal(pn2,P2_HUMIDITY, humidity); |
||
| 313 | f9daq | 521 | if (fabs(tdiff)<0.2 && fabs(dt) < 0.05) SetCtrlVal(pn2,P2_LED, 1); |
| 304 | f9daq | 522 | else SetCtrlVal(pn2,P2_LED, 0); |
| 523 | } |
||
| 524 | break; |
||
| 525 | case TCP_DISCONNECT: |
||
| 526 | MessagePopup ("TCP Client", "Server has closed connection!"); |
||
| 527 | |||
| 528 | g_connected = 0; |
||
| 529 | |||
| 530 | break; |
||
| 531 | } |
||
| 532 | return 0; |
||
| 533 | } |
||
| 534 | |||
| 535 | |||
| 536 | void SetDimming(int state) { |
||
| 537 | SetCtrlAttribute (pnl, P2_IVSCAN, ATTR_DIMMED, state); |
||
| 538 | SetCtrlAttribute (pnl, P2_EXIT, ATTR_DIMMED, state); |
||
| 539 | SetCtrlAttribute (pnl, P2_STOP, ATTR_DIMMED, !state); |
||
| 540 | } |
||
| 541 | |||
| 542 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
||
| 543 | CmtThreadFunctionID functionID, unsigned int event, |
||
| 544 | int value, void *callbackData ) { |
||
| 545 | SetDimming(0); |
||
| 546 | printf("End of Thread \n"); |
||
| 547 | return ; |
||
| 548 | |||
| 549 | } |
||
| 550 | |||
| 551 | int ivscan (void *arg); |
||
| 552 | |||
| 553 | int TScan () { |
||
| 554 | |||
| 555 | double temp; |
||
| 556 | int n=0; |
||
| 557 | int led; |
||
| 558 | GetNumTableRows (pn2, P2_TABLE, &n ); |
||
| 313 | f9daq | 559 | stop = 0; |
| 304 | f9daq | 560 | for(int i=0; i<n; i++) { |
| 313 | f9daq | 561 | if (stop) break; |
| 304 | f9daq | 562 | GetTableCellVal (pn2, P2_TABLE, MakePoint (1,i+1), &temp); |
| 563 | if (temp>100) break; |
||
| 564 | char transmitBuf[512]= {0}; |
||
| 565 | sprintf(transmitBuf, "1 %f\n", temp); |
||
| 313 | f9daq | 566 | |
| 567 | |||
| 568 | if (g_connected) |
||
| 569 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); else printf("%s\n", transmitBuf); |
||
| 570 | SetCtrlVal(pn2,P2_LED, 0); |
||
| 304 | f9daq | 571 | do { |
| 572 | time_t t0 = time(NULL); |
||
| 573 | SetCtrlVal(pn2,P2_TIME, ctime(&t0)); |
||
| 574 | Delay(1); |
||
| 575 | GetCtrlVal(pn2,P2_LED, &led); |
||
| 313 | f9daq | 576 | if (led) { |
| 577 | for (int k=0;k<10;k++){ |
||
| 578 | Delay(1); |
||
| 579 | if (stop) break; |
||
| 580 | } |
||
| 581 | GetCtrlVal(pn2,P2_LED, &led); |
||
| 582 | } |
||
| 304 | f9daq | 583 | if (stop) break; |
| 584 | } while (!led); |
||
| 585 | if (stop) break; |
||
| 586 | |||
| 587 | int itemp = (int) temp; |
||
| 588 | ivscan(&itemp); |
||
| 589 | printf("%d %f\n",i,temp); |
||
| 590 | } |
||
| 591 | |||
| 592 | return 0; |
||
| 593 | } |
||
| 594 | |||
| 595 | |||
| 596 | int CVICALLBACK TScanCB (int panel, int control, int event, |
||
| 597 | void *callbackData, int eventData1, int eventData2) { |
||
| 598 | |||
| 599 | switch (event) { |
||
| 600 | case EVENT_COMMIT:{ |
||
| 601 | ThreadFunctionPtr mythread = TScan; |
||
| 602 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
||
| 603 | DEFAULT_THREAD_PRIORITY, |
||
| 604 | EndOfThread, |
||
| 605 | EVENT_TP_THREAD_FUNCTION_END, |
||
| 606 | NULL, RUN_IN_SCHEDULED_THREAD, |
||
| 607 | &tfID); |
||
| 608 | } |
||
| 609 | break; |
||
| 610 | } |
||
| 611 | return 0; |
||
| 612 | } |
||
| 613 | |||
| 281 | f9daq | 614 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
| 615 | void *callbackData, int eventData1, int eventData2) |
||
| 616 | { |
||
| 617 | int state; |
||
| 618 | switch (event) |
||
| 619 | { |
||
| 620 | case EVENT_COMMIT: |
||
| 621 | GetCtrlVal(panel, control, &state); |
||
| 622 | if (state){ |
||
| 623 | ResumeTimerCallbacks(); |
||
| 624 | } else { |
||
| 625 | SuspendTimerCallbacks (); |
||
| 626 | printf ("Disabling timer....\n"); |
||
| 627 | } |
||
| 628 | break; |
||
| 629 | } |
||
| 630 | return 0; |
||
| 631 | } |
||
| 632 | |||
| 633 | // reads the run number from the first line in the file |
||
| 634 | int GetRunNumberFromFile(char *fname) { |
||
| 635 | char line[MAX_PATHNAME_LEN]; |
||
| 636 | int ndim= MAX_PATHNAME_LEN; |
||
| 637 | int current_run = -1; |
||
| 638 | FILE *fp = NULL; |
||
| 639 | ssize_t size; |
||
| 640 | |||
| 641 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
| 642 | |||
| 643 | if (fp) { |
||
| 644 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
||
| 645 | fclose(fp); |
||
| 646 | } |
||
| 647 | return current_run; |
||
| 648 | |||
| 649 | } |
||
| 650 | |||
| 651 | int IncreaseRunNumberInFile(char *fname) { |
||
| 652 | |||
| 653 | int current_run = GetRunNumberFromFile(fname); |
||
| 654 | FILE *fp = fopen(fname,"w"); |
||
| 655 | |||
| 656 | if (fp) { |
||
| 657 | fprintf(fp,"%d", current_run+1 ); |
||
| 658 | fclose(fp); |
||
| 659 | } |
||
| 660 | return current_run+1; |
||
| 661 | } |
||
| 662 | |||
| 304 | f9daq | 663 | |
| 281 | f9daq | 664 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 665 | LPSTR lpszCmdLine, int nCmdShow) |
||
| 666 | { |
||
| 667 | char cres[100]; |
||
| 668 | double Voltage, Current, tinterval; |
||
| 669 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
||
| 304 | f9daq | 670 | SetStdioPort (CVI_STDIO_WINDOW); |
| 671 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
| 672 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
| 673 | |||
| 281 | f9daq | 674 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
| 675 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
||
| 304 | f9daq | 676 | DisableBreakOnLibraryErrors(); |
| 281 | f9daq | 677 | K6517_open (1,4,3,0,13); |
| 678 | |||
| 679 | |||
| 680 | SetCtrlVal(pnl, P1_ONOFF, 0); |
||
| 681 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
||
| 682 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
| 683 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT,NULL,0,0); |
||
| 684 | for (unsigned char ch=0;ch<1;ch++){ |
||
| 685 | int ison,i; |
||
| 686 | Voltage =K6517_vsource_get(); |
||
| 687 | Current =K6517_get(cres,&i); |
||
| 688 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
| 689 | SetCtrlVal(pnl, iset[ch], Current); |
||
| 690 | GetCtrlVal(pnl, radiob[ch], &ison); |
||
| 691 | gMask = ison; |
||
| 692 | } |
||
| 693 | |||
| 694 | DisplayPanel (pnl); |
||
| 695 | DisplayPanel (pn2); |
||
| 696 | RunUserInterface (); |
||
| 304 | f9daq | 697 | CmtDiscardThreadPool (poolHandle); |
| 698 | if (g_connected) |
||
| 699 | DisconnectFromTCPServer (g_hconversation); |
||
| 281 | f9daq | 700 | DiscardPanel (pn2); |
| 701 | DiscardPanel (pnl); |
||
| 702 | K6517_close(); |
||
| 703 | |||
| 704 | if (gFp) fclose(gFp); |
||
| 705 | |||
| 706 | |||
| 707 | return 0; |
||
| 708 | } |
||
| 709 | |||
| 710 | |||
| 711 | |||
| 712 | |||
| 713 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
||
| 714 | void *callbackData, int eventData1, int eventData2) |
||
| 715 | { |
||
| 716 | unsigned char state; |
||
| 717 | switch (event) |
||
| 718 | { |
||
| 719 | case EVENT_COMMIT: |
||
| 720 | GetCtrlVal(panel, control, &state); |
||
| 721 | K6517_vsource_operate (state); |
||
| 722 | break; |
||
| 723 | } |
||
| 724 | return 0; |
||
| 725 | } |
||
| 726 | |||
| 727 | int CVICALLBACK SetCB (int panel, int control, int event, |
||
| 728 | void *callbackData, int eventData1, int eventData2) |
||
| 729 | { |
||
| 730 | |||
| 731 | char cres[100]; |
||
| 732 | int i; |
||
| 733 | switch (event) |
||
| 734 | { |
||
| 735 | case EVENT_COMMIT: |
||
| 736 | |||
| 737 | for (unsigned char ch = 0; ch<1;ch++){ |
||
| 738 | //printf("ch %d %x\n", ch, gMask); |
||
| 739 | if (gMask){ |
||
| 740 | double Voltage; |
||
| 741 | double Current; |
||
| 742 | GetCtrlVal(panel, vset[ch], &Voltage); |
||
| 743 | GetCtrlVal(panel, iset[ch], &Current); |
||
| 744 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
| 745 | |||
| 746 | K6517_vsource_set (Voltage); |
||
| 747 | Voltage=K6517_vsource_get(); |
||
| 748 | |||
| 749 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
||
| 750 | Current=K6517_get(cres,&i); |
||
| 751 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
| 752 | |||
| 753 | } |
||
| 754 | } |
||
| 755 | break; |
||
| 756 | } |
||
| 757 | return 0; |
||
| 758 | } |
||
| 759 | |||
| 760 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
| 761 | void *callbackData, int eventData1, int eventData2) |
||
| 762 | { |
||
| 763 | |||
| 764 | int iRet; |
||
| 765 | char ch=0; |
||
| 766 | double Voltage; |
||
| 767 | double Current; |
||
| 768 | char cv_cc; |
||
| 769 | char cres[100]; |
||
| 770 | |||
| 771 | switch (event) |
||
| 772 | { |
||
| 773 | case EVENT_COMMIT: |
||
| 774 | for (ch = 0; ch<1;ch++){ |
||
| 775 | if (gMask){ |
||
| 776 | int ison,i; |
||
| 777 | Voltage =K6517_vsource_get(); |
||
| 778 | Current =K6517_get(cres,&i); |
||
| 779 | cv_cc = 1; |
||
| 780 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
| 781 | SetCtrlVal(panel, vmon[ch], Voltage); |
||
| 782 | SetCtrlVal(panel, imon[ch], Current); |
||
| 783 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
| 784 | } |
||
| 785 | } |
||
| 786 | break; |
||
| 787 | } |
||
| 788 | return 0; |
||
| 789 | } |
||
| 790 | |||
| 791 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
| 792 | void *callbackData, int eventData1, int eventData2) { |
||
| 793 | double tinterval; |
||
| 794 | switch (event) { |
||
| 795 | case EVENT_COMMIT: |
||
| 796 | GetCtrlVal(panel, control, &tinterval); |
||
| 797 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
| 798 | break; |
||
| 799 | } |
||
| 800 | return 0; |
||
| 801 | } |
||
| 802 | |||
| 803 | |||
| 804 | |||
| 805 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
| 806 | void *callbackData, int eventData1, int eventData2) |
||
| 807 | { |
||
| 808 | switch (event) |
||
| 809 | { |
||
| 810 | case EVENT_COMMIT: |
||
| 811 | K6517_send (":OUTP OFF", 0); |
||
| 812 | QuitUserInterface(0); |
||
| 813 | break; |
||
| 814 | } |
||
| 815 | return 0; |
||
| 816 | } |
||
| 817 | |||
| 818 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
||
| 819 | void *callbackData, int eventData1, int eventData2) |
||
| 820 | { int ison; |
||
| 821 | switch (event) |
||
| 822 | { |
||
| 823 | case EVENT_COMMIT: |
||
| 824 | GetCtrlVal(panel, control, &ison); |
||
| 825 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
||
| 826 | gMask = ison; |
||
| 827 | break; |
||
| 828 | } |
||
| 829 | return 0; |
||
| 830 | } |
||
| 831 | |||
| 832 | |||
| 833 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
||
| 834 | void *callbackData, int eventData1, int eventData2) |
||
| 835 | { |
||
| 836 | |||
| 837 | switch (event) |
||
| 838 | { |
||
| 839 | case EVENT_COMMIT: |
||
| 840 | GetCtrlVal(panel, control, &gLogToFile); |
||
| 841 | |||
| 842 | break; |
||
| 843 | } |
||
| 844 | return 0; |
||
| 845 | } |
||
| 846 | |||
| 847 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
| 848 | void *callbackData, int eventData1, int eventData2) |
||
| 849 | { |
||
| 850 | switch (event) |
||
| 851 | { |
||
| 852 | |||
| 853 | unsigned char ch; |
||
| 854 | double current[4]; |
||
| 855 | double voltage; |
||
| 856 | char cv_cc = 0; |
||
| 857 | char cres[100]; |
||
| 858 | int i=0; |
||
| 859 | case EVENT_TIMER_TICK: |
||
| 860 | for (ch = 0; ch<1;ch++){ |
||
| 861 | if (gMask){ |
||
| 862 | voltage =K6517_vsource_get(); |
||
| 863 | current[ch] =K6517_get(cres,&i); |
||
| 864 | |||
| 865 | if (gLogToFile){ |
||
| 866 | if (!gFp) { |
||
| 867 | gFp= fopen("K6517.log","w"); |
||
| 868 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
||
| 869 | } |
||
| 870 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
||
| 871 | } |
||
| 872 | } |
||
| 873 | } |
||
| 874 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
||
| 875 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
||
| 876 | break; |
||
| 877 | } |
||
| 878 | return 0; |
||
| 879 | } |
||
| 880 | |||
| 881 | int CVICALLBACK TestCB (int panel, int control, int event, |
||
| 882 | void *callbackData, int eventData1, int eventData2) { |
||
| 883 | switch (event) { |
||
| 884 | case EVENT_COMMIT: |
||
| 885 | K6517_test(); |
||
| 886 | break; |
||
| 887 | } |
||
| 888 | return 0; |
||
| 889 | } |
||
| 890 | |||
| 891 | |||
| 304 | f9daq | 892 | int ivscan (void *arg) { |
| 893 | int *iarg = (int *) arg; |
||
| 281 | f9daq | 894 | int nsteps; |
| 895 | double umin, umax, u; |
||
| 896 | double *xpoints; |
||
| 897 | double *ypoints; |
||
| 898 | static int plivhandle=0; |
||
| 899 | double current; |
||
| 900 | double voltage; |
||
| 901 | char cv_cc = 0; |
||
| 902 | char cres[100]; |
||
| 903 | char fileName[100]; |
||
| 904 | char fname[100]; |
||
| 905 | char path[100]; |
||
| 906 | double range; |
||
| 907 | int k=0; |
||
| 908 | int state; |
||
| 909 | int overflow; |
||
| 910 | char ovf[10]; |
||
| 911 | FILE *fp; |
||
| 912 | time_t mtime; |
||
| 913 | ssize_t size; |
||
| 304 | f9daq | 914 | int repeatscan = 1; |
| 915 | while (repeatscan){ |
||
| 916 | |||
| 917 | |||
| 281 | f9daq | 918 | K6517_send (":OUTP ON", 0); |
| 304 | f9daq | 919 | |
| 281 | f9daq | 920 | SetCtrlVal(pnl, P1_TIMERON, 0); |
| 304 | f9daq | 921 | GetCtrlVal(pn2, P2_FILENAME, fileName); |
| 922 | GetCtrlVal(pn2, P2_PATH, path); |
||
| 923 | |||
| 281 | f9daq | 924 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
| 304 | f9daq | 925 | GetCtrlVal(pn2, P2_REPEAT, &repeatscan); |
| 926 | if (repeatscan) { |
||
| 927 | int month, day, year, hours,minutes,seconds; |
||
| 928 | GetSystemDate (&month,&day ,&year ); |
||
| 929 | GetSystemTime(&hours, &minutes, &seconds); |
||
| 930 | sprintf(fname ,"%s/%s.%d_%d_%d_%d_%d.dat", path, fileName,year,month,day,hours,minutes ); |
||
| 931 | fp = fopen(fname,"w"); |
||
| 932 | } else { |
||
| 933 | if (*iarg>=100) sprintf(fname, "%s/%s.dat", path, fileName); |
||
| 934 | else sprintf(fname, "%s/%s_T%d.dat", path, fileName,*iarg); |
||
| 935 | if ( !GetFileInfo(fname,&size) || strstr("test",fileName)!=NULL ) |
||
| 281 | f9daq | 936 | fp = fopen(fname,"w"); |
| 304 | f9daq | 937 | else { |
| 938 | sprintf(cres, "File %s exist\n Remove it first",fname); |
||
| 281 | f9daq | 939 | MessagePopup ("Info", cres); |
| 940 | return 0; |
||
| 304 | f9daq | 941 | } |
| 942 | } |
||
| 281 | f9daq | 943 | time(&mtime); |
| 944 | printf("#%s %s\n",DateStr(), TimeStr()); |
||
| 945 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
||
| 946 | // K6517_current_mode (range); |
||
| 947 | stop = 0; |
||
| 304 | f9daq | 948 | LogScaleCB (pn2, P2_LOGSCALE, EVENT_COMMIT,NULL, 0, 0); |
| 281 | f9daq | 949 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
| 950 | int voltageMin[4]={P2_UMIN_1,P2_UMIN_2,P2_UMIN_3,P2_UMIN_4}; |
||
| 951 | int numberOfSteps[4]={P2_NSTEPS_1,P2_NSTEPS_2,P2_NSTEPS_3,P2_NSTEPS_4}; |
||
| 952 | int selectRange[4]={P2_RANGE_1,P2_RANGE_2,P2_RANGE_3,P2_RANGE_4}; |
||
| 953 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
||
| 954 | int nrOfInt; |
||
| 955 | int nrOfSteps; |
||
| 956 | int N=0; |
||
| 957 | int K=0; |
||
| 958 | for (int j=0;j<4;j++){ |
||
| 304 | f9daq | 959 | GetCtrlVal(pn2, intervals[j], &nrOfInt); |
| 281 | f9daq | 960 | N = N + nrOfInt; |
| 304 | f9daq | 961 | GetCtrlVal(pn2, numberOfSteps[j], &nrOfSteps); |
| 281 | f9daq | 962 | K = K + nrOfSteps; |
| 963 | } |
||
| 304 | f9daq | 964 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
| 965 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
||
| 281 | f9daq | 966 | int tockaK=0; |
| 304 | f9daq | 967 | double t1,t2; |
| 968 | GetCtrlVal(pn2, P2_DELAY, &t1); |
||
| 969 | GetCtrlVal(pn2, P2_DELAY2, &t2); |
||
| 970 | |||
| 281 | f9daq | 971 | for (int i=0;i<N;i++){ |
| 304 | f9daq | 972 | GetCtrlVal(pn2, voltageMin[i], &umin); |
| 973 | GetCtrlVal(pn2, voltageMax[i], &umax); |
||
| 974 | GetCtrlVal(pn2, numberOfSteps[i], &nsteps); |
||
| 975 | GetCtrlVal(pn2, selectRange[i], &range); |
||
| 281 | f9daq | 976 | K6517_current_mode (range); |
| 977 | for (int n=0;n<nsteps+1;n++){ |
||
| 304 | f9daq | 978 | |
| 281 | f9daq | 979 | if (i>0) { |
| 980 | if(n==0) n++; |
||
| 981 | }; |
||
| 982 | u= umin+ n*(umax-umin)/nsteps; |
||
| 304 | f9daq | 983 | if (n==0) { |
| 984 | K6517_vsource_set (u); |
||
| 985 | Delay(1); |
||
| 986 | K6517_get(cres,&k); |
||
| 987 | K6517_vsource_set (u); |
||
| 988 | Delay(1); |
||
| 989 | K6517_get(cres,&k); |
||
| 990 | |||
| 991 | } |
||
| 992 | K6517_vsource_set (u); |
||
| 993 | current =K6517_get(cres,&k); |
||
| 994 | if (n==0) Delay(t1); |
||
| 995 | Delay(t2); |
||
| 281 | f9daq | 996 | // voltage =K6517_vsource_get(); |
| 997 | current =K6517_get(cres,&k); |
||
| 313 | f9daq | 998 | int status = K6517_EventStatus(); |
| 999 | SetCtrlVal(pn2,P2_STATUS, status); |
||
| 1000 | SetCtrlVal(pn2,P2_OVERFLOW, status & 0x1); |
||
| 304 | f9daq | 1001 | // if (current > range) printf("Overflow +\n"); |
| 1002 | // if (current < -range) printf("Overflow -\n"); |
||
| 313 | f9daq | 1003 | if (status & 0x1){ |
| 1004 | if (range>0) range*=10; |
||
| 1005 | K6517_current_mode (range); |
||
| 1006 | Delay(1); |
||
| 1007 | current =K6517_get(cres,&k); |
||
| 1008 | status = K6517_EventStatus(); |
||
| 1009 | SetCtrlVal(pn2,P2_STATUS, status); |
||
| 1010 | SetCtrlVal(pn2,P2_OVERFLOW, status & 0x1); |
||
| 1011 | } |
||
| 281 | f9daq | 1012 | voltage = u; |
| 1013 | xpoints[tockaK]= voltage; |
||
| 1014 | ypoints[tockaK]= current; |
||
| 304 | f9daq | 1015 | SetCtrlVal(pn2, P2_VMON, voltage); |
| 1016 | SetCtrlVal(pn2, P2_VCUR, current); |
||
| 1017 | double temperature=0; |
||
| 1018 | double humidity=0; |
||
| 1019 | GetCtrlVal(pn2, P2_TMON, &temperature); |
||
| 1020 | GetCtrlVal(pn2, P2_HUMIDITY, &humidity); |
||
| 313 | f9daq | 1021 | if (fp) fprintf(fp, "%d %g %g %g %g %g %d\n",tockaK, u, voltage,current, humidity, temperature, status); |
| 304 | f9daq | 1022 | if (debugCode) printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
| 1023 | if (plivhandle) DeleteGraphPlot (pn2, P2_GRAPHIV, plivhandle, VAL_IMMEDIATE_DRAW); |
||
| 1024 | plivhandle = PlotXY (pn2, P2_GRAPHIV, xpoints, ypoints, tockaK+1, VAL_DOUBLE, VAL_DOUBLE, VAL_CONNECTED_POINTS, VAL_BOLD_X, VAL_SOLID, 1, VAL_RED); |
||
| 281 | f9daq | 1025 | ProcessSystemEvents(); |
| 1026 | tockaK++; |
||
| 1027 | if (stop) break; |
||
| 1028 | } |
||
| 304 | f9daq | 1029 | if (stop) break; |
| 281 | f9daq | 1030 | } |
| 304 | f9daq | 1031 | u = 0; |
| 1032 | K6517_vsource_set (u); |
||
| 1033 | SetCtrlVal(pn2, P2_VMON, u); |
||
| 1034 | |||
| 1035 | SetCtrlVal(pnl, P1_ONOFF, 0); |
||
| 1036 | K6517_vsource_operate (0); |
||
| 281 | f9daq | 1037 | fclose(fp); |
| 1038 | free(xpoints); |
||
| 1039 | free(ypoints); |
||
| 304 | f9daq | 1040 | if (stop) break; |
| 1041 | if (repeatscan){ |
||
| 1042 | double period; |
||
| 1043 | GetCtrlVal(pn2,P2_PERIOD,&period); |
||
| 1044 | while (period>0){ |
||
| 1045 | Delay(1); |
||
| 1046 | period--; |
||
| 1047 | SetCtrlVal(pn2,P2_NEXTSCAN, period); |
||
| 1048 | if (stop) { |
||
| 1049 | SetCtrlVal(pn2,P2_NEXTSCAN, 0); |
||
| 1050 | return 0; |
||
| 1051 | } |
||
| 1052 | } |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | } |
||
| 1056 | return 0; |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | |||
| 1060 | |||
| 1061 | |||
| 1062 | |||
| 1063 | int CVICALLBACK IVSCANCB (int panel, int control, int event, |
||
| 1064 | void *callbackData, int eventData1, int eventData2) { |
||
| 1065 | |||
| 1066 | rID=100; |
||
| 1067 | switch (event) { |
||
| 1068 | case EVENT_COMMIT:{ |
||
| 1069 | ThreadFunctionPtr mythread = ivscan; |
||
| 1070 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
||
| 1071 | DEFAULT_THREAD_PRIORITY, |
||
| 1072 | EndOfThread, |
||
| 1073 | EVENT_TP_THREAD_FUNCTION_END, |
||
| 1074 | NULL, RUN_IN_SCHEDULED_THREAD, |
||
| 1075 | &tfID); |
||
| 1076 | } |
||
| 281 | f9daq | 1077 | break; |
| 1078 | } |
||
| 1079 | return 0; |
||
| 1080 | } |
||
| 304 | f9daq | 1081 | |
| 281 | f9daq | 1082 | |
| 1083 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
||
| 1084 | void *callbackData, int eventData1, int eventData2) { |
||
| 1085 | double voltage; |
||
| 1086 | switch (event) { |
||
| 1087 | case EVENT_COMMIT: |
||
| 1088 | GetCtrlVal(panel, P2_VOLT, &voltage); |
||
| 1089 | K6517_vsource_set (voltage); |
||
| 304 | f9daq | 1090 | SetCtrlVal(panel, P2_VMON, voltage); |
| 281 | f9daq | 1091 | break; |
| 1092 | } |
||
| 1093 | return 0; |
||
| 1094 | } |
||
| 1095 | |||
| 1096 | |||
| 1097 | int CVICALLBACK StopCB (int panel, int control, int event, |
||
| 1098 | void *callbackData, int eventData1, int eventData2) { |
||
| 1099 | switch (event) { |
||
| 1100 | case EVENT_COMMIT: |
||
| 1101 | stop = 1; |
||
| 1102 | break; |
||
| 1103 | } |
||
| 1104 | return 0; |
||
| 1105 | } |
||
| 1106 | |||
| 1107 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
||
| 1108 | void *callbackData, int eventData1, int eventData2) { |
||
| 1109 | int selected; |
||
| 1110 | switch (event) { |
||
| 1111 | case EVENT_COMMIT: |
||
| 1112 | GetCtrlVal(panel, control, &selected); |
||
| 1113 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
||
| 1114 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
||
| 1115 | break; |
||
| 1116 | } |
||
| 1117 | return 0; |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | |||
| 1121 | //**************************** |
||
| 1122 | int EscapeString(const char *i, char *o) { |
||
| 1123 | int iptr=0, optr = 0; |
||
| 1124 | // walk though the input string |
||
| 1125 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
||
| 1126 | // search for |
||
| 1127 | if ( (i[iptr]=='\\') ) { |
||
| 1128 | printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
||
| 1129 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
||
| 1130 | o[optr] = i[iptr]; |
||
| 1131 | optr++; |
||
| 1132 | } |
||
| 1133 | o[optr] = i[iptr]; |
||
| 1134 | } |
||
| 1135 | o[optr] = '\0'; |
||
| 1136 | return 0; |
||
| 1137 | } |
||
| 1138 | |||
| 1139 | |||
| 1140 | int CVICALLBACK DrawCB (int panel, int control, int event, |
||
| 1141 | void *callbackData, int eventData1, int eventData2) { |
||
| 1142 | switch (event) { |
||
| 1143 | case EVENT_COMMIT:{ |
||
| 1144 | char fileName[100]; |
||
| 1145 | char fname[100]; |
||
| 1146 | char path[100]; |
||
| 1147 | GetCtrlVal(panel, P2_FILENAME, fileName); |
||
| 1148 | GetCtrlVal(panel, P2_PATH, path); |
||
| 1149 | sprintf(fname, "%s/%s.dat", path, fileName); |
||
| 1150 | int status; |
||
| 1151 | char name[MAX_PATHNAME_LEN]; |
||
| 1152 | // char dfile[MAX_PATHNAME_LEN]; |
||
| 1153 | // char efile[MAX_PATHNAME_LEN]; |
||
| 1154 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
||
| 1155 | // "Izberi datoteko s podatki", |
||
| 1156 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
||
| 1157 | // EscapeString(efile,dfile); |
||
| 1158 | sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname); |
||
| 1159 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
||
| 1160 | printf("%s\n",name); |
||
| 1161 | LaunchExecutable(name); |
||
| 1162 | break; |
||
| 1163 | } |
||
| 1164 | } |
||
| 1165 | return 0; |
||
| 1166 | } |
||
| 1167 | |||
| 1168 | |||
| 1169 | int CVICALLBACK Print (int panel, int control, int event, |
||
| 1170 | void *callbackData, int eventData1, int eventData2) { |
||
| 1171 | char dfile[MAX_PATHNAME_LEN]; |
||
| 1172 | char name[MAX_PATHNAME_LEN]; |
||
| 1173 | int h2=0; |
||
| 1174 | switch (event) { |
||
| 1175 | case EVENT_COMMIT: { |
||
| 1176 | int hours, minutes, seconds; |
||
| 1177 | int month, day, year; |
||
| 1178 | int id=-1; |
||
| 1179 | //int bitmap = 0; |
||
| 1180 | |||
| 1181 | GetSystemDate (&month,&day ,&year ); |
||
| 1182 | GetSystemTime(&hours, &minutes, &seconds); |
||
| 1183 | sprintf(name,"IV"); |
||
| 1184 | sprintf(dfile ,"%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
||
| 1185 | SaveCtrlDisplayToFile (panel,P2_GRAPHIV, 0, -1, -1, dfile); |
||
| 1186 | printf("bmp image saved as %s\n", dfile); |
||
| 1187 | |||
| 1188 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
||
| 1189 | } |
||
| 1190 | break; |
||
| 1191 | } |
||
| 1192 | return 0; |
||
| 1193 | } |
||
| 1194 | |||
| 1195 | int CVICALLBACK DebugCB (int panel, int control, int event, |
||
| 1196 | void *callbackData, int eventData1, int eventData2) { |
||
| 1197 | int selected; |
||
| 304 | f9daq | 1198 | |
| 281 | f9daq | 1199 | switch (event) { |
| 1200 | case EVENT_COMMIT: |
||
| 1201 | GetCtrlVal(panel, control, &selected); |
||
| 1202 | if(selected) debugCode = 1; |
||
| 1203 | else debugCode = 0; |
||
| 1204 | break; |
||
| 1205 | } |
||
| 1206 | return 0; |
||
| 1207 | } |
||
| 1208 | |||
| 1209 | int CVICALLBACK Exit2CB (int panel, int control, int event, |
||
| 1210 | void *callbackData, int eventData1, int eventData2) { |
||
| 1211 | switch (event) { |
||
| 1212 | case EVENT_COMMIT: |
||
| 1213 | K6517_send (":OUTP OFF", 0); |
||
| 1214 | QuitUserInterface(0); |
||
| 1215 | break; |
||
| 1216 | } |
||
| 1217 | return 0; |
||
| 1218 | } |
||
| 304 | f9daq | 1219 | |
| 1220 | |||
| 1221 | |||
| 281 | f9daq | 1222 | #endif |