int CVIFUNC mouth_OutBufferCommand (dnaBufferRF*buffer) { int l; int err=0; require(0<buffer->CommandCounter); l = dna_LengthBufferRF (buffer); if (l) { // ibwrt (gpibDS345, buffer->Buffer+buffer->PosByte, l); ibwait (gpibDS345, 0); // re-synch if (ThreadIbsta() & ERR) return -2; // TODO BUG GOTCHA : make more verbose // errChk(mouth_Error("mouth_WriteDS345{ibwait call failed}",0,0)); ibwrta (gpibDS345, buffer->Buffer+buffer->PosByte, l); if (ThreadIbsta() & ERR) return -3; // err = mouth_Error("mouth_WriteDS345{ibwrta call failed}",0,0); #if VERBOSE > 1 printf("%s\n",&buffer->Buffer[buffer->PosByte]); if (err) printf("mouth_OutBufferCommand{ibwrt call failed} %d %d %d %d %d\n", buffer->PosByte,buffer->PosCommand,ERR,ThreadIbsta(),ThreadIberr()); #endif if (err) goto Error; errChk(dna_AdvanceRunBufferRF (buffer)); } else { errChk(dna_AdvanceRunBufferRF (buffer)); #if VERBOSE > 0 printf("mouth_OutBufferCommand{Length was zero} %d %d\n", buffer->PosByte,buffer->PosCommand); #endif } Error: return (err?-1:0); }
int CVIFUNC mouth_WriteDS345 (const char command[], int numberofBytes) { int err=0; // ibwrt (gpibDS345, command, numberofBytes); ibwait (gpibDS345, 0); // re-synch errChk(mouth_Error("mouth_WriteDS345{ibwait call failed}",0,0)); ibwrta (gpibDS345, command, numberofBytes); errChk(mouth_Error("mouth_WriteDS345{ibwrta call failed}",0,0)); Error: return (err?-1:0); }
int CVIFUNC mouth_ZeroDS345 (void) { int err=0,l; char *command; mouth_MakeIdleCommand(&command,0.0,0.0,0.0); l=strlen(command); // ibwrt (gpibDS345, "OFFS, numberofBytes); ibwait (gpibDS345, 0); // re-synch errChk(mouth_Error("mouth_ZeroDS345{ibwait call failed}",0,0)); ibwrta (gpibDS345, command, l); errChk(mouth_Error("mouth_ZeroDS345{ibwrta call failed}",0,0)); Error: return (err?-1:0); }
int wxGPIB_x::Read(char* buf,size_t len) { static char* rdbuf; if(m_fifo->items() > 0) { return m_fifo->read(buf,len); } if(!m_asyncio) { char spr = 0; // ask the device if it is ready (this call blocks with Linux, // so we reduced the serial poll timeout in the OpenDevice // member function (look there) ibrsp(m_hd,&spr); if(spr & 0x10) { // MAV Bit is set (message available), allocate memory on // heap. (Because the data transfer is asynchrone, the allocated // memory must exist until the transfer finished. The GPIB // device driver copy the data in it's interrupt service // routine!!!) m_asyncio = ASYNCRD; rdbuf = new char[len]; memset(rdbuf,0,len); // start the asynchron data transfer ibrda(m_hd,rdbuf,len); } } if(m_asyncio == ASYNCRD ) { ibwait(m_hd,0); int state = ThreadIbsta(); if((state & CMPL+ERR) == 0) { return 0; } // asynchrone I/O was finished m_asyncio = 0; // save state, error and count m_state = m_count = m_error = 0; m_state = ThreadIbsta(); m_count = ThreadIbcnt(); m_error = ThreadIberr(); memcpy(buf,rdbuf,len); delete rdbuf; return m_count; } return 0; };
int gpibPort::portService(void) { int sta; char spr; int ret = 0; sta = ibwait( BDINDEX, 0); if (sta & SRQI) { // printf( "Board Service Request\n" ); sta = ibrsp( handle, & spr ); if ( ( spr & 0x40 ) != 0 ) { // printf( "Instrument Service Request %s\n", deviceString); ret = 1; } } return ret; }
int wxGPIB_x::Write(char* buf,size_t len) { if(!m_asyncio) { m_asyncio |= ASYNCWR; // start the asynchron data transfer ibwrta(m_hd,buf,len); } if(m_asyncio & ASYNCWR) { ibwait(m_hd,0); int state = ThreadIbsta(); if((state & CMPL+ERR) == 0) { return 0; } m_asyncio = 0; // save state, error and count m_state = ThreadIbsta(); m_count = ThreadIbcnt(); m_error = ThreadIberr(); return m_count; } // at this time, return 0 Bytes return 0; };
void main() { printf("Read 10 measurements from the Fluke 45...\n"); printf("\n"); /* * Assign a unique identifier to the Fluke 45 and store in the variable * DVM. IBDEV opens an available device and assigns it to access GPIB0 * with a primary address of 1, a secondary address of 0, a timeout of * 10 seconds, the END message enabled, and the EOS mode disabled. * If DVM is less than zero, call GPIBERR with an error message. */ dvm = ibdev (0, 1, 0, T10s, 1, 0); if (dvm < 0) gpiberr("ibdev Error"); /* Clear the internal or device functions of the Fluke 45. */ ibclr (dvm); if (ibsta & ERR) gpiberr("ibclr Error"); /* * Reset the Fluke 45 by issuing the reset (*RST) command. Instruct the * Fluke 45 to measure the volts alternating current (VAC) using auto-ranging * (AUTO), to wait for a trigger from the GPIB interface board (TRIGGER 2), * and to assert the IEEE-488 Service Request line, SRQ, when the measurement * has been completed and the Fluke 45 is ready to send the result (*SRE 16). */ ibwrt (dvm,"*RST; VAC; AUTO; TRIGGER 2; *SRE 16", 35L); if (ibsta & ERR) gpiberr("ibwrt Error"); /* Initialize the accumulator of the 10 measurements to zero. */ sum = 0.0; /* * Establish FOR loop to read the 10 measuements. The variable m will * serve as the counter of the FOR loop. */ for (m=0; m < 10 ; m++) { /* Trigger the Fluke 45. */ ibtrg (dvm); if (ibsta & ERR) gpiberr("ibtrg Error"); /* * Request the triggered measurement by sending the instruction * "VAL1?". */ ibwrt (dvm,"VAL1?", 5L); if (ibsta & ERR) gpiberr("ibwrt Error"); /* * Wait for the Fluke 45 to request service (RQS) or wait for the * Fluke 45 to timeout(TIMO). The default timeout period is 10 seconds. * RQS is detected by bit position 11 (hex 800). TIMO is detected * by bit position 14 (hex 4000). These status bits are listed under * the NI-488 function IBWAIT in the Software Reference Manual. */ ibwait (dvm,TIMO|RQS); if (ibsta & (ERR|TIMO)) gpiberr("ibwait Error"); /* Read the Fluke 45 serial poll status byte. */ ibrsp (dvm, &spr); if (ibsta & ERR) gpiberr("ibrsp Error"); /* * If the returned status byte is hex 50, the Fluke 45 has valid data to * send; otherwise, it has a fault condition to report. If the status * byte is not hex 50, call DVMERR with an error message. */ if (spr != 0x50) dvmerr("Fluke 45 Error", spr); /* Read the Fluke 45 measurement. */ ibrd (dvm,rd,10L); if (ibsta & ERR) gpiberr("ibrd Error"); /* * Use the null character to mark the end of the data received * in the array RD. Print the measurement received from the * Fluke 45. */ rd[ibcnt] = '\0'; printf("Reading : %s\n", rd); /* Convert the variable RD to its numeric value and add to the * accumulator. */ sum = sum + atof(rd); } /* Continue FOR loop until 10 measurements are read. */ /* Print the average of the 10 readings. */ printf(" The average of the 10 readings is : %f\n", sum/10); ibonl (dvm,0); /* Disable the hardware and software */ }
int main( int argc, char *argv[] ) { int board = 0; int eos_mode = 0; char *file_path; int status; int retval; FILE *filep; struct stat file_stats; uint8_t *buffer; unsigned long buffer_length; if( argc < 2 ) { fprintf( stderr, "Must provide file path as arguement\n" ); return -1; } file_path = argv[ 1 ]; filep = fopen( file_path, "r" ); if( filep == NULL ) { perror( "fopen()"); return -1; } retval = fstat( fileno( filep ), &file_stats ); if( retval < 0 ) { perror( "fstat()"); return -1; } buffer_length = file_stats.st_size; buffer = malloc( buffer_length ); if( buffer == NULL ) { perror( "malloc()"); return -1; } if( fread( buffer, 1, buffer_length, filep ) != buffer_length ) { perror( "fread()" ); return -1; } fclose( filep ); status = ibeos( board, eos_mode ); if( status & ERR ) { fprintf( stderr, "ibeos() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibtmo( board, TNONE ); if( status & ERR ) { fprintf( stderr, "ibtmo() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibconfig( board, IbcTIMING, T1_DELAY_350ns ); if( status & ERR ) { fprintf( stderr, "ibconfig() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibwait( board, TACS ); if( ( status & TACS ) == 0 ) { fprintf( stderr, "ibwait() for TACS failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibwrt( board, buffer, buffer_length ); if( status & ERR ) { fprintf( stderr, "ibwrt() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } free( buffer ); return 0; }