Jump to content
  • 0

DAQ Unable to Measure After Perform 2nd Time of Init


Ricky Ooi

Question

I had created an GUI that allow user to control the DAQ easily. With GUI, I created three functions, which are Init, Start and Stop, each of these functions are explained below:
1. Init - Initialize the DAQ with custom configuration
2. Start - Run the DAQ background scan
3. Stop - Stop the DAQ background scan

Below are my function call for each features:
[Init]
DaqDeviceManager.ReleaseDaqDevice(board);
var devices = DaqDeviceManager.GetDaqDeviceInventory(DaqDeviceInterface.Usb);
var board = DaqDeviceManager.CreateDaqDevice(0, devices[0]);

<Configure DAQ>

[Start]
board.DaqInScan(chanArray, chanTypeArray, rangeArray, NUM_OF_CHANNEL, ref rate, ref PretrigCount, ref Total_Samples, m_MemHandle, SCAN_OPTIONS); // where SCAN_OPTIONS = ScanOptions.Background | ScanOptions.Continuous

m_IsScanning = true;
while(m_IsScanning)
{
  Board.GetStatus(out transfer_status, out current_count, out last_index, m_FunctionType);
  Console.WriteLine(current_count);
}

[Stop]
m_IsScanning = false;
board.StopBackground(m_FunctionType);

P/S: I could not write out all code as it was too long, so I just return some important part of my code.

 

Problem:
Whenever I start my program, then I clicked "Init" followed by "Start". The data received normally. I tested to "Stop" button and the scanning really stop. When I clicked back "Start", it resume normally as well. 
Here come the problem, I click "Init" button followed by "Start" again, I received the data normally for a few second then suddenly stuck at the same "current_count" value. No matter how much time I clicked "Init", this issue still the same. I check from the ULError State and it indicated "Invalid board number". Till I restart my entire program, then only my program run normally (first Init only).

Can help me to advice is there any mistake I did in my code?

Edited by Ricky Ooi
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello Ricky,

The first function in Init should be MccDaq.DaqDeviceManager.IgnoreInstaCal() and move DaqDeviceManager.ReleaseDaqDevice(board) to your stop function. This will give the program more time to clean up the resource.  You could set board = 0 as some added insurance. 

Another approach is to make the board object global and call Init once when the program starts. Below is a routine I use to get the board number.

dev = "USB-1608G"

  public static int GetBoardNumber(string dev)
        {

            MccDaq.DaqDeviceManager.IgnoreInstaCal();
            MccDaq.DaqDeviceDescriptor[] inventory = MccDaq.DaqDeviceManager.GetDaqDeviceInventory(MccDaq.DaqDeviceInterface.Any);
            int DevicesFound = inventory.Length;
            if (DevicesFound > 0)
            {
                for (int boardNum = 0; boardNum < DevicesFound; boardNum++)
                {

                    try
                    {

                        if (inventory[boardNum].ProductName.Contains(dev))
                        {
                            MccDaq.MccBoard daqBoard = MccDaq.DaqDeviceManager.CreateDaqDevice(boardNum, inventory[boardNum]);
                            Console.WriteLine("Product Name:    {0}", inventory[boardNum].ProductName);
                            Console.WriteLine("Device Type # :  {0}", inventory[boardNum].ProductID);
                            Console.WriteLine("Serial # :       {0}", inventory[boardNum].UniqueID);
                            return boardNum;
                        }
                    }
                    catch (ULException ule)
                    {
                        Console.WriteLine("Error occurred: " + ule.Message);
                    }
                }
            }
            return -1;
        }

 

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