2016年12月2日 星期五

[c++] IGPIBDevice

IGPIBDevice.h

IGPIBDevice.cpp

 

iGPIBInterfaceID = 0

iGPIBCardAddress = 20

 

bool IGPIBDevice::DetectGPIBDevice(int iGPIBInterfaceID, int iGPIBCardAddress)

{

        g_iGPIBInterfaceID = iGPIBInterfaceID;

        g_iGPIBCardAddress = iGPIBCardAddress;

        g_vDeviceName.clear();

        g_vNI488Address.clear();

        g_vPrimaryAddress.clear();

        g_vSecondaryAddress.clear();

 

        int iUD = 0;

 

        Addr4882_t instruments[32];

        Addr4882_t result[32];

        Addr4882_t deviceFound[32];

        int iListnerCount = 0;

 

        // Initial variables

        for (int i = 0; i < 32; ++i)

        {

                instruments[i] = i;

                result[i] = 0;

                deviceFound[i] = 0;

        }

        instruments[31] = NOADDR;

 

        // Initial GPIB interface

        CString cstrGPIBInterface;

        cstrGPIBInterface.Format(_T("GPIB%d"), g_iGPIBInterfaceID);

        CT2A szGPIBInterface(cstrGPIBInterface);

 

        iUD = ibfind(szGPIBInterface);

        if (ibsta & ERR)

                return false;

 

        ibrsc(iUD, 1);

        if (ibsta & ERR)

                return false;

 

        ibsic(iUD);

        if (ibsta & ERR)

                return false;

 

        ibsre(iUD, 1);

        if (ibsta & ERR)

                return false;

 

        ibconfig(iUD, IbcTIMING, 1);

        if (ibsta & ERR)

                return false;

 

        // Find GPIB devices

        FindLstn(g_iGPIBInterfaceID, instruments, result, 31);

        if (ibsta & ERR)

                return false;

 

        // Calculate GPIB device counts

        for (int i = 0; i < ibcntl; ++i)

        {

                if (result[i] > 1)

                {

                        deviceFound[iListnerCount] = result[i];

                        ++iListnerCount;

                }

        }

 

        // Get GPIB device name, PAD, SAD

        for (int i = 0; i < iListnerCount; ++i)

        {

                char szDeviceName[128];

                memset(szDeviceName, 0, 128);

 

                int iPAD = GetPAD(deviceFound[i]);

                int iSAD = GetSAD(deviceFound[i]);

 

                int iDD = ibdev(0, iPAD, iSAD, T10s, 1, 0);

                if (ibsta & ERR)

                        return false;

 

                ibclr(iDD);

                if (ibsta & ERR)

                        return false;

 

                ibwrt(iDD, (void*)"*IDN?", 5);

                if (ibsta & ERR)

                        return false;

 

                ibrd(iDD, (void*)szDeviceName, 127);

                if (ibsta & ERR)

                        return false;

 

                ibonl(iDD, 0);

                if (ibsta & ERR)

                        return false;

 

                bool bExist = false;

                std::string strDeviceName(szDeviceName);

 

                for (int j = 0; j < (signed)g_vDeviceName.size(); ++j)

                {

                        if (g_vDeviceName[j] == strDeviceName && g_vPrimaryAddress[j] == iPAD)

                        {

                                bExist = true;

                                break;

                        }

                }

 

                if (! bExist)

                {

                        g_vDeviceName.push_back(strDeviceName);

                        g_vNI488Address.push_back(deviceFound[i]);

                        g_vPrimaryAddress.push_back(iPAD);

                        g_vSecondaryAddress.push_back(iSAD);

                }

        }

 

        return true;

}

 

 

**********************Confidentiality Notice************************
The opinions and views expressed in this e-mail are solely those of the author and do not necessarily represent our company and its affiliates. If this e-mail is not originally intended for you, or received by you in error, do not disclose its content to anyone and delete it immediately. This e-mail may contain information that is legally privileged, confidential or exempt from disclosure.

沒有留言:

張貼留言