Jump to content
  • 0

USB2523 hangs on software reset


Coy C

Question

I am working with a single USB2523 connected to a Win10 64bit computer using C++ code. I have everything working as I need and acquiring data correctly with one exception. That is, when I try to do a software reset and then re-initialize the board, the code hangs up. Below is the bare minimum code to reproduce the issue. All I need to do is call Init(), then Reset() and then Init() again. The code will hang on  FindAnalogChansOfType(). If I remove this call from my full code, the code hangs when I try to acquire data with cbAIn(). I assume I am not free up some resources but can not find anything in the examples that shows what I am doing wrong. Any help would be greatly appreciated.

int HW_MCCDAQ_DRIVER::Init()
{
  int iULStat = NOERRORS;
  float RevLevel = (float)CURRENTREVNUM;
  DaqDeviceDescriptor inventory[MAXNUMDEVS];
  DaqDeviceDescriptor DeviceDescriptor;
  m_iNumberOfDevices = MAXNUMDEVS;

  iULStat = cbDeclareRevision(&RevLevel);
  if (iULStat != NOERRORS)
  {
     return -1;
  }
    
  iULStat = cbGetDaqDeviceInventory(ANY_IFC, inventory, &m_iNumberOfDevices);
  if (iULStat != NOERRORS)
  {
    return -1;
  }
    
  DeviceDescriptor = inventory[0];
  CString name = CString(DeviceDescriptor.ProductName).GetString();
  CString id = CString(DeviceDescriptor.UniqueID).GetString();

  int ADResolution = 0;
  int Range = BIP10VOLTS;
  int LowChan = 0;
  int DefaultTrig = 0;
  int iNumAIChans = FindAnalogChansOfType(0, ANALOGDAQIN, &ADResolution, &Range, &LowChan, &DefaultTrig);
  if (iNumAIChans != 8)
  {
    return -1;
  }
}

int HW_MCCDAQ_DRIVER::Reset()
{
  int iULStat = cbReleaseDaqDevice(0);
  if (iULStat != NOERRORS)
  {
    return -1;
  }
}

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

As written, I believe your code should work. I have tested cbReleaseDaqDevice with the code below and found it to work. 

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"

#define MAXNUMDEVS 100

int GetBoardNum()
{
  int ULStat = 0;
  int BoardNum = -1;
  int numberOfDevices = MAXNUMDEVS;
  DaqDeviceDescriptor inventory[MAXNUMDEVS];
  DaqDeviceDescriptor DeviceDescriptor;

  //Ignore InstaCal device discovery
  cbIgnoreInstaCal();

  //locate USB devices
  ULStat = cbGetDaqDeviceInventory(ANY_IFC, inventory, &numberOfDevices);
  for (int i = 0; i < numberOfDevices; i++)
  {
    DeviceDescriptor = inventory[i];

    //Product ID for USB-2523 = 0xB1
    //Product ID for USB-2533 = 0xB3
    //Product IDs can be found in ULProps.txt located in  
    // C:\Program Files (x86)\Measurement Computing\DAQ
    if (DeviceDescriptor.ProductID == 0xB1)
    {
      BoardNum = i;
      ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
      printf("Device Name: %s\n", DeviceDescriptor.ProductName);
      return BoardNum;
    }

  }
  return BoardNum;
}


void main()
{
  /* Variable Declarations */
  long curCount, curIndex;
  int ULStat = 0;
  int BoardNum = -1;

  float Rev = (float)CURRENTREVNUM;
  ULStat = cbDeclareRevision(&Rev);
  cbErrHandling(PRINTALL, STOPALL);

  for (int j = 0; j < 10; j++)
  {

    BoardNum = GetBoardNum();

    if (BoardNum < 0)
    {
      printf("USB device not found...press any key to exit\n");
      getch();
      return;
    }
    printf("BoardNum = %d\n", BoardNum);

    cbReleaseDaqDevice(BoardNum);
    BoardNum = -1;
  }

  printf("Completed...press any key to exit\n");
  getch();
}
 

DaqReleaseTest.cpp

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...