bool CGPIBDevice::Open(int nBUS, int nAddr, int nSecAddr) { if(m_hGPIBDLL == NULL && !LoadGPIBDriver()) { return false; } m_nDev = ibdev(nBUS, nAddr, nSecAddr, 13, 1, 0); if (m_nDev < 0 || (ibsta & ERR)) { Log(CCommon::FormatString(_T("Failed to open GPIB device at GPIB::%d::%d::%d!"), nBUS, nAddr, nSecAddr)); return false; } short n = 0; ibln(m_nDev, nAddr, 0, &n); if (n <= 0 || (ibsta & ERR)) { Log(_T("No GPIB listener!")); return false; } else { Log(_T("GPIB device opened!")); ibclr(m_nDev); return true; } }
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; };