示例#1
0
int wxGPIB::CloseDevice()
{
    if(m_hd != -1) {
	   // goto local...
	   ibloc(m_hd);
	   // ...and switch device offline
	   ibonl(m_hd,0);
	   m_hd = -1;
	   m_board = -1;
    }
    return 0;
};
示例#2
0
bool CGPIBDevice::Close()
{
	if(m_nDev >= 0)
	{
		ibloc(m_nDev);
		ibonl(m_nDev, 0);
		m_nDev = -1;
	}

	Log(_T("GPIB device closed!"));

	return true;
}
示例#3
0
int wxGPIB_x::Ioctl(int cmd,void* args)
{
    switch(cmd) {
    case CTB_RESET:
	   if(m_hd >= 0) {
		  if(m_asyncio) {
			 ibstop(m_hd);
			 m_asyncio = 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;
    }
    // error or unknown command
    return -1;
};
示例#4
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;
};