void pressure () { /* Open communication with DataAcqu using usb-rs232 com address "7" */ viOpenDefaultRM (&defaultRM); viOpen (defaultRM,"ASRL07::INSTR",VI_NULL,VI_NULL, &DataAcqu); viQueryf(DataAcqu, "*IDN?\n","%t",reply_string); printf ("Instrument identification string: %s\n",reply_string); /* Reset instrument to power-on and clear the Status Byte */ viPrintf (DataAcqu, "*RST;*CLS\n"); viPrintf (DataAcqu, "STAT:OPER:ENAB 272\n"); viPrintf (DataAcqu, "*ESE 1\n"); viPrintf (DataAcqu, "*SRE 255\n"); viPrintf (DataAcqu, "CONF:CURR 0.1, 1e-5, (@121)\n"); viPrintf (DataAcqu, "CALC:SCAL:GAIN 37500, (@121)\n"); viPrintf (DataAcqu, "CALC:SCAL:OFFS -148.4, (@121)\n"); viPrintf (DataAcqu, "CALC:SCAL:UNIT 'KPA', (@121)\n"); viPrintf (DataAcqu, "CALC:SCAL:STAT ON, (@121)\n"); viPrintf (DataAcqu, "ROUT:SCAN (@121)\n"); viPrintf (DataAcqu, "TRIG:SOUR TIM\n"); viPrintf (DataAcqu, "TRIG:TIMER 5\n"); viPrintf (DataAcqu, "TRIG:COUNT 5\n"); viPrintf (DataAcqu, "INIT;*OPC\n"); for (count = 0; count <5; count++) { /* Query the Status of Standard Operation Register after the sweep done, the five bit position will set to 1 */ loop: viPrintf(DataAcqu, "STAT:OPER?\n"); viScanf(DataAcqu,"%d",&status); //printf("stat:oper= %d ", status); bool value; value = status & 0x10; //printf("value = %d ",value); if ( !value ) //if not set, keep query goto loop; else //show the query data { viPrintf(DataAcqu, "SYST:TIME?\n"); viScanf(DataAcqu,"%s",&reply_string); printf("Time = %s ", reply_string); viPrintf (DataAcqu,"DATA:READ?\n"); /* Get all the readings */ viScanf(DataAcqu,"%s",&temp);/* Put readings into an array */ printf("Data = %s\n", temp); } } viClose (DataAcqu); /* Close the communication port */ viClose (defaultRM); }
bool EITMeasurementThread::openSwitch(int si) { char buf [1000] = {0}; viPrintf (viSwMat, (ViString)CMD_SWITCH_OPEN[si]); this->msleep(exp->SWITCHING_DELAY); int test_count = 0; while (test_count < 5) { viPrintf (viSwMat, (ViString)CMD_SWITCH_OPEN_TEST[si]); viScanf (viSwMat, (ViString)"%t", &buf); if (strlen(buf) == 0) return false; else if (buf[0] == '1') return true; test_count++; } return false; }
int Delay_LastComplete( int handle ) { double lfCurrentTime = 0.0, lfTimeOut = 10.0, lfStartTime = 0.0; int iOpcValue = 0; int status = 0; ViAttrState attrValue = 0; if ( viGetAttribute ( handle , VI_ATTR_TMO_VALUE , &attrValue ) == 0 ) lfTimeOut = attrValue / 1E3; GetCurrentDateTime ( &lfStartTime ); GetCurrentDateTime ( &lfCurrentTime ); while(( lfCurrentTime - lfStartTime ) < lfTimeOut ) { GetCurrentDateTime ( &lfCurrentTime ); status = viPrintf ( handle , "*OPC?\n"); if ( status ) continue; Delay ( 0.2 ); status = viScanf ( handle , "%d" , &iOpcValue); if ( status ) continue; if ( iOpcValue == 1 ) return 0; } return -1; }
int anyErr(ViSession *pvi) { ViStatus err; static char buf[1024]={0}; int err_no; int err_cnt = 0; err=viPrintf(*pvi, "SYSTEM:ERR?\n"); err=viScanf (*pvi, "%d%t", &err_no, &buf); if(err_no >0){ ++err_cnt; } err=viFlush(*pvi, VI_READ_BUF); err=viFlush(*pvi, VI_WRITE_BUF); viPrintf(*pvi, "*rst\n"); return err_cnt; }