Exemplo n.º 1
0
int CVIFUNC mouth_Error (const char message[], dnaByte abortQ,
						 dnaByte forceErrorQ)
{
	int status,err;
	long count;
	char mouthMessage[80]={0};
#if VERBOSE > 0
	if (forceErrorQ) {
		FmtOut ("%s\n", message);
		Beep();
		Breakpoint();
		ScanIn ("%s", mouthMessage);		// Wait for enter to be pressed
		if (abortQ) abort();
		return -1;
	}		
	status = ThreadIbsta ();
	if (status & ERR) {						// ERR is defined in gpib.h
		err=ThreadIberr();
		count = ThreadIbcntl();
		FmtOut ("%s\n", message);
		FmtOut ("status %d  error %d count %d\n", status,err,count);
		FmtOut ("Library error so Abort always requested.\n");
		FmtOut ("Reminder: Did you turn on the SRS? to GPIB ID #19?\n");
		Beep();
		Breakpoint();
		ScanIn ("%s", mouthMessage);		// Wait for enter to be pressed
		if (abortQ) abort();
		return -1;
	}		
#else
	if (forceErrorQ) {
		Beep();
		MessagePopup ("Mouth Error", message);
		Breakpoint();
		if (abortQ) abort();
		return -1;
	}
	status = ThreadIbsta ();
	if (status & ERR) {
		err=ThreadIberr();
		count = ThreadIbcntl();
		Fmt (mouthMessage, "%s<%s\n", message);
		Fmt (mouthMessage, "%s[a]<status %d  error %d count %d\n", status,err,count);
		if (abortQ)
			Fmt (mouthMessage, "%s[a]<Software Error and Abort has been requested.\n");
		Fmt (mouthMessage, "%s[a]<Reminder: Did you turn on the SRS? to GPIB ID #19?\n");
		Beep();
		MessagePopup ("Mouth Error", mouthMessage);
		Breakpoint();
//		if (abortQ) abort();
		return -1;
	}		

#endif

	return 0;    
}
Exemplo n.º 2
0
int wxGPIB::Write(char* buf,size_t len)
{
    m_state = ibwrt(m_hd,buf,len);
    m_error = ThreadIberr();
    m_count = ThreadIbcnt();
    return m_count;
};
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
int wxGPIB::Read(char* buf,size_t len)
{
    // if something is in the fifo, first read that
    if(m_fifo->items() > 0) {
	   return m_fifo->read(buf,len);
    }
    m_state = ibrd(m_hd,buf,len);
    m_error = ThreadIberr();
    m_count = ThreadIbcnt();
    return m_count;
};
Exemplo n.º 5
0
int wxGPIB::OpenDevice(const char* devname, void* dcs)
{
    // if dcs isn't NULL, type cast
    if(dcs) m_dcs = *(wxGPIB_DCS*)dcs;
    
    if(strncmp(devname,"gpib1",5) == 0) m_board = 0;
    else if(strncmp(devname,"gpib2",5) == 0) m_board = 1;
    if(m_board < 0) {
	   return -1;
    }
    // check for a valid timeout
    if((unsigned int)m_dcs.m_timeout > wxGPIB_TO_1000s) {
	   m_dcs.m_timeout = wxGPIB_TO_10us;
    }

    m_hd = ibdev(m_board,
			  m_dcs.m_address1,
			  m_dcs.m_address2,
			  m_dcs.m_timeout,
			  m_dcs.m_eot,
#ifdef __GNUG__
			  // FIXME!
			  // linux-gpib-3.2.08 doesn't work with any EOS (blocks). 
			  // Because we always has to add an EOS on the message 
			  // (independent of the m_eosChar setting), we can ignore it! 
			  0
#else
			  (m_dcs.m_eosMode << 8) | m_dcs.m_eosChar
#endif
	   );
    if(m_hd < 0) {
	   // no gpib controller installed (not found)
	   return -2;
    }
    // test for a connected listener (device with given address)
    short int listen = 0;
    ibln(m_board,m_dcs.m_address1,NO_SAD,&listen);
    if(!listen) {
	   // no listener at the given address
 	   CloseDevice();
 	   return -3;
    }
    // reset device
    ibclr(m_hd);
    // save state, error and count
    m_state = ThreadIbsta();
    m_count = ThreadIbcnt();
    m_error = ThreadIberr();
    // no error
    return 0;
};
Exemplo n.º 6
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;
};
Exemplo n.º 7
0
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;
};
Exemplo n.º 8
0
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;
}