Jump to content
  • 0

Using Universal Library to access USB-201


USB-201 User

Question

I am currently facing challenges in setting up the USB-201 device using the Universal Library. Despite successfully installing the driver (I am unsure if it is 32-bit or 64-bit), I have encountered issues with initializing the device in my 64-bit application. 

 

Development Environment:

Visual Studio 2022 C++

Library Linking: Linked against cbw64.lib

Headers: Included cbw.h

DLLs: Copied all necessary DLLs (cbw64.dll, DaqLib64.dll, DaqDevInfo64.dll, MccDaq.dll, MccSkts.exe, HIDRegUpdater.exe)  to the execution folder.

My C++ routine,

#include "../Measurement Computing/DAQ/C/cbw.h"

bool USE201::InitReceiver() {
    int ULStat = NOERRORS;
    float RevLevel = (float)CURRENTREVNUM;
    int boardNum = 0; // Assuming USB-201 is board number 0

    ULStat = cbDeclareRevision(&RevLevel);
    if (ULStat != NOERRORS) return false;

    ULStat = cbErrHandling(DONTPRINT, STOPALL);
    if (ULStat != NOERRORS) return false;

    ULStat = cbIgnoreInstaCal();
    if (ULStat != NOERRORS) return false;

    int ConfigVal = 0;
    ULStat = cbGetConfig(BOARDINFO, boardNum, 0, BIADCHANTYPE, &ConfigVal);
    if (ULStat != NOERRORS) {
        char errMsg[ERRSTRLEN];
        cbGetErrMsg(ULStat, errMsg);
        std::cerr << "Error in cbGetConfig: " << errMsg << std::endl;
        return false;
    }

    char BoardName[64] = {0};
    ULStat = cbGetBoardName(boardNum, BoardName);
    if (ULStat != NOERRORS) {
        char errMsg[ERRSTRLEN];
        cbGetErrMsg(ULStat, errMsg);
        std::cerr << "Error in cbGetBoardName: " << errMsg << std::endl;
        return false;
    }

    unsigned short dataValue = 0;
    ULStat = cbAIn(boardNum, 0, BIP5VOLTS, &dataValue);
    if (ULStat != NOERRORS) {
        char errMsg[ERRSTRLEN];
        cbGetErrMsg(ULStat, errMsg);
        std::cerr << "Error in cbAIn: " << errMsg << std::endl;
        return false;
    }

    ULStat = cbDIn(boardNum, FIRSTPORTA, &dataValue);
    if (ULStat != NOERRORS) {
        char errMsg[ERRSTRLEN];
        cbGetErrMsg(ULStat, errMsg);
        std::cerr << "Error in cbDIn: " << errMsg << std::endl;
        return false;
    }

    return true;
}

Issue Description:

Functions such as cbDeclareRevision, cbErrHandling, and cbIgnoreInstaCal execute without errors.

Subsequent calls, cbGetConfig, cbGetBoardName, cbAIn, and cbDIn, fail with the error "Invalid board number".

The boardNum parameter is set to 0, which matches the board number shown in InstaCal.

I have attached a screenshot demonstrating that the driver is installed and the device is detected by InstaCal.

Could you please assist in resolving this issue or provide guidance on what might be going wrong?

Invalid board number.PNG

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Once I commented out the line, ULStat = cbIgnoreInstaCal(); 

cbGetConfig and cbGetBoardName execute without errors.

But the following section,

    int channel = 0; // Channel number
    int gain = BIP5VOLTS; // Gain setting for +/- 5 Volts
    unsigned short dataValue = 0;

    ULStat = cbAIn(boardNum, channel, gain, &dataValue);
    if (ULStat != NOERRORS)
    {
        char errMsg[ERRSTRLEN];
        cbGetErrMsg(ULStat, errMsg);
        std::cerr << "Error in cbAIn: " << errMsg << std::endl;
        return false;
    }

returns ULStat = 343, and errMsg = "Specified USB board not detected."

Could the gain be different number? Or the channel number should not be set to 0? Please advice.

 

 

 

Link to comment
Share on other sites

  • 0

Please don't copy files from C:\Program Files (x86)\Measurement Computing\DAQ\ to other folders. The files that should be in your project are cbw.h and cbw64.lib for a 64-bit build. 

I have attached a 32-bit console program as an example to show how to discover the USB-201 without using InstaCal. If you wish to execute it, create a Win32 Console Application project, add cbw.h and cbw32.lib to the project as well as the attached example, and then build and run.  Let me know if you run into problems. 

 

program.cpp

Link to comment
Share on other sites

  • 0

Hi JRys,
Thanks for the reply. I saw that you are using AIFUNCTION in ULStat = cbGetStatus(BoardNum,&Status,&curCount,&curIndex,AIFUNCTION);
What I used (also used in the sample code, GetValidChannelTypes(int BoardNum)) is ANALOGDAQIN, as follow,
    // determine the number of analog channels and their capabilities
    ChannelType = ANALOGDAQIN;
    NumAIChans = FindAnalogChansOfType(BoardNum, ChannelType,
        &ADResolution, &Range, &LowChan, &DefaultTrig);
        
In the FindAnalogChansOfType, there are lines,
            if (IOType == ANALOGDAQIN)
            {
                functionType = DAQIFUNCTION;
                ULStat = cbGetIOStatus(BoardNum, &status, &curCount, &curIndex, functionType);
                if (ULStat != NOERRORS)
                {
                   return 0;
                }
            }
            
 ULStat = cbGetIOStatus(BoardNum, &status, &curCount, &curIndex, functionType); returns error, and the error message is "Invalid option specified for this function."
 
 I don't find any document explaining the difference between AIFUNCTION and ANALOGDAQIN.
 
 In addition, you used the legacy call cbGetStatus and I use the current cbGetIOStatus.
 
 Please explain why the example code FindAnalogChansOfType fails at the line ULStat = cbGetIOStatus(BoardNum, &status, &curCount, &curIndex, functionType);
 

Link to comment
Share on other sites

  • 0

Anything with DAQI or DAQIN is usually associated with a group product that was rebranded from IOtech. These had some advanced features, like being able to scan digital inputs at the same rate as the analog inputs. The USB-201 does not have DAQIN functionality or allow a digital input scan. Because of this, use AIFUNCTION with the cbGetStatus function. 

In order to determine whether your device can run an example, it performs a series of tests to determine its capabilities. One of the tests is to figure out if it has DAQIN capabilities. When FindAnalogChansOfType calls the status function with functionType set to DAQIFUNCION, it fails because the USB-201 does not have DAQIN functionality. You can determine this ahead of time by looking at the USB-200 series page in the UL Help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...