Exemple #1
0
void *gpibPort::portOpen(void)
{
    int ret;
    int gpibAddress;
    int sta;

    gpibAddress = atoi(deviceString);

    handle = ibdev( BDINDEX, gpibAddress, NO_SECONDARY_ADDR, T1s, 1, 0 );
    if ( ibsta & ERR )
    {
        GPIBCleanup( (char*)"Unable to open device" );
        exit( -1 );
    }

    sta = ibconfig( BDINDEX, IbcAUTOPOLL, 0 ); // enable auto serial polling
    if ( sta & ERR )
    {
        GPIBCleanup( (char*)"Problem setting Autopoll" );
        exit( -1 );
    }

    if (eosMode)
    {
        ibeos( handle, eosMode);
    }

    if (eotMode)
    {
        ibeot( handle, eotMode);
    }

    ibtmo( handle, timeout);

    portService();

    Dev = &handle;

    return Dev;
}
Exemple #2
0
int wxGPIB::Ioctl(int cmd,void* args)
{
    switch(cmd) {
    case CTB_RESET:
	   if(m_hd >= 0) {
		  ibclr(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_GETRSP: {
	   char spr = 0;
	   if(m_hd >= 0) {
		  ibrsp(m_hd,&spr);
		  *(int*)args = (int)spr;
		  return 0;
	   }
	   return 1; }
    case CTB_GPIB_GETSTA:
	   *(int*)args = m_state;
	   return 0;
    case CTB_GPIB_GETERR:
	   *(int*)args = m_error;
	   return 0;
    case CTB_GPIB_GETLINES: {
	   short state = 0;
	   if(m_hd >= 0) {
		  iblines(m_board,&state);
		  *(int*)args = (int)state;
		  return 0;
	   }
	   return -1; }
    case CTB_GPIB_SETTIMEOUT: {
	   if(m_hd >= 0) {
		  wxGPIB_Timeout timeout;
		  unsigned long to = *(unsigned long*)args;
		  // convert the timeout in ms (given by args) into the
		  // traditional NI-488.2 timeout period 
		  if(to > 1000000) timeout = wxGPIB_TO_1000s;
		  else if(to >= 300000) timeout = wxGPIB_TO_300s;
		  else if(to >= 100000) timeout = wxGPIB_TO_100s;
		  else if(to >= 30000) timeout = wxGPIB_TO_30s;
		  else if(to >= 10000) timeout = wxGPIB_TO_10s;
		  else if(to >= 3000) timeout = wxGPIB_TO_3s;
		  else if(to >= 1000) timeout = wxGPIB_TO_1s;
		  else if(to >= 300) timeout = wxGPIB_TO_300ms;
		  else if(to >= 100) timeout = wxGPIB_TO_100ms;
		  else if(to >= 30) timeout = wxGPIB_TO_30ms;
		  else if(to >= 10) timeout = wxGPIB_TO_10ms;
		  else if(to >= 3) timeout = wxGPIB_TO_3ms;
		  else if(to >= 1) timeout = wxGPIB_TO_1ms;
		  else timeout = wxGPIB_TO_NONE;
		  ibtmo(m_hd,timeout);
		  return 0; 
	   }
	   return -1; }
    case CTB_GPIB_GTL:
	   // Forces the specified device to go to local program mode
	   if(m_hd >= 0) {
		  ibloc(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_REN:
	   // This routine can only be used if the specified GPIB 
	   // Interface Board is the System Controller.
	   // Remember that even though the REN line is asserted, 
	   // the device(s) will not be put into remote state until is
	   // addressed to listen by the Active Controller
	   if(m_hd) {
		  char adr = (char)m_dcs.m_address1;
		  ibsre(m_board,1);
		  ibcmd(m_board,&adr,1);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_RESET_BUS:
	   ibsic(m_board);
	   return 0;
    case CTB_GPIB_GET_EOS_CHAR:
	   if( m_hd ) {
		  *(int*)args = (int)m_dcs.m_eosChar;
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_SET_EOS_CHAR:
#ifdef __GNUG__
	   // FIXME!
	   // Doesn't work with linux-gpib-3.2.08. All EOS beside 0x00
	   // are blocking during sending data to the device. (Look at 
	   // function my_ibwrt in linux-gpib-3.2.08/lib/ibWrt.c
	   if( m_hd ) {
		  m_dcs.m_eosChar = (char)*(int*)args;
		  ibeos(m_hd,(m_dcs.m_eosMode << 8) | m_dcs.m_eosChar);
		  return 0;
	   }
#endif
	   return -1;
    case CTB_GPIB_GET_EOS_MODE:
	   if( m_hd ) {
		  *(int*)args = (int)m_dcs.m_eosMode;
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_SET_EOS_MODE:
	   if( m_hd ) {
		  m_dcs.m_eosMode = (char)*(int*)args;
		  ibeos(m_hd,(m_dcs.m_eosMode << 8) | m_dcs.m_eosChar);
		  return 0;
	   }
	   return -1;
    }
    // error or unknown command
    return -1;
};
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;
}