JNIEXPORT jint JNICALL Java_com_sun_electric_tool_simulation_test_GPIB_ibask (JNIEnv *penv, jclass cls, jint ud, jint option, jintArray value, jintArray err) { int ret; //variable preparation phase jint *pvalue = (*penv)->GetIntArrayElements(penv, value, 0); jint *perr = (*penv)->GetIntArrayElements(penv, err, 0); //excution phase ret = ibask(ud, option, pvalue); *perr = iberr; //printf("ret = %d, value=%d, err=%d\n", ret, *pvalue, *perr); // release phase (*penv)->ReleaseIntArrayElements(penv, value, pvalue, 0); (*penv)->ReleaseIntArrayElements(penv, err, perr, 0); return ret; }
bool CGPIBDevice::ScanDevice(CArray<IO_ADDRESS> &addresses) { IO_ADDRESS addrnode; addresses.RemoveAll(); int res; if (m_hGPIBDLL == NULL && !LoadGPIBDriver()) { return false; } short primary_addrs[MAX_GPIB_PRIM_ADDR]; short addr[MAX_ADDRESSES]; for (int nAddr = 0; nAddr < MAX_ADDRESSES; nAddr++) { addr[nAddr] = (short)0xFFFF; } for (int nAddr = 0; nAddr < (MAX_GPIB_PRIM_ADDR - 2); nAddr++) { primary_addrs[nAddr] = (short)(nAddr + 1); } primary_addrs[MAX_GPIB_PRIM_ADDR - 2] = (short)0xFFFF; Log(_T("GPIB device scanning start!")); for (int nBus = 0; nBus < MAX_GPIB_CARD; nBus++) { ibonl(nBus, 1); if (ibsta & ERR) continue; ibconfig(nBus, IbcSC, 1); if (ibsta & ERR) continue; ibsic(nBus); if (ibsta & ERR) continue; ibconfig(nBus, IbcSRE, 1); if (ibsta & ERR) continue; ibconfig(nBus, IbcTIMING, 1); if (ibsta & ERR) continue; ibask(nBus, IbaPAD, &res); if (ibsta & ERR) continue; ibask(nBus, IbaSAD, &res); if (ibsta & ERR) continue; FindLstn(nBus, primary_addrs, addr, MAX_ADDRESSES - 1); if (ibsta & ERR) continue; for (int i = 0; i < (MAX_ADDRESSES - 1); i++) { if (addr[i] == -1) break; memset(&addrnode, 0, sizeof(IO_ADDRESS)); addrnode.nBus = nBus; addrnode.eType = DRV_GPIB; addrnode.nPrimAddr = (addr[i] & 0xFF); addrnode.nSecAddr = ((addr[i] & 0xFF00) >> 8); addrnode.bPrimary = (i == 0 || addresses[i - 1].nPrimAddr != addrnode.nPrimAddr); if (addrnode.bPrimary && !Open(nBus, addrnode.nPrimAddr, addrnode.nSecAddr)) continue; if (!addrnode.bPrimary) strcpy_s(addrnode.sDevIdentity, addresses[i - 1].sDevIdentity); else { int nReadLen = MAX_DEV_IDN_LEN; CString strIDN; if (!Query("*IDN?", nReadLen, addrnode.sDevIdentity, 1000)) { Log(CCommon::FormatString(_T("Failed to query identity of device at GPIB::%d::%d::%d"), nBus, addrnode.nPrimAddr, addrnode.nSecAddr)); Close(); continue; } Close(); } addresses.Add(addrnode); } } if (addresses.GetCount() == 0) { Log(_T("Found no GPIB device!")); return false; } return true; }