/** Close opened device connected to GPIB */ void GPIB::close() { if (isOpen()) { ibsre(devId, 0); ibonl(devId, 0); } }
static int configure_board( int fileno, const parsed_options_t *options ) { board_type_ioctl_t boardtype; select_pci_ioctl_t pci_selection; pad_ioctl_t pad_cmd; sad_ioctl_t sad_cmd; online_ioctl_t online_cmd; int retval; online_cmd.online = 0; online_cmd.init_data_ptr = 0; online_cmd.init_data_length = 0; retval = ioctl( fileno, IBONL, &online_cmd ); if( retval < 0 ) { fprintf( stderr, "failed to bring board offline\n" ); return retval; } if( options->offline != 0 ) return 0; strncpy( boardtype.name, options->board_type, sizeof( boardtype.name ) ); retval = ioctl( fileno, CFCBOARDTYPE, &boardtype ); if( retval < 0 ) { fprintf(stderr, "failed to configure boardtype: %s\n", boardtype.name); return retval; } retval = ioctl( fileno, CFCBASE, &options->iobase ); if( retval < 0 ) { fprintf(stderr, "failed to configure base address\n"); return retval; } retval = ioctl( fileno, CFCIRQ, &options->irq ); if( retval < 0 ) { fprintf(stderr, "failed to configure irq\n"); return retval; } retval = ioctl( fileno, CFCDMA, &options->dma ); if( retval < 0 ) { fprintf(stderr, "failed to configure dma channel\n"); return retval; } pad_cmd.handle = 0; pad_cmd.pad = options->pad; retval = ioctl( fileno, IBPAD, &pad_cmd ); if( retval < 0 ) { fprintf(stderr, "failed to configure pad\n"); return retval; } sad_cmd.handle = 0; sad_cmd.sad = options->sad; retval = ioctl( fileno, IBSAD, &sad_cmd ); if( retval < 0 ) { fprintf(stderr, "failed to configure sad\n"); return retval; } pci_selection.pci_bus = options->pci_bus; pci_selection.pci_slot = options->pci_slot; retval = ioctl( fileno, IBSELECT_PCI, &pci_selection ); if( retval < 0 ) { fprintf(stderr, "failed to configure pci bus\n"); return retval; } online_cmd.online = 1; assert(sizeof(options->init_data) <= sizeof(online_cmd.init_data_ptr)); online_cmd.init_data_ptr = (uintptr_t)options->init_data; online_cmd.init_data_length = options->init_data_length; retval = ioctl( fileno, IBONL, &online_cmd ); if( retval < 0 ) { fprintf( stderr, "failed to bring board online\n" ); return retval; } retval = ibrsc( options->minor, options->is_system_controller ); if( retval & ERR ) { fprintf( stderr, "failed to request/release system control\n" ); return -1; } if( options->is_system_controller ) { if( options->assert_ifc ) { retval = ibsic( options->minor ); if( retval & ERR ) { fprintf( stderr, "failed to assert interface clear\n" ); return -1; } } if( options->assert_remote_enable ) { retval = ibsre( options->minor, 1 ); if( retval & ERR ) { fprintf( stderr, "failed to assert remote enable\n" ); return -1; } } } return 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; };
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; };